Skip to content

Introducing periodic topology mechanism for JedisCluster#3596

Merged
sazzad16 merged 8 commits into
redis:masterfrom
yangbodong22011:feature-cluster-periodic-topology-refresh
Nov 2, 2023
Merged

Introducing periodic topology mechanism for JedisCluster#3596
sazzad16 merged 8 commits into
redis:masterfrom
yangbodong22011:feature-cluster-periodic-topology-refresh

Conversation

@yangbodong22011

@yangbodong22011 yangbodong22011 commented Oct 25, 2023

Copy link
Copy Markdown
Contributor

solves #3595

EDIT: The main changes in this PR are as follows:

  1. Add topologyRefreshEnabled and topologyRefreshPeriod to control the periodic topology refresh mechanism.
  2. topologyRefreshExecutor is a single-threaded executor responsible for running TopologyRefreshTask.
  3. Add checkClusterSlotSequence to check whether the cluster slots returned by the server are consecutive and there are no duplicates.
  4. [Test] In JedisClusterTestBase, CLUSTER RESET SOFT was changed to HARD, because SOFT cannot clean up the Redis Cluster configuration and may cause a crash. Please refer to [CRASH] Cluster CLUSTERMSG_EXT_TYPE_FORGOTTEN_NODE redis#12701
  5. [Test] Adjust the cluster-node-timeout in the Makefile to 15s, consistent with the default configuration of Redis.

@yangbodong22011 yangbodong22011 force-pushed the feature-cluster-periodic-topology-refresh branch 5 times, most recently from b50121f to 3100eb8 Compare October 27, 2023 02:00
@yangbodong22011 yangbodong22011 force-pushed the feature-cluster-periodic-topology-refresh branch from 3100eb8 to 2a46e65 Compare October 31, 2023 01:50
@codecov-commenter

codecov-commenter commented Oct 31, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (65ed601) 71.46% compared to head (2ad3381) 71.49%.

❗ Current head 2ad3381 differs from pull request most recent head 9f9f677. Consider uploading reports for the commit 9f9f677 to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3596      +/-   ##
============================================
+ Coverage     71.46%   71.49%   +0.02%     
- Complexity     4848     4860      +12     
============================================
  Files           288      288              
  Lines         15464    15511      +47     
  Branches       1095     1105      +10     
