From b85f69ed70032d44bdc8a9e7626d4b2dcf38da04 Mon Sep 17 00:00:00 2001 From: Wu Wenxiang Date: Tue, 18 Dec 2012 17:29:16 +0800 Subject: [PATCH] Refactor Ring::get_nodes() and Ring::get_part_nodes() Add a _get_part_nodes() method in Ring class, then call it in Ring::get_nodes() and Ring::get_part_nodes(). In order to reduce duplicate codes. Change-Id: Id92f8dfd08388305638a2ba2ab64e77545c14cba --- swift/common/ring/ring.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/swift/common/ring/ring.py b/swift/common/ring/ring.py index 1f97ee2ccb..bc76e42e17 100644 --- a/swift/common/ring/ring.py +++ b/swift/common/ring/ring.py @@ -182,6 +182,11 @@ class Ring(object): """ return getmtime(self.serialized_path) != self._mtime + def _get_part_nodes(self, part): + seen_ids = set() + return [self._devs[r[part]] for r in self._replica2part2dev_id + if not (r[part] in seen_ids or seen_ids.add(r[part]))] + def get_part_nodes(self, part): """ Get the nodes that are responsible for the partition. If one @@ -196,9 +201,7 @@ class Ring(object): if time() > self._rtime: self._reload() - seen_ids = set() - return [self._devs[r[part]] for r in self._replica2part2dev_id - if not (r[part] in seen_ids or seen_ids.add(r[part]))] + return self._get_part_nodes(part) def get_nodes(self, account, container=None, obj=None): """ @@ -232,9 +235,7 @@ class Ring(object): if time() > self._rtime: self._reload() part = struct.unpack_from('>I', key)[0] >> self._part_shift - seen_ids = set() - return part, [self._devs[r[part]] for r in self._replica2part2dev_id - if not (r[part] in seen_ids or seen_ids.add(r[part]))] + return part, self._get_part_nodes(part) def get_more_nodes(self, part): """