-
Notifications
You must be signed in to change notification settings - Fork 994
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RedisClusterNode.hasSameSlotsAs() is unreliable #2341
Comments
It makes sense to fix this problem. Since you've looked already into it, do you want to submit a pull request along with a few unit test cases? |
@mp911de , @jacob-pro I really want to give it a try! |
On second thought🤔🤔🤔, don't need to check the conditions to assigned a slot when creating a node. Just check if it's slot.empty(). What do you think of my opinion? Please review it.🙇🏻🙇🏻🙇🏻 |
…de's constructors
…terNode constructors
…nstructor and compare the two clusters with hasSameSlotsAs()
…tructors (#2852) * fix(#2341): Initialize slots with empty BitSet in RedisClusterNode's constructors * test(#2341): Add test cases for slot initialization in RedisClusterNode constructors * fix(#2341): Initialize RedisClusterNode slots with SlotHash.SLOT_COUNT * chore(#2341): Adjust the formatting * test(#2341):Add test cases for hasSameSlotsAs() * fix(#2341): Clone node2 from node1 using the RedisClusterNode constructor and compare the two clusters with hasSameSlotsAs()
Bug Report
Current Behavior
When using the
RedisClusterNode::hasSameSlotsAs()
function to compare nodes retrieved fromRedisClusterClient::getPartitions()
against nodes fromClusterPartitionParser::parse
(viaRedisClusterCommands::clusterNodes
) it incorrectly returns false.This is because the nodes in the client partitions table have a slot range of
null
whereas the parsed nodes have a non null but empty slot range.The parsed nodes are created with a non-null BitSet even if they have no slots:
https://github.com/lettuce-io/lettuce-core/blob/fc6630e0fdd46e175e1d51a2491732092bb683ff/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java#L102-L103
Whereas cloned nodes are created with a null BitSet if the slots are empty:
https://github.com/lettuce-io/lettuce-core/blob/fc6630e0fdd46e175e1d51a2491732092bb683ff/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java#L122-L125
Updating the slots also leaves the value as null if the new range is empty:
https://github.com/lettuce-io/lettuce-core/blob/fc6630e0fdd46e175e1d51a2491732092bb683ff/src/main/java/io/lettuce/core/cluster/models/partitions/RedisClusterNode.java#L332-L334
Environment
Additional context
Similar / related to:
#1091
#1089
The text was updated successfully, but these errors were encountered: