Skip to content

Commit

Permalink
Fixed the logic that prevents all cluster slot requests sent to speci…
Browse files Browse the repository at this point in the history
…fic instances (#1928)

* Fixed the logic that prevents all cluster slot requests sent to specific instances when jedis is initialized on many processes(such as storm with a lot of works), It can cause high CPU and the impact of many slow queries.

* Replace each tab with two spaces.

* merge

* reduce one possible import

Co-authored-by: wenjian.wu <wenjian.wu@vipshop.com>
Co-authored-by: dengliming <liming.d.pro@gmail.com>
Co-authored-by: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com>
  • Loading branch information
4 people authored Mar 24, 2021
1 parent b9e1553 commit 557cdea
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package redis.clients.jedis;

import java.io.Closeable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import javax.net.ssl.HostnameVerifier;
Expand Down Expand Up @@ -117,8 +119,10 @@ public Map<String, JedisPool> getNodes() {
}

private void initializeSlotsCache(Set<HostAndPort> startNodes, JedisClientConfig clientConfig) {
ArrayList<HostAndPort> startNodeList = new ArrayList<>(startNodes);
Collections.shuffle(startNodeList);

for (HostAndPort hostAndPort : startNodes) {
for (HostAndPort hostAndPort : startNodeList) {
try (Jedis jedis = new Jedis(hostAndPort, clientConfig)) {
cache.discoverClusterNodesAndSlots(jedis);
return;
Expand Down

0 comments on commit 557cdea

Please sign in to comment.