From f150a5035ced99f40cad0888c2301bd1469ec279 Mon Sep 17 00:00:00 2001 From: Jianjian Huo Date: Fri, 12 May 2023 15:37:20 -0700 Subject: [PATCH] proxy: print logs when write new shard range cache into memcache. Change-Id: I0e13e0148a6e19fd6d0a9438604aa791f948502a --- swift/proxy/controllers/container.py | 4 ++-- swift/proxy/controllers/obj.py | 3 +++ test/unit/proxy/controllers/test_container.py | 4 ++++ test/unit/proxy/test_server.py | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/swift/proxy/controllers/container.py b/swift/proxy/controllers/container.py index fe8480ba37..76a28e644e 100644 --- a/swift/proxy/controllers/container.py +++ b/swift/proxy/controllers/container.py @@ -239,8 +239,8 @@ class ContainerController(Controller): memcache = cache_from_env(req.environ, True) if memcache and ns_bound_list: # cache in memcache only if shard ranges as expected - self.logger.debug('Caching %d shards for %s', - len(ns_bound_list.bounds), req.path_qs) + self.logger.info('Caching listing shards for %s (%d shards)', + cache_key, len(ns_bound_list.bounds)) memcache.set(cache_key, ns_bound_list.bounds, time=self.app.recheck_listing_shard_ranges) return ns_bound_list diff --git a/swift/proxy/controllers/obj.py b/swift/proxy/controllers/obj.py index 113ea9d439..c63d7eb5f9 100644 --- a/swift/proxy/controllers/obj.py +++ b/swift/proxy/controllers/obj.py @@ -386,6 +386,9 @@ class BaseObjectController(Controller): shard_ranges) infocache[cache_key] = cached_namespaces if memcache: + self.logger.info( + 'Caching updating shards for %s (%d shards)', + cache_key, len(cached_namespaces.bounds)) memcache.set( cache_key, cached_namespaces.bounds, time=self.app.recheck_updating_shard_ranges) diff --git a/test/unit/proxy/controllers/test_container.py b/test/unit/proxy/controllers/test_container.py index d8b1367578..f0bd3ae693 100644 --- a/test/unit/proxy/controllers/test_container.py +++ b/test/unit/proxy/controllers/test_container.py @@ -3210,6 +3210,10 @@ class TestContainerController(TestRingBase): 'shard-listing-v2/a/c', self.ns_bound_list.bounds, time=600), mock.call.set('container/a/c', mock.ANY, time=60)], self.memcache.calls) + info_lines = self.logger.get_lines_for_level('info') + self.assertIn( + 'Caching listing shards for shard-listing-v2/a/c (3 shards)', + info_lines) # shards were cached self.assertEqual('sharded', self.memcache.calls[2][1][1]['sharding_state']) diff --git a/test/unit/proxy/test_server.py b/test/unit/proxy/test_server.py index 2e4da07544..1082a23717 100644 --- a/test/unit/proxy/test_server.py +++ b/test/unit/proxy/test_server.py @@ -4358,6 +4358,10 @@ class TestReplicatedObjectController( 'object.shard_updating.cache.miss.200': 1}, stats) self.assertEqual([], self.app.logger.log_dict['set_statsd_prefix']) + info_lines = self.logger.get_lines_for_level('info') + self.assertIn( + 'Caching updating shards for shard-updating-v2/a/c (3 shards)', + info_lines) backend_requests = fake_conn.requests account_request = backend_requests[0]