Commits

Adam Lindsay  committed 1958ba2

Backed out changes that changed the mixing algorithm for hash_ring.py

  • Participants
  • Parent commits 8bf6cdd

Comments (0)

Files changed (23)

File .hgignore

File contents unchanged.

File LICENSE

File contents unchanged.

File README.mdown

 
 There are two primary thrift interfaces exposed in locator.thrift:
 `locator.Base` and `locator.Locator`. `Locator.Base` supports primal methods
-such as `ping()`, `service\_type()`, `service\_types()`, and `die()`, that
+such as `ping()`, `service_type()`, `service_types()`, and `die()`, that
 don't rely on any of the locator services. `Locator.Locator` implements basic
 node location and management: propagating and dropping services on the
 network. When creating your own thrift definition, your service should import

File TODO

File contents unchanged.

File diststore.thrift

File contents unchanged.

File gen-py/__init__.py

File contents unchanged.

File gen-py/diststore/Store.py

File contents unchanged.

File gen-py/diststore/__init__.py

File contents unchanged.

File gen-py/diststore/constants.py

File contents unchanged.

File gen-py/diststore/ttypes.py

File contents unchanged.

File gen-py/locator/Base.py

File contents unchanged.

File gen-py/locator/Locator.py

File contents unchanged.

File gen-py/locator/__init__.py

File contents unchanged.

File gen-py/locator/constants.py

File contents unchanged.

File gen-py/locator/ttypes.py

File contents unchanged.

File hash_ring.py

 # Pretty radically changed by atl on 2009.04.28:
 # added append/extend/remove methods (bugfix 2009.05.18)
 # made nodes a set to accommodate that more easily/naturally
+# Backed out of changes that modified the node mixing (2009.09.18)
 #
 # __getindex__() to support dict-like access::
 #   ring.get_node('a') == ring['a']
 #
-# changed hash values around so that::
-#   ring.gen_key('greenwood') == int(md5.new('greenwood').hexdigest()[0:8], base=16)
-# ... generating the key is the same as the most significant quarter of the md5 hash
-#
-# changed the logic so that passing in a hex digest::
-#   ring.gen_key('a') == ring.gen_key(md5.new('a').hexdigest())
-# ...does not hash again
-# This last one may make things unsuitable for other people.
 
 import md5
 import math
             if node in self.weights:
                 weight = self.weights.get(node)
 
-            factor = math.floor((30*len(self.nodes)*weight) / total_weight);
+            factor = math.floor((40*len(self.nodes)*weight) / total_weight);
 
             for j in xrange(0, int(factor)):
                 b_key = self._hash_digest( '%s-%s' % (node, j) )
 
-                for i in xrange(0, 4):
-                    key = self._hash_val(b_key, i*4)
+                for i in xrange(0, 3):
+                    key = self._hash_val(b_key, lambda x: x+i*4)
                     self.ring[key] = node
                     self._sorted_keys.append(key)
 
 
         md5 is currently used because it mixes well.
         """
-        if len(key) == 32 and all([f.lower() in HEXDIGITS for f in key]):
-            return int(key[0:8], base=16)
         b_key = self._hash_digest(key)
-        return self._hash_val(b_key, 0)
+        return self._hash_val(b_key, lambda x: x)
 
-    def _hash_val(self, b_key, offset):
-        return (( b_key[0] << (24 + offset))
-                |(b_key[1] << (16 + offset))
-                |(b_key[2] << ( 8 + offset))
-                |(b_key[3] << ( 0 + offset)))
+    def _hash_val(self, b_key, entry_fn):
+        return (( b_key[entry_fn(3)] << 24)
+                |(b_key[entry_fn(2)] << 16)
+                |(b_key[entry_fn(1)] << 8)
+                | b_key[entry_fn(0)] )
 
     def _hash_digest(self, key):
         m = md5.new()

File location.py

File contents unchanged.

File locator.thrift

File contents unchanged.

File storeget.py

File contents unchanged.

File storeprimer.py

File contents unchanged.

File storeput.py

File contents unchanged.

File storeserver.py

File contents unchanged.

File storetest.py

File contents unchanged.