diff --git a/swift/container/backend.py b/swift/container/backend.py index 3d3338c84d..8684a75d5f 100644 --- a/swift/container/backend.py +++ b/swift/container/backend.py @@ -1996,26 +1996,36 @@ class ContainerBroker(DatabaseBroker): self.update_metadata({'X-Container-Sysmeta-Shard-' + key: (value, Timestamp.now().internal)}) - def get_sharding_sysmeta(self, key=None, include_timestamps=False): + def get_sharding_sysmeta_with_timestamps(self): + """ + Returns sharding specific info from the broker's metadata with + timestamps. + + :param key: if given the value stored under ``key`` in the sharding + info will be returned. + :return: a dict of sharding info with their timestamps. + """ + prefix = 'X-Container-Sysmeta-Shard-' + return { + k[len(prefix):]: v + for k, v in self.metadata.items() + if k.startswith(prefix) + } + + def get_sharding_sysmeta(self, key=None): """ Returns sharding specific info from the broker's metadata. :param key: if given the value stored under ``key`` in the sharding info will be returned. - :param include_timestamps: bool, return the metadata timestamps - along with the metadata. I.e last modified timestamp. :return: either a dict of sharding info or the value stored under ``key`` in that dict. """ - prefix = 'X-Container-Sysmeta-Shard-' - metadata = self.metadata - info = dict((k[len(prefix):], v if include_timestamps else v[0]) - for k, v in metadata.items() if k.startswith(prefix)) + info = self.get_sharding_sysmeta_with_timestamps() if key: - if include_timestamps: - return info.get(key, (None, None)) - return info.get(key) - return info + return info.get(key, (None, None))[0] + else: + return {k: v[0] for k, v in info.items()} def _load_root_info(self): """ diff --git a/swift/container/sharder.py b/swift/container/sharder.py index 79215b8300..b4d86628d6 100644 --- a/swift/container/sharder.py +++ b/swift/container/sharder.py @@ -250,7 +250,7 @@ class CleavingContext(object): :return: list of tuples of (CleavingContext, timestamp) """ brokers = broker.get_brokers() - sysmeta = brokers[-1].get_sharding_sysmeta(include_timestamps=True) + sysmeta = brokers[-1].get_sharding_sysmeta_with_timestamps() for key, (val, timestamp) in sysmeta.items(): # If the value is of length 0, then the metadata is