From 30576591ab27afa6b3f797ad6fe750e6bd4af512 Mon Sep 17 00:00:00 2001 From: szywilliam Date: Wed, 19 Jun 2024 17:11:13 +0800 Subject: [PATCH] Synchronize takeSnapshotAsync on RaftGroupID --- .../iotdb/consensus/ratis/RatisConsensus.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 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 90816ba6291c2..c8fbeea4ced26 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 @@ -771,14 +771,22 @@ public void triggerSnapshot(ConsensusGroupId groupId, boolean force) throws Cons 300000, force ? 1 : 0); - final RaftClientReply reply; - try { - reply = server.get().snapshotManagement(request); - if (!reply.isSuccess()) { - throw new RatisRequestFailedException(reply.getException()); + synchronized (raftGroupId) { + final RaftClientReply reply; + try { + reply = server.get().snapshotManagement(request); + if (!reply.isSuccess()) { + throw new RatisRequestFailedException(reply.getException()); + } + logger.info( + "{} group {}: successfully taken snapshot at index {} with force = {}", + this, + raftGroupId, + reply.getLogIndex(), + force); + } catch (IOException ioException) { + throw new RatisRequestFailedException(ioException); } - } catch (IOException ioException) { - throw new RatisRequestFailedException(ioException); } }