From 10b16f97373fb2cc61083a91c7db3a89b4224522 Mon Sep 17 00:00:00 2001 From: Alistair Coles Date: Thu, 18 Feb 2021 09:14:58 +0000 Subject: [PATCH] Improve 'swift-manage-shard-ranges compact' output The output from swift-manage-shard-ranges compact was hard to read, particularly with long lower and upper bounds typically seen in production. This patch changes the output, most significantly by aligning lower and upper bounds at the end of lines and printing donors before acceptors, so that the continuity of shard range bounds is easier to see. Example of new ouput: Donor shard range(s) with total of 2 objects: objects: 2 lower: '' state: active upper: 'obj-0001' can be compacted into acceptor shard range: objects: 2 lower: 'obj-0001' state: active upper: 'obj-0003' Donor shard range(s) with total of 2 objects: objects: 2 lower: 'obj-0003' state: active upper: 'obj-0005' can be compacted into acceptor shard range: objects: 2 lower: 'obj-0005' state: active upper: '' Change-Id: I90f3ab7a29b87d0959c94a05c9ee9ad97b60014d --- swift/cli/manage_shard_ranges.py | 16 +++++++++++----- test/unit/cli/test_manage_shard_ranges.py | 13 ++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/swift/cli/manage_shard_ranges.py b/swift/cli/manage_shard_ranges.py index e3d8954c2f..14d234e549 100644 --- a/swift/cli/manage_shard_ranges.py +++ b/swift/cli/manage_shard_ranges.py @@ -177,6 +177,12 @@ DEFAULT_MAX_SHRINKING = 1 DEFAULT_MAX_EXPANDING = -1 +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)) + + def _load_and_validate_shard_data(args): try: with open(args.input, 'r') as fd: @@ -454,12 +460,12 @@ def compact_shard_ranges(broker, args): for sequence in compactible: acceptor = sequence[-1] donors = sequence[:-1] - print('Shard %s (object count %d) can expand to accept %d objects ' - 'from:' % - (acceptor, acceptor.object_count, donors.object_count)) + print('Donor shard range(s) with total of %d objects:' + % donors.object_count) for donor in donors: - print(' shard %s (object count %d)' % - (donor, donor.object_count)) + _print_shard_range(donor, level=1) + print('can be compacted into acceptor shard range:') + _print_shard_range(acceptor, level=1) print('Once applied to the broker these changes will result in shard ' 'range compaction the next time the sharder runs.') choice = input('Do you want to apply these changes? [y/N]') diff --git a/test/unit/cli/test_manage_shard_ranges.py b/test/unit/cli/test_manage_shard_ranges.py index 8e7c0756d8..19065027d3 100644 --- a/test/unit/cli/test_manage_shard_ranges.py +++ b/test/unit/cli/test_manage_shard_ranges.py @@ -529,11 +529,14 @@ class TestManageShardRanges(unittest.TestCase): err_lines = err.getvalue().split('\n') self.assert_starts_with(err_lines[0], 'Loaded db broker for ') out_lines = out.getvalue().split('\n') - self.assertIn('can expand to accept 20 objects', out_lines[0]) - self.assertIn('(object count 10)', out_lines[1]) - self.assertIn('(object count 10)', out_lines[2]) - self.assertIn('can expand to accept 10 objects', out_lines[3]) - self.assertIn('(object count 10)', out_lines[4]) + 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