Merge "Address a sharder/replicator race"

This commit is contained in:
Zuul 2020-08-07 07:46:19 +00:00 committed by Gerrit Code Review
commit d50b50ba8d
2 changed files with 13 additions and 9 deletions

View File

@ -749,8 +749,9 @@ class ContainerSharder(ContainerReplicator):
# root may not yet know about this shard container
warnings.append('root has no matching shard range')
shard_range = None
else:
elif not own_shard_range.deleted:
warnings.append('unable to get shard ranges from root')
# else, our shard range is deleted, so root may have reclaimed it
else:
errors.append('missing own shard range')
@ -770,14 +771,16 @@ class ContainerSharder(ContainerReplicator):
self.logger.debug('Updating shard from root %s', dict(shard_range))
broker.merge_shard_ranges(shard_range)
own_shard_range = broker.get_own_shard_range()
delete_age = time.time() - self.reclaim_age
if (own_shard_range.state == ShardRange.SHARDED and
own_shard_range.deleted and
own_shard_range.timestamp < delete_age and
broker.empty()):
broker.delete_db(Timestamp.now().internal)
self.logger.debug('Deleted shard container %s (%s)',
broker.db_file, quote(broker.path))
delete_age = time.time() - self.reclaim_age
if (own_shard_range.state == ShardRange.SHARDED and
own_shard_range.deleted and
own_shard_range.timestamp < delete_age and
broker.empty()):
broker.delete_db(Timestamp.now().internal)
self.logger.debug('Deleted shard container %s (%s)',
broker.db_file, quote(broker.path))
self._increment_stat('audit_shard', 'success', statsd=True)
return True

View File

@ -4640,6 +4640,7 @@ class TestSharder(BaseTestSharder):
own_shard_range.deleted = 1
own_shard_range.timestamp = Timestamp.now()
broker.merge_shard_ranges([own_shard_range])
del shard_ranges[:] # root responds with no shard ranges
assert_ok()
self.assertTrue(broker.is_deleted())