Skip to content

Commit

Permalink
Add bolt reconnection parameter: jraft.bolt.conn.reconnect (sofastack…
Browse files Browse the repository at this point in the history
…#1136)

* add param "jraft.bolt.conn.reconnect"

* add param "jraft.bolt.conn.reconnect"

* refactor

---------

Co-authored-by: yuanyuan.liu <yuanyuan.liu@signalplus.com>
  • Loading branch information
shihuili1218 and yuanyuan.liu authored Aug 7, 2024
1 parent 4d53aa5 commit 79df847
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 + '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 79df847

Please sign in to comment.