Merge "ContainerBroker.get_shard_ranges(): states must be a list"
This commit is contained in:
commit
7d5c73fcde
|
@ -1709,8 +1709,8 @@ class ContainerBroker(DatabaseBroker):
|
||||||
``marker`` and ``end_marker`` are ignored, but other constraints
|
``marker`` and ``end_marker`` are ignored, but other constraints
|
||||||
are applied (e.g. ``exclude_others`` and ``include_deleted``).
|
are applied (e.g. ``exclude_others`` and ``include_deleted``).
|
||||||
:param include_deleted: include rows marked as deleted.
|
:param include_deleted: include rows marked as deleted.
|
||||||
:param states: include only rows matching the given state(s); can be an
|
:param states: include only rows matching the given states; should be
|
||||||
int or a list of ints.
|
a list of ints.
|
||||||
:param include_own: boolean that governs whether the row whose name
|
:param include_own: boolean that governs whether the row whose name
|
||||||
matches the broker's path is included in the returned list. If
|
matches the broker's path is included in the returned list. If
|
||||||
True, that row is included unless it is excluded by other
|
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:
|
if exclude_others and not include_own:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
included_states = set()
|
included_states = set(states) if states else None
|
||||||
if isinstance(states, (list, tuple, set)):
|
|
||||||
included_states.update(states)
|
|
||||||
elif states is not None:
|
|
||||||
included_states.add(states)
|
|
||||||
|
|
||||||
# defaults to be used when legacy db's are missing columns
|
# defaults to be used when legacy db's are missing columns
|
||||||
default_values = {'reported': 0,
|
default_values = {'reported': 0,
|
||||||
|
@ -1868,8 +1864,7 @@ class ContainerBroker(DatabaseBroker):
|
||||||
:param reverse: reverse the result order.
|
:param reverse: reverse the result order.
|
||||||
:param include_deleted: include items that have the delete marker set.
|
:param include_deleted: include items that have the delete marker set.
|
||||||
:param states: if specified, restricts the returned list to shard
|
: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
|
ranges that have one of the given states; should be a list of ints.
|
||||||
single int.
|
|
||||||
:param include_own: boolean that governs whether the row whose name
|
:param include_own: boolean that governs whether the row whose name
|
||||||
matches the broker's path is included in the returned list. If
|
matches the broker's path is included in the returned list. If
|
||||||
True, that row is included unless it is excluded by other
|
True, that row is included unless it is excluded by other
|
||||||
|
|
|
@ -1308,7 +1308,7 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator):
|
||||||
# Shrinking is how we resolve overlaps; we've got to
|
# Shrinking is how we resolve overlaps; we've got to
|
||||||
# allow multiple shards in that state
|
# allow multiple shards in that state
|
||||||
continue
|
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
|
# Transient overlaps can occur during the period immediately after
|
||||||
# sharding if a root learns about new child shards before it learns
|
# sharding if a root learns about new child shards before it learns
|
||||||
# that the parent has sharded. These overlaps are normally
|
# 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
|
# Create shard containers that are ready to receive redirected object
|
||||||
# updates. Do this now, so that redirection can begin immediately
|
# updates. Do this now, so that redirection can begin immediately
|
||||||
# without waiting for cleaving to complete.
|
# 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 = []
|
created_ranges = []
|
||||||
for shard_range in found_ranges:
|
for shard_range in found_ranges:
|
||||||
self._increment_stat('created', 'attempted')
|
self._increment_stat('created', 'attempted')
|
||||||
|
@ -2233,7 +2233,7 @@ class ContainerSharder(ContainerSharderConf, ContainerReplicator):
|
||||||
else:
|
else:
|
||||||
own_shard_range.update_state(ShardRange.SHARDED)
|
own_shard_range.update_state(ShardRange.SHARDED)
|
||||||
modified_shard_ranges = broker.get_shard_ranges(
|
modified_shard_ranges = broker.get_shard_ranges(
|
||||||
states=ShardRange.CLEAVED)
|
states=[ShardRange.CLEAVED])
|
||||||
for sr in modified_shard_ranges:
|
for sr in modified_shard_ranges:
|
||||||
sr.update_state(ShardRange.ACTIVE)
|
sr.update_state(ShardRange.ACTIVE)
|
||||||
if (not broker.is_root_container() and not
|
if (not broker.is_root_container() and not
|
||||||
|
|
|
@ -4289,13 +4289,18 @@ class TestContainerBroker(test_db.TestDbBase):
|
||||||
[dict(sr) for sr in actual])
|
[dict(sr) for sr in actual])
|
||||||
|
|
||||||
actual = broker.get_shard_ranges(marker='c', end_marker='e',
|
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]],
|
self.assertEqual([dict(sr) for sr in shard_ranges[2:3]],
|
||||||
[dict(sr) for sr in actual])
|
[dict(sr) for sr in actual])
|
||||||
|
|
||||||
actual = broker.get_shard_ranges(marker='e', end_marker='e')
|
actual = broker.get_shard_ranges(marker='e', end_marker='e')
|
||||||
self.assertFalse([dict(sr) for sr in actual])
|
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
|
# includes overrides include_own
|
||||||
actual = broker.get_shard_ranges(includes='b', include_own=True)
|
actual = broker.get_shard_ranges(includes='b', include_own=True)
|
||||||
self.assertEqual([dict(shard_ranges[0])], [dict(sr) for sr in actual])
|
self.assertEqual([dict(shard_ranges[0])], [dict(sr) for sr in actual])
|
||||||
|
|
Loading…
Reference in New Issue