Merge "ContainerBroker.get_shard_ranges(): states must be a list"

This commit is contained in:
Zuul 2024-01-09 20:38:06 +00:00 committed by Gerrit Code Review
commit 7d5c73fcde
3 changed files with 13 additions and 13 deletions

View File

@ -1709,8 +1709,8 @@ class ContainerBroker(DatabaseBroker):
``marker`` and ``end_marker`` are ignored, but other constraints
are applied (e.g. ``exclude_others`` and ``include_deleted``).
:param include_deleted: include rows marked as deleted.
:param states: include only rows matching the given state(s); can be an
int or a list of ints.
:param states: include only rows matching the given states; should be
a list of ints.
:param include_own: boolean that governs whether the row whose name
matches the broker's path is included in the returned list. If
True, that row is included unless it is excluded by other
@ -1734,11 +1734,7 @@ class ContainerBroker(DatabaseBroker):
if exclude_others and not include_own:
return []
included_states = set()
if isinstance(states, (list, tuple, set)):
included_states.update(states)
elif states is not None:
included_states.add(states)
included_states = set(states) if states else None
# defaults to be used when legacy db's are missing columns
default_values = {'reported': 0,
@ -1868,8 +1864,7 @@ class ContainerBroker(DatabaseBroker):
:param reverse: reverse the result order.
:param include_deleted: include items that have the delete marker set.
:param states: if specified, restricts the returned list to shard
ranges that have the given state(s); can be a list of ints or a
single int.
ranges that have one of the given states; should be a list of ints.
:param include_own: boolean that governs whether the row whose name
matches the broker's path is included in the returned list. If
True, that row is included unless it is excluded by other

View File

@ -1308,7 +1308,7 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator):
# Shrinking is how we resolve overlaps; we've got to
# allow multiple shards in that state
continue
shard_ranges = broker.get_shard_ranges(states=state)
shard_ranges = broker.get_shard_ranges(states=[state])
# Transient overlaps can occur during the period immediately after
# sharding if a root learns about new child shards before it learns
# that the parent has sharded. These overlaps are normally
@ -1935,7 +1935,7 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator):
# Create shard containers that are ready to receive redirected object
# updates. Do this now, so that redirection can begin immediately
# without waiting for cleaving to complete.
found_ranges = broker.get_shard_ranges(states=ShardRange.FOUND)
found_ranges = broker.get_shard_ranges(states=[ShardRange.FOUND])
created_ranges = []
for shard_range in found_ranges:
self._increment_stat('created', 'attempted')
@ -2233,7 +2233,7 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator):
else:
own_shard_range.update_state(ShardRange.SHARDED)
modified_shard_ranges = broker.get_shard_ranges(
states=ShardRange.CLEAVED)
states=[ShardRange.CLEAVED])
for sr in modified_shard_ranges:
sr.update_state(ShardRange.ACTIVE)
if (not broker.is_root_container() and not

View File

@ -4289,13 +4289,18 @@ class TestContainerBroker(test_db.TestDbBase):
[dict(sr) for sr in actual])
actual = broker.get_shard_ranges(marker='c', end_marker='e',
states=ShardRange.ACTIVE)
states=[ShardRange.ACTIVE])
self.assertEqual([dict(sr) for sr in shard_ranges[2:3]],
[dict(sr) for sr in actual])
actual = broker.get_shard_ranges(marker='e', end_marker='e')
self.assertFalse([dict(sr) for sr in actual])
# check state filtering...
actual = broker.get_shard_ranges(states=[ShardRange.FOUND])
self.assertEqual([dict(sr) for sr in shard_ranges[:2]],
[dict(sr) for sr in actual])
# includes overrides include_own
actual = broker.get_shard_ranges(includes='b', include_own=True)
self.assertEqual([dict(shard_ranges[0])], [dict(sr) for sr in actual])