Merge "Fix logging in proxy container GET path"

This commit is contained in:
Zuul 2021-01-22 17:08:46 +00:00 committed by Gerrit Code Review
commit 257041affe
2 changed files with 11 additions and 10 deletions

View File

@ -391,23 +391,19 @@ class ContainerController(Controller):
req, shard_range.account, shard_range.container, req, shard_range.account, shard_range.container,
headers=headers, params=params) headers=headers, params=params)
shard_state = 'unknown' sharding_state = shard_resp.headers.get('x-backend-sharding-state',
try: 'unknown')
shard_state = shard_resp.headers['x-backend-sharding-state']
shard_state = ShardRange.resolve_state(shard_state)
except (AttributeError, ValueError, KeyError):
pass
if objs is None: if objs is None:
# tolerate errors # tolerate errors
self.app.logger.debug( self.app.logger.debug(
'Failed to get objects from shard (state=%s), total = %d', 'Failed to get objects from shard (state=%s), total = %d',
shard_state, len(objects)) sharding_state, len(objects))
continue continue
self.app.logger.debug( self.app.logger.debug(
'Found %d objects in shard (state=%s), total = %d', 'Found %d objects in shard (state=%s), total = %d',
len(objs), shard_state, len(objs) + len(objects)) len(objs), sharding_state, len(objs) + len(objects))
if not objs: if not objs:
# tolerate empty shard containers # tolerate empty shard containers

View File

@ -982,7 +982,7 @@ class TestContainerController(TestRingBase):
# when shrinking the final shard will return the root shard range into # when shrinking the final shard will return the root shard range into
# which it is shrinking # which it is shrinking
shard_resp_hdrs = { shard_resp_hdrs = {
'X-Backend-Sharding-State': 'sharded', 'X-Backend-Sharding-State': 'sharding',
'X-Container-Object-Count': 0, 'X-Container-Object-Count': 0,
'X-Container-Bytes-Used': 0, 'X-Container-Bytes-Used': 0,
'X-Backend-Storage-Policy-Index': 0, 'X-Backend-Storage-Policy-Index': 0,
@ -1028,6 +1028,11 @@ class TestContainerController(TestRingBase):
self.assertEqual( self.assertEqual(
[('a', 'c'), ('.shards_a', 'c_xyz')], [('a', 'c'), ('.shards_a', 'c_xyz')],
resp.request.environ.get('swift.shard_listing_history')) resp.request.environ.get('swift.shard_listing_history'))
lines = [line for line in self.app.logger.get_lines_for_level('debug')
if line.startswith('Found 1024 objects in shard')]
self.assertEqual(2, len(lines), lines)
self.assertIn("(state=sharded), total = 1024", lines[0]) # shard->root
self.assertIn("(state=sharding), total = 1024", lines[1]) # shard
def test_GET_sharded_container_shard_redirects_between_shards(self): def test_GET_sharded_container_shard_redirects_between_shards(self):
# check that if one shard redirects listing to another shard that # check that if one shard redirects listing to another shard that
@ -1767,7 +1772,7 @@ class TestContainerController(TestRingBase):
'X-Backend-Storage-Policy-Index': '0'} 'X-Backend-Storage-Policy-Index': '0'}
def _do_test_caching(self, record_type, exp_recheck_listing): def _do_test_caching(self, record_type, exp_recheck_listing):
# this test gest shard ranges into cache and then reads from cache # this test gets shard ranges into cache and then reads from cache
sharding_state = 'sharded' sharding_state = 'sharded'
self.memcache.delete_all() self.memcache.delete_all()
self.memcache.clear_calls() self.memcache.clear_calls()