After doing it, the mark_connection_up method from nydus.db.routers.keyvalue.ConsistentHashingRouter is called twice, one for each server that went up.
mark_connection_up called with db_num parameter as 0 (host key)
check if the node isn't in the up nodes list (the if condition of this pull request)
self._hash.get_node(node_key) is None: #returns None, so add the node
self._hash.add_node(node_key)
The result of self._hash.get_node(node_key) is None, so, add node_key redis://localhost:6290/0ConsistentHashingRouter._hash.nodes is now set(['redis://localhost:6290/0'])
In the second call, the condition returns the first node added instead of returning None, as expected. I think it's a bug from get_node method.
# node_key is `redis://localhost:6291/0`
self._hash.get_node(node_key) is None: # returns redis://localhost:6290/0
self._hash.add_node(node_key)
Isn't None, so, don't add the node
Is there a bug with get_node method?
If no, please, revert this pull request.
If you need more information about this bug, let me know.
Hi @dcramer.
After this pull request, I found a bug. These are the steps to reproduce the bug:
1- Start at least 2 redis servers.
2- Run some application that uses nydus.db.create_cluster method to handle the redis cluster. In my case, I started a simple flask application.
3- Restart the redis server.
After doing it, the
mark_connection_up
method fromnydus.db.routers.keyvalue.ConsistentHashingRouter
is called twice, one for each server that went up.In the first call, the condition I added in this pull request returns
None
as expected, because ketama nodes are empty (the servers were down).What happens:
mark_connection_up
called withdb_num
parameter as0
(host key)if
condition of this pull request)self._hash.get_node(node_key)
is None, so, add node_keyredis://localhost:6290/0
ConsistentHashingRouter._hash.nodes
is nowset(['redis://localhost:6290/0'])
In the second call, the condition returns the first node added instead of returning None, as expected. I think it's a bug from
get_node
method.Is there a bug with
get_node
method? If no, please, revert this pull request.If you need more information about this bug, let me know.
Thanks in advance.