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
This commit is contained in:
Alistair Coles 2021-02-18 09:14:58 +00:00
parent 6fca356be9
commit 10b16f9737
2 changed files with 19 additions and 10 deletions

View File

@ -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]')

View File

@ -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