This is an automated email from the ASF dual-hosted git repository. tanxinyu pushed a commit to branch fix_ratis_recover_failure in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 709735d1970203dffc820b301e5867d812e79189 Author: OneSizeFitQuorum <[email protected]> AuthorDate: Mon May 20 16:31:36 2024 +0800 fix Signed-off-by: OneSizeFitQuorum <[email protected]> --- .../java/org/apache/iotdb/consensus/ratis/RatisConsensus.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java index de646de2334..235556ccced 100644 --- a/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java +++ b/iotdb-core/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java @@ -115,8 +115,8 @@ class RatisConsensus implements IConsensus { private final RaftPeer myself; private final File storageDir; - - private final RaftServer server; + private final RaftServer.Builder serverBuilder; + private RaftServer server; private final RaftProperties properties = new RaftProperties(); private final RaftClientRpc clientRpc; @@ -195,7 +195,8 @@ class RatisConsensus implements IConsensus { clientRpc = new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), properties); - server = + // do not build server in constructor in case stateMachine is not ready + serverBuilder = RaftServer.newBuilder() .setServerId(myself.getId()) .setProperties(properties) @@ -205,12 +206,12 @@ class RatisConsensus implements IConsensus { new ApplicationStateMachineProxy( registry.apply(Utils.fromRaftGroupIdToConsensusGroupId(raftGroupId)), raftGroupId, - this::onLeaderChanged)) - .build(); + this::onLeaderChanged)); } @Override public synchronized void start() throws IOException { + server = serverBuilder.build(); MetricService.getInstance().addMetricSet(this.ratisMetricSet); server.start(); registerAndStartDiskGuardian();
