From 79df847a7defb06a5fa46f1852638ed601f2fc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8A=E6=85=A7=E5=88=A9?= Date: Wed, 7 Aug 2024 14:12:11 +0800 Subject: [PATCH] Add bolt reconnection parameter: jraft.bolt.conn.reconnect (#1136) * add param "jraft.bolt.conn.reconnect" * add param "jraft.bolt.conn.reconnect" * refactor --------- Co-authored-by: yuanyuan.liu --- .../alipay/sofa/jraft/option/RpcOptions.java | 18 +++++++++++++++++- .../sofa/jraft/rpc/impl/BoltRpcClient.java | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/jraft-core/src/main/java/com/alipay/sofa/jraft/option/RpcOptions.java b/jraft-core/src/main/java/com/alipay/sofa/jraft/option/RpcOptions.java index 3c75ad7c9..4e0f40d2e 100644 --- a/jraft-core/src/main/java/com/alipay/sofa/jraft/option/RpcOptions.java +++ b/jraft-core/src/main/java/com/alipay/sofa/jraft/option/RpcOptions.java @@ -16,6 +16,7 @@ */ package com.alipay.sofa.jraft.option; +import com.alipay.sofa.jraft.util.SystemPropertyUtil; import com.alipay.sofa.jraft.util.concurrent.FixedThreadsExecutorGroup; import com.codahale.metrics.MetricRegistry; @@ -62,6 +63,12 @@ public class RpcOptions { */ private FixedThreadsExecutorGroup appendEntriesExecutors; + /** + * Whether to enable bolt reconnection, default enabled(true). + */ + private boolean enableBoltReconnect = SystemPropertyUtil.getBoolean( + "jraft.bolt.conn.reconnect", true); + public int getRpcConnectTimeoutMs() { return this.rpcConnectTimeoutMs; } @@ -118,11 +125,20 @@ public void setAppendEntriesExecutors(FixedThreadsExecutorGroup appendEntriesExe this.appendEntriesExecutors = appendEntriesExecutors; } + public boolean isEnableBoltReconnect() { + return enableBoltReconnect; + } + + public void setEnableBoltReconnect(boolean enableBoltReconnect) { + this.enableBoltReconnect = enableBoltReconnect; + } + @Override public String toString() { return "RpcOptions{" + "rpcConnectTimeoutMs=" + rpcConnectTimeoutMs + ", rpcDefaultTimeout=" + rpcDefaultTimeout + ", rpcInstallSnapshotTimeout=" + rpcInstallSnapshotTimeout + ", rpcProcessorThreadPoolSize=" + rpcProcessorThreadPoolSize + ", enableRpcChecksum=" - + enableRpcChecksum + ", metricRegistry=" + metricRegistry + '}'; + + enableRpcChecksum + ", metricRegistry=" + metricRegistry + ", enableBoltReconnect=" + + enableBoltReconnect + '}'; } } diff --git a/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/BoltRpcClient.java b/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/BoltRpcClient.java index 2ba5c6a7c..6a45ca65f 100644 --- a/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/BoltRpcClient.java +++ b/jraft-core/src/main/java/com/alipay/sofa/jraft/rpc/impl/BoltRpcClient.java @@ -57,7 +57,7 @@ public boolean init(final RpcOptions opts) { this.rpcClient.option(BoltClientOption.NETTY_FLUSH_CONSOLIDATION, true); this.rpcClient.initWriteBufferWaterMark(BoltRaftRpcFactory.CHANNEL_WRITE_BUF_LOW_WATER_MARK, BoltRaftRpcFactory.CHANNEL_WRITE_BUF_HIGH_WATER_MARK); - this.rpcClient.enableReconnectSwitch(); + this.rpcClient.option(BoltClientOption.CONN_RECONNECT_SWITCH, opts.isEnableBoltReconnect()); this.rpcClient.startup(); return true; }