============================================
+ Hits          11051    11089      +38     
- Misses         3934     3938       +4     
- Partials        479      484       +5     
Files Coverage Δ
...redis/clients/jedis/DefaultJedisSocketFactory.java 96.05% <100.00%> (ø)
...rc/main/java/redis/clients/jedis/JedisCluster.java 42.04% <100.00%> (+3.67%) ⬆️
...nts/jedis/providers/ClusterConnectionProvider.java 81.15% <100.00%> (+1.15%) ⬆️
...main/java/redis/clients/jedis/ClusterPipeline.java 75.00% <0.00%> (-12.50%) ⬇️
...ava/redis/clients/jedis/JedisClusterInfoCache.java 77.20% <76.74%> (+0.92%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yangbodong22011

Copy link
Copy Markdown
Contributor Author

@sazzad16 The PR is now available for review, and I have updated the top comments with more details, please take a look at it when you are free.

Comment thread src/main/java/redis/clients/jedis/UnifiedJedis.java Outdated
Comment thread src/main/java/redis/clients/jedis/JedisCluster.java
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
@yangbodong22011

Copy link
Copy Markdown
Contributor Author

notice: #3597 has been included in this PR.

Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
Comment thread src/main/java/redis/clients/jedis/JedisClusterInfoCache.java Outdated
Comment thread src/test/java/redis/clients/jedis/JedisClusterTest.java Outdated
Comment thread src/test/java/redis/clients/jedis/JedisClusterTest.java Outdated
sazzad16
sazzad16 previously approved these changes Oct 31, 2023
Comment thread src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java
@yangbodong22011 yangbodong22011 force-pushed the feature-cluster-periodic-topology-refresh branch from f7f2c5a to 9f9f677 Compare November 2, 2023 12:10
socket.connect(new InetSocketAddress(host.getHostAddress(), hostAndPort.getPort()), connectionTimeout);
// Passing 'host' directly will avoid another call to InetAddress.getByName() inside the InetSocketAddress constructor.
// For machines with ipv4 and ipv6, but the startNode uses ipv4 to connect, the ipv6 connection may fail.
socket.connect(new InetSocketAddress(host, hostAndPort.getPort()), connectionTimeout);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[Adding for future reference:]
Please check #3597 for more information about this change.

@sazzad16 sazzad16 merged commit 5a70626 into redis:master Nov 2, 2023
@yangbodong22011

Copy link
Copy Markdown
Contributor Author

@sazzad16 I will backport it to 4. x and 3. x, WDYT?

@sazzad16

sazzad16 commented Nov 2, 2023

Copy link
Copy Markdown
Contributor

@yangbodong22011 I think I can manage 4.x. You can do it if you want. I'm not doing it now because there will be a patch release for 4 and I don't want to manage more branches (if I can).

About 3.x, I doubt if there will ever be a new 3 minor release.

@yangbodong22011

Copy link
Copy Markdown
Contributor Author

I think I can manage 4.x.

Thank you, that would be great. p.s. I took the initiative to propose a backport, on the one hand because you are busy, and on the other hand, to truly complete it.

About 3.x, I doubt if there will ever be a new 3 minor release.

I believe that this PR is not only an enhancement, but also a fix, and it is worth releasing a 3. x version. If you agree, I can backport to 3.x.

@sazzad16

sazzad16 commented Nov 2, 2023

Copy link
Copy Markdown
Contributor

You can craft both backport PRs if you want. But I can't promise a new 3 release.

yangbodong22011 added a commit to yangbodong22011/jedis that referenced this pull request Nov 3, 2023
The main changes in this PR are as follows:

1. Add `topologyRefreshEnabled` and `topologyRefreshPeriod` to control the periodic topology refresh mechanism.
2. `topologyRefreshExecutor` is a single-threaded executor responsible for running `TopologyRefreshTask`.
3. Add `checkClusterSlotSequence` to check whether the cluster slots returned by the server are consecutive and there are no duplicates.
4. [Test] In JedisClusterTestBase, `CLUSTER RESET SOFT` was changed to `HARD`, because SOFT cannot clean up the Redis Cluster configuration and may cause a crash. Please refer to redis/redis#12701
5. [Test] Adjust the cluster-node-timeout in the Makefile to 15s, consistent with the default configuration of Redis.

---------

* Introducing periodic topology mechanism for JedisCluster

* Apply suggestions from sazzad16

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>

* Remove topologyRefreshEnabled

* Apply suggestions from sazzad16

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>

* remove save topologyRefreshPeriod

* Move INIT_NO_ERROR_PROPERTY to JedisCluster

* add timeout for clusterPeriodTopologyRefreshTest

* Update src/main/java/redis/clients/jedis/DefaultJedisSocketFactory.java

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>

---------

Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
@yangbodong22011

Copy link
Copy Markdown
Contributor Author

@sazzad16 I've backported it to 4.x #3604 . Since 5.x already exists, 3.x may not be supported by us.

agarwalbharat added a commit to agarwalbharat/spring-data-redis that referenced this pull request Dec 23, 2025
Jedis added support of topology refresh and providing a period on which jedis will refresh node topology of cluster.
This was done from jedis version v5.1.0 https://github.com/redis/jedis/releases/tag/v5.1.0
In pr: redis/jedis#3596
agarwalbharat added a commit to agarwalbharat/spring-data-redis that referenced this pull request Dec 23, 2025
Jedis added support of topology refresh and providing a period on which jedis will refresh node topology of cluster.

This was done from jedis version v5.1.0 https://github.com/redis/jedis/releases/tag/v5.1.0
In pr: redis/jedis#3596

Signed-off-by: Bharat Agarwal <agarwalbharat68@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants