From 31a2ef1935133f224169a1315a91a2d9e9775d9a Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Thu, 30 May 2013 17:31:26 -0400 Subject: Remove account name from being saved in the object Instead we save the account in the a list, where the index to the account is the partition number. Change-Id: Ie4abefee48a3b237306a1e301ffa798e24e3f1db Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/5120 Reviewed-by: Peter Portante Tested-by: Peter Portante --- gluster/swift/common/ring.py | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'gluster') diff --git a/gluster/swift/common/ring.py b/gluster/swift/common/ring.py index f88af4e..a3209e2 100644 --- a/gluster/swift/common/ring.py +++ b/gluster/swift/common/ring.py @@ -38,12 +38,30 @@ if not reseller_prefix.endswith('_'): class Ring(ring.Ring): + + def __init__(self, *args, **kwargs): + self.false_node = {'zone': 1, 'weight': 100.0, 'ip': '127.0.0.1', + 'id': 0, 'meta': '', 'device': 'volume_not_in_ring', + 'port': 6012} + self.account_list = [] + ring.Ring.__init__(self, *args, **kwargs) + def _get_part_nodes(self, part): seen_ids = set() - nodes = [dev for dev in self._devs if dev['device'] == self.acc_name - and not (dev['id'] in seen_ids or seen_ids.add(dev['id']))] - if not nodes: - nodes = [self.false_node] + + try: + account = self.account_list[part] + except IndexError: + return [self.false_node] + else: + nodes = [] + for dev in self._devs: + if dev['device'] == account: + if dev['id'] not in seen_ids: + seen_ids.add(dev['id']) + nodes.append(dev) + if not nodes: + nodes = [self.false_node] return nodes def get_part_nodes(self, part): @@ -85,15 +103,18 @@ class Ring(ring.Ring): hardware description ====== =============================================================== """ - self.false_node = {'zone': 1, 'weight': 100.0, 'ip': '127.0.0.1', - 'id': 0, 'meta': '', 'device': 'volume_not_in_ring', - 'port': 6012} if account.startswith(reseller_prefix): - self.acc_name = account.replace(reseller_prefix, '', 1) - else: - self.acc_name = account + account = account.replace(reseller_prefix, '', 1) + + # Save the account name in the table + # This makes part be the index of the location of the account + # in the list + try: + part = self.account_list.index(account) + except ValueError: + self.account_list.append(account) + part = self.account_list.index(account) - part = 0 return part, self._get_part_nodes(part) def get_more_nodes(self, part): -- cgit