From 9f079ee2b45d95a2b46553b06188dbdf891e0404 Mon Sep 17 00:00:00 2001 From: William Song <48054931+SzyWilliam@users.noreply.github.com> Date: Thu, 20 Jun 2024 10:02:52 +0800 Subject: [PATCH] Synchronize takeSnapshotAsync on RaftGroupID (#12767) --- .../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 90816ba6291c..c8fbeea4ced2 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); } }