Skip to content
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

Renew cluster slots strategy update #2643

Merged

Conversation

yangbodong22011
Copy link
Collaborator

@yangbodong22011 yangbodong22011 commented Sep 9, 2021

This PR solves #2551, a problem solving scenario is as follows:

  1. JedisCluster jc = new JedisCluster(vip); // now vip -> ip1
  2. change vip -> ip2
  3. renewClusterSlots just use getShuffledNodesPool, that is ip1
  4. connect to ip1, and will never connect to ip2

The new strategy is as follows:

  1. First, if jedis(meet JedisRedirectionException) is available, use jedis renew.
  2. Then, we use startNodes to try, as long as startNodes is available,
    whether it is vip, domain, or physical ip, it will succeed.
  3. Finally, we go back to the ShuffledNodesPool and try the remaining physical nodes.

@sazzad16
Copy link
Collaborator

@yangbodong22011 Not only this is a breaking change but also backward incompatible.

  • (Preferable) Could you find a non-breaking solution?
  • If not, at least find a backward compatible solution.
    • Hint: We can handle that startNodes can be null.

You are completely disregarding getShuffledNodesPool(). IMO we should check those first and if no solution is found, then check among startNodes.

@yangbodong22011
Copy link
Collaborator Author

  • (Preferable) Could you find a non-breaking solution?

  • If not, at least find a backward compatible solution.

    • Hint: We can handle that startNodes can be null.

This is not actually a behavior visible to the user, so I think we can modify it without having to be compatible with the old (and may cause errors) logic.

If it should be compatible, maybe we can add a refreshConfigByStartNode option to control the two logics.

I guess the reason you think it should be compatible is that the performance of the getShuffledNodesPool() method will be higher, because operations such as new connections and auth are avoided.

You are completely disregarding getShuffledNodesPool(). IMO we should check those first and if no solution is found, then check among startNodes.

This may be a bit difficult, because we did not distinguish whether the type in NodesPool is MASTER or SLAVE, (we think that MASTER will always belong to the cluster), but there are two solutions:

  • After taking out the Jedis connection, call jedis.clusterNodes() to get your own type (master or slave)
  • When we add to the NodesPool, use the key to record the type, such as nodes.put(127.0.0.1:6379:master, nodePool);

@sazzad16
Copy link
Collaborator

This is not actually a behavior visible to the user, so I think we can modify it without having to be compatible with the old (and may cause errors) logic.

Practically, yes. But theoretically no; because JedisClusterInfoCache is a public class.

I guess the reason you think it should be compatible is that ...

No. If the behavior is changed significantly, we may have to push it for 4.0 instead of 3.x.

@sazzad16
Copy link
Collaborator

@yangbodong22011 WDYT about #2644 ?

@sazzad16 sazzad16 removed this from the 3.8.0 milestone Sep 10, 2021
@yangbodong22011 yangbodong22011 force-pushed the feature-refresh-depends-on-startNodes branch 2 times, most recently from 92014b6 to fc38c53 Compare February 17, 2022 06:27
@yangbodong22011 yangbodong22011 changed the title Renew cluster slots depends on startNodes Renew cluster slots strategy update Feb 17, 2022
@yangbodong22011
Copy link
Collaborator Author

yangbodong22011 commented Feb 17, 2022

@sazzad16 @dengliming PING, pls have a look when you have time.
also updated top comment.

Copy link
Collaborator

@sazzad16 sazzad16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About existing JedisClusterInfoCache constructors, we have to keep those. So, keep these constructors, deprecate these, forward to new constructors (like this(..., ..., (Set<HostAndPort>) null); and handle startNodes == null in other methods.

@yangbodong22011 yangbodong22011 force-pushed the feature-refresh-depends-on-startNodes branch from fc38c53 to 7ba0667 Compare February 17, 2022 06:54
@yangbodong22011
Copy link
Collaborator Author

About existing JedisClusterInfoCache constructors, we have to keep those. So, keep these constructors, deprecate these, forward to new constructors (like this(..., ..., (Set<HostAndPort>) null); and handle startNodes == null in other methods.

done

@yangbodong22011 yangbodong22011 force-pushed the feature-refresh-depends-on-startNodes branch from 7ba0667 to 7f5efba Compare February 17, 2022 07:00
Copy link
Collaborator

@sazzad16 sazzad16 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM so far.

@codecov-commenter
Copy link

codecov-commenter commented Feb 17, 2022

Codecov Report

Merging #2643 (7f5efba) into master (023b362) will decrease coverage by 0.00%.
The diff coverage is 64.28%.

❗ Current head 7f5efba differs from pull request most recent head 873562d. Consider uploading reports for the commit 873562d to get more accurate results

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2643      +/-   ##
============================================
- Coverage     55.03%   55.03%   -0.01%     
- Complexity     3154     3155       +1     
============================================
  Files           195      195              
  Lines         12069    12086      +17     
  Branches        689      690       +1     
============================================
+ Hits           6642     6651       +9     
- Misses         5200     5206       +6     
- Partials        227      229       +2     
Impacted Files Coverage Δ
...rc/main/java/redis/clients/jedis/JedisCluster.java 23.94% <0.00%> (ø)
...ava/redis/clients/jedis/JedisClusterInfoCache.java 75.15% <56.25%> (-4.30%) ⬇️
src/main/java/redis/clients/jedis/Jedis.java 84.84% <100.00%> (-0.01%) ⬇️
src/main/java/redis/clients/jedis/Protocol.java 87.89% <100.00%> (ø)
...nts/jedis/providers/ClusterConnectionProvider.java 78.18% <100.00%> (+3.63%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8476aaf...873562d. Read the comment docs.

This PR solves redis#2551, a problem solving scenario is as follows:

1) JedisCluster jc = new JedisCluster(vip);  // now `vip -> ip1`
2) change `vip -> ip2`
3) renewClusterSlots just use getShuffledNodesPool, that is `ip1`
4) connect to `ip1`, and will never connect to `ip2`

The new strategy is as follows:
1. First, if jedis(meet JedisRedirectionException) is available, use jedis renew.
2. Then, we use startNodes to try, as long as startNodes is available,
    whether it is vip, domain, or physical ip, it will succeed.
3. Finally, we go back to the ShuffledNodesPool and try the remaining physical nodes.
@yangbodong22011 yangbodong22011 force-pushed the feature-refresh-depends-on-startNodes branch from 7f5efba to 873562d Compare February 17, 2022 07:22
@sazzad16 sazzad16 added this to the 4.2.0 milestone Feb 17, 2022
Copy link
Contributor

@dengliming dengliming left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yangbodong22011
Copy link
Collaborator Author

@sazzad16 I would like to backport this PR to version 3.9.x, what do you think?

@sazzad16
Copy link
Collaborator

@yangbodong22011 I may consider it for 3.10.0

@yangbodong22011
Copy link
Collaborator Author

@yangbodong22011 I may consider it for 3.10.0

That's ok, what should I do next? Submit a PR to the 3.x branch?

@sazzad16
Copy link
Collaborator

Submit a PR to the 3.x branch?

That'd be helpful.

yangbodong22011 added a commit to yangbodong22011/jedis that referenced this pull request Apr 12, 2023
@yangbodong22011
Copy link
Collaborator Author

@sazzad16 #3370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants