bitwalker/libring

issue adding pids with the same number in different nodes

peillis opened this issue · 1 comments

I don't know if this is an issue of this lib or is elsewhere, but when adding pids to a HashRing I get this problem:
Suppose pid1 = #PID<0.433.0> and pid2 = #PID<21396.433.0>
Processes in different nodes.

> r = HashRing.new()
#<Ring[]>
> r = HashRing.add_node(r, pid1)
#<Ring[#PID<0.433.0>]>
> r = HashRing.add_node(r, pid2)
#<Ring[#PID<0.433.0>]>

It's like they were the same for HashRing

This is an issue with using pids as node names, as :erlang.phash2 ignores the node component of the pid, so in your case above, only the node component differs, so they are considered equivalent. I'm not sure why this behavior exists. It's best to avoid using pids alone as nodes, another option is to use {node(), pid()} as a key, that way the hash will be unique, and you can still easily obtain the original pid. You could also use pid_to_list and list_to_pid to serialize/deserialize them for hashing/storage in the ring.