Fix shard_max_row in ContainerBroker.get_replication_info()

ContainerBroker adds the shard_max_row item to the
get_replication_info result by querying the db for the shard ranges
table max rowid. However, the wrong table name was being used in the
db query such that the value was always -1. This bug was benign
because the value of shard_max_row is not currently used.

Noticed while reviewing [1] which does make use of the shard_max_row
*key* in replication info.

[1] Related-Change: I7231e8af310e268484f2075f0194b7783cf1c3ea

Change-Id: I9e733e301894f1ffff4a1092926cc0df8419c5b5
This commit is contained in:
Alistair Coles 2018-06-13 12:20:17 +01:00
parent 9ca3160ff7
commit 65e1de29d6
2 changed files with 36 additions and 1 deletions

View File

@ -838,7 +838,7 @@ class ContainerBroker(DatabaseBroker):
def get_replication_info(self):
info = super(ContainerBroker, self).get_replication_info()
info['shard_max_row'] = self.get_max_row('shard_ranges')
info['shard_max_row'] = self.get_max_row(SHARD_RANGE_TABLE)
return info
def _do_get_info_query(self, conn):

View File

@ -2013,6 +2013,41 @@ class TestContainerBroker(unittest.TestCase):
self.assertEqual(info['reported_object_count'], 2)
self.assertEqual(info['reported_bytes_used'], 1123)
@with_tempdir
def test_get_replication_info(self, tempdir):
ts_iter = make_timestamp_iter()
db_path = os.path.join(tempdir, 'part', 'suffix', 'hash', 'hash.db')
broker = ContainerBroker(
db_path, account='myaccount', container='mycontainer')
broker.initialize(next(ts_iter).internal, 0)
metadata = {'blah': ['val', next(ts_iter).internal]}
broker.update_metadata(metadata)
expected = broker.get_info()
expected['metadata'] = json.dumps(metadata)
expected.pop('object_count')
expected['count'] = 0
expected['max_row'] = -1
expected['shard_max_row'] = -1
actual = broker.get_replication_info()
self.assertEqual(expected, actual)
broker.put_object('o1', next(ts_iter).internal, 123, 'text/plain',
'fake etag')
expected = broker.get_info()
expected['metadata'] = json.dumps(metadata)
expected.pop('object_count')
expected['count'] = 1
expected['max_row'] = 1
expected['shard_max_row'] = -1
actual = broker.get_replication_info()
self.assertEqual(expected, actual)
sr = ShardRange('.shards_a/c', next(ts_iter))
broker.merge_shard_ranges(sr)
expected['shard_max_row'] = 1
actual = broker.get_replication_info()
self.assertEqual(expected, actual)
@with_tempdir
def test_remove_objects(self, tempdir):
objects = (('undeleted', Timestamp.now().internal, 0, 'text/plain',