From a045f90b4d7ccc2da4cd52883c04c176b9ec920f Mon Sep 17 00:00:00 2001 From: Matthew Oliver Date: Fri, 26 Feb 2021 17:14:30 +1100 Subject: [PATCH] Add name to compact output Currently when you get to the final collapse into root with the compact command, it can look a little screwy: $ swift-manage-shard-ranges --conf /etc/swift/container-server/1.conf /mnt/sdb1/1/node/sdb1/containers/925/c2a/e77a449c51d01ef47471efb208c20c2a/e77a449c51d01ef47471efb208c20c2a.db compact Loaded db broker for AUTH_admin/shardme. Donor shard range(s) with total of 0 objects: objects: 0 lower: '' state: active upper: '' can be compacted into acceptor shard range: objects: 0 lower: '' state: sharded upper: '' Once applied to the broker these changes will result in shard range compaction the next time the sharder runs. But it's fixed if we add the name to the compact output. It also makes gives it just a little bit more useful information: $ swift-manage-shard-ranges --conf /etc/swift/container-server/1.conf /mnt/sdb1/1/node/sdb1/containers/925/c2a/e77a449c51d01ef47471efb208c20c2a/e77a449c51d01ef47471efb208c20c2a.db compact Loaded db broker for AUTH_admin/shardme. Donor shard range(s) with total of 0 objects: '.shards_AUTH_admin/shardme-7820d6e9550a1661e01e0538aea8cc1b-1614319760.63229-5' objects: 0 lower: '' state: active upper: '' can be compacted into acceptor shard range: 'AUTH_admin/shardme' objects: 0 lower: '' state: sharded upper: '' Once applied to the broker these changes will result in shard range compaction the next time the sharder runs. Do you want to apply these changes? [y/N] This is what a non root collapse would look like with more ranges: $ swift-manage-shard-ranges --conf /etc/swift/container-server/1.conf /mnt/sdb1/1/node/sdb1/containers/925/c2a/e77a449c51d01ef47471efb208c20c2a/e77a449c51d01ef47471efb208c20c2a.db compact Loaded db broker for AUTH_admin/shardme. Donor shard range(s) with total of 0 objects: '.shards_AUTH_admin/shardme-7820d6e9550a1661e01e0538aea8cc1b-1614565810.95419-0' objects: 0 lower: '' state: active upper: 'e9' can be compacted into acceptor shard range: '.shards_AUTH_admin/shardme-7820d6e9550a1661e01e0538aea8cc1b-1614565810.95419-1' objects: 0 lower: 'e9' state: active upper: 'j9' Donor shard range(s) with total of 0 objects: '.shards_AUTH_admin/shardme-7820d6e9550a1661e01e0538aea8cc1b-1614565810.95419-2' objects: 0 lower: 'j9' state: active upper: 'o9' can be compacted into acceptor shard range: '.shards_AUTH_admin/shardme-7820d6e9550a1661e01e0538aea8cc1b-1614565810.95419-3' objects: 0 lower: 'o9' state: active upper: 't9' Donor shard range(s) with total of 0 objects: '.shards_AUTH_admin/shardme-7820d6e9550a1661e01e0538aea8cc1b-1614565810.95419-4' objects: 0 lower: 't9' state: active upper: 'y9' can be compacted into acceptor shard range: '.shards_AUTH_admin/shardme-7820d6e9550a1661e01e0538aea8cc1b-1614565810.95419-5' objects: 0 lower: 'y9' state: active upper: '' Once applied to the broker these changes will result in shard range compaction the next time the sharder runs. Do you want to apply these changes? [y/N] Change-Id: Ie8e2b03f93ace0283c7a759d2404022208c0c553 --- swift/cli/manage_shard_ranges.py | 6 ++++-- test/unit/cli/test_manage_shard_ranges.py | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/swift/cli/manage_shard_ranges.py b/swift/cli/manage_shard_ranges.py index 43efe57fa6..6599c7daa5 100644 --- a/swift/cli/manage_shard_ranges.py +++ b/swift/cli/manage_shard_ranges.py @@ -181,8 +181,10 @@ DEFAULT_SHRINK_THRESHOLD = DEFAULT_SHARD_CONTAINER_THRESHOLD * \ def _print_shard_range(sr, level=0): indent = ' ' * level - print(indent + 'objects: %-9d lower: %r' % (sr.object_count, sr.lower_str)) - print(indent + ' state: %-9s upper: %r' % (sr.state_text, sr.upper_str)) + print(indent + '%r' % sr.name) + print(indent + ' objects: %-9d lower: %r' % (sr.object_count, + sr.lower_str)) + print(indent + ' state: %-9s upper: %r' % (sr.state_text, sr.upper_str)) def _load_and_validate_shard_data(args): diff --git a/test/unit/cli/test_manage_shard_ranges.py b/test/unit/cli/test_manage_shard_ranges.py index 0937c43418..2f66f32605 100644 --- a/test/unit/cli/test_manage_shard_ranges.py +++ b/test/unit/cli/test_manage_shard_ranges.py @@ -694,15 +694,17 @@ class TestManageShardRanges(unittest.TestCase): self.assert_starts_with(err_lines[0], 'Loaded db broker for ') out_lines = out.getvalue().split('\n') self.assertIn('total of 20 objects', out_lines[0]) - self.assertIn('objects: 10', out_lines[1]) - self.assertIn('state: active', out_lines[2]) - self.assertIn('objects: 10', out_lines[3]) - self.assertIn('state: active', out_lines[4]) - self.assertIn('can be compacted into', out_lines[5]) - self.assertIn('objects: 10', out_lines[6]) - self.assertIn('state: active', out_lines[7]) - broker_ranges = broker.get_shard_ranges() - return broker_ranges + self.assertIn('.shards_a', out_lines[1]) + self.assertIn('objects: 10', out_lines[2]) + self.assertIn('state: active', out_lines[3]) + self.assertIn('.shards_a', out_lines[4]) + self.assertIn('objects: 10', out_lines[5]) + self.assertIn('state: active', out_lines[6]) + self.assertIn('can be compacted into', out_lines[7]) + self.assertIn('.shards_a', out_lines[8]) + self.assertIn('objects: 10', out_lines[9]) + self.assertIn('state: active', out_lines[10]) + return broker.get_shard_ranges() broker_ranges = do_compact('n') # expect no changes to shard ranges