config-file.yaml設定ファイルにRedisサーバーのアドレス、ポート、パスワード、およびtimeout(3000ms)などの情報を設定します。設定情報に基づいて、Redisへの接続を確立します。package org.example;// Redisson関連のパッケージをインポートします。import org.redisson.Redisson;import org.redisson.api.RAtomicLong;import org.redisson.api.RedissonClient;import org.redisson.config.Config;import org.redisson.connection.balancer.RoundRobinLoadBalancer;// Java IO関連のパッケージをインポートします。import java.io.File;import java.io.IOException;public class Main {public static void main(String[] args) throws IOException {// YAMLファイルからRedissonの設定情報を読み取ります。Config config = Config.fromYAML(new File("/data/home/test**/redissontest/src/main/resources/config-file.yaml"));RedissonClient redisson = Redisson.create(config);// カウンタ変数を初期化します。int i = 0;// 1000000回ループします。while(i++ < 1000000){// 現在のカウンタ値をキーとして、アトミックな長整数オブジェクトを取得します。RAtomicLong atomicLong = redisson.getAtomicLong(Integer.toString(i));// アトミックな長整数オブジェクトの値に対してアトミックに1を減算する操作を実行します。atomicLong.getAndDecrement();}// Redissonクライアントを閉じます。redisson.shutdown();}}
sudo iptables -A INPUT -s 10.0.16.6 -p tcp --sport 6379 -m conntrack --ctstate NEW,ESTABLISHED -j DROP

sudo iptables -D INPUT -s 10.0.16.6 -p tcp --sport 6379 -m conntrack --ctstate NEW,ESTABLISHED -j DROP


Unable to send PING command over channelが発生したため、PingConnectionHandlerのコードを確認します。以下に示します。PING再接続検出が失敗してエラーが発生した後、ctx.channel().close()を実行して異常なchannelを閉じ、さらにconnection.getRedisClient().getConfig().getFailedNodeDetector().onPingFailed();を実行して現在の接続クライアントの状態を検出していることがわかります。if(connection.getUsage() == 0 && future != null && (future.cancel(false) || cause(future) != null)) {Throwable cause = cause(future);if (!(cause instanceof RedisRetryException)) {if (!future.isCancelled()) {log.error("Unable to send PING command over channel: {}", ctx.channel(), cause);}log.debug("channel: {} closed due to PING response timeout set in {} ms", ctx.channel(), config.getPingConnectionInterval());ctx.channel().close();connection.getRedisClient().getConfig().getFailedNodeDetector().onPingFailed();} else {connection.getRedisClient().getConfig().getFailedNodeDetector().onPingSuccessful();sendPing(ctx);}} else {connection.getRedisClient().getConfig().getFailedNodeDetector().onPingSuccessful();sendPing(ctx);}
RedisConnection connection = RedisConnection.getFrom(ctx.channel());接続を作成するコンストラクタRedisConnection()を確認します。以下に示します。この関数はchannel属性を作成・更新し、接続の最終使用時刻を記録しますが、新しいChannelに切り替えて接続を試みる動作はありません。public <C> RedisConnection(RedisClient redisClient, Channel channel, CompletableFuture<C> connectionPromise) {this.redisClient = redisClient;this.connectionPromise = connectionPromise;updateChannel(channel);lastUsageTime = System.nanoTime();LOG.debug("Connection created {}", redisClient);}// updateChannelはChannelの属性を更新します。public void updateChannel(Channel channel) {if (channel == null) {throw new NullPointerException();}this.channel = channel;channel.attr(CONNECTION).set(this);}
ERROR org.redisson.cluster.ClusterConnectionManager - Can't update cluster stateorg.redisson.client.RedisTimeoutException: Command execution timeout for command: (CLUSTER NODES), params: [], Redis client: [addr=redis://10.0.16.7:6379] at org.redisson.client.RedisConnection.lambda$async$0(RedisConnection.java:256) at io.netty.util.HashedWheelTimer$HashedWheelTimeout.run(HashedWheelTimer.java:715) at io.netty.util.concurrent.ImmediateExecutor.execute(ImmediateExecutor.java:34) at io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:703) at io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:790) at io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:503) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:829)
ClusterConnectionManager.javaでクラスタ更新のエラーメッセージ部分を特定できます。 Can't update cluster state例外がスローされた後、クラスタ状態の変更のみを確認し、接続プールから新しい接続を取得して操作する動作は行わず、そのまま返していることがわかります。private void checkClusterState(ClusterServersConfig cfg, Iterator<RedisURI> iterator, AtomicReference<Throwable> lastException) {if (!iterator.hasNext()) {if (lastException.get() != null) {log.error("Can't update cluster state", lastException.get());}// クラスタ状態の変更を確認します。scheduleClusterChangeCheck(cfg);return;}......}
package org.example;import org.redisson.Redisson;import org.redisson.api.RAtomicLong;import org.redisson.api.RedissonClient;import org.redisson.config.Config;import org.redisson.connection.balancer.RoundRobinLoadBalancer;import java.io.File;import java.io.IOException;public class Main {public static void main(String[] args) throws IOException {boolean connected = false;RedissonClient redisson = null;while (!connected) {try {Config config = Config.fromYAML(new File("/data/home/sharmaxia/redissontest/src/main/resources/config-file.yaml"));redisson = Redisson.create(config);connected = true;} catch (Exception e) {e.printStackTrace();try {Thread.sleep(1000);} catch (InterruptedException ex) {Thread.currentThread().interrupt(); //現在のスレッドを能動的に中断し、接続プールから接続を再取得します。}}}int i = 0;while (i++ < 1000000) {try {RAtomicLong atomicLong = redisson.getAtomicLong(Integer.toString(i));atomicLong.getAndDecrement();} catch (Exception e) {e.printStackTrace();try {Thread.sleep(1000);} catch (InterruptedException ex) {Thread.currentThread().interrupt(); //現在のスレッドを能動的に中断し、接続プールから接続を再取得します。}i--;}}redisson.shutdown();}}


フィードバック