Use self.__class__.X instead of self.X

The variable '_hash_rings' is being referenced by both
self.__class__._hash_rings (for assigning) and self._hash_rings (for
reading).

Instead use only self.__class__._hash_rings to be consistent. This
should be less confusing. Before the reader had to know the scoping
rules and that reading self._hash_rings was actually reading
self.__class__._hash_rings. But assigning to self._hash_rings would
create a new instance variable instead of updating the class level
self.__class__._hash_rings.

This change will hopefully make the code easier to read and understand.

Change-Id: I6c38962ee6c8d6b341a04efaffa8e7a0f53bfbe5
This commit is contained in:
John L. Villalovos
2015-10-22 08:30:12 -07:00
parent fc51cc9939
commit 874b54d478

View File

@@ -177,15 +177,15 @@ class HashRingManager(object):
interval = CONF.hash_ring_reset_interval
limit = time.time() - interval
# Hot path, no lock
if self._hash_rings is not None and self.updated_at >= limit:
return self._hash_rings
if self.__class__._hash_rings is not None and self.updated_at >= limit:
return self.__class__._hash_rings
with self._lock:
if self._hash_rings is None or self.updated_at < limit:
if self.__class__._hash_rings is None or self.updated_at < limit:
rings = self._load_hash_rings()
self.__class__._hash_rings = rings
self.updated_at = time.time()
return self._hash_rings
return self.__class__._hash_rings
def _load_hash_rings(self):
rings = {}