in pyignite/client.py [0:0]
def _get_node_by_hashcode(self, cache_id, hashcode, parts):
"""
Get node by key hashcode. Calculate partition and return node on that it is primary.
(algorithm is taken from `RendezvousAffinityFunction.java`)
"""
# calculate partition for key or affinity key
# (algorithm is taken from `RendezvousAffinityFunction.java`)
mask = parts - 1
if parts & mask == 0:
part = (hashcode ^ (unsigned(hashcode) >> 16)) & mask
else:
part = abs(hashcode // parts)
assert 0 <= part < parts, 'Partition calculation has failed'
node_mapping = self._cache_partition_mapping(cache_id).get('node_mapping')
if not node_mapping:
return None
node_uuid, best_conn = None, None
for u, p in node_mapping.items():
if part in p:
node_uuid = u
break
if node_uuid:
for n in self._nodes:
if n.uuid == node_uuid:
best_conn = n
break
if best_conn and best_conn.alive:
return best_conn