This is an automated email from the ASF dual-hosted git repository.

tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new dfb538d1aa [IOTDB-3516] Add trigger snapshot implementation for 
RatisConsensus (#6305)
dfb538d1aa is described below

commit dfb538d1aacd3b853eaa8e5fe33e1f6df0f8293f
Author: William Song <[email protected]>
AuthorDate: Fri Jun 17 11:17:19 2022 +0800

    [IOTDB-3516] Add trigger snapshot implementation for RatisConsensus (#6305)
    
    * add trigger snapshot
    
    * spotless
    
    * local call
    
    * add todo
---
 .../iotdb/consensus/ratis/RatisConsensus.java      | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git 
a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java 
b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
index e84e3fdb46..726012a3ed 100644
--- 
a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
+++ 
b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
@@ -58,6 +58,7 @@ import org.apache.ratis.protocol.RaftGroup;
 import org.apache.ratis.protocol.RaftGroupId;
 import org.apache.ratis.protocol.RaftPeer;
 import org.apache.ratis.protocol.RaftPeerId;
+import org.apache.ratis.protocol.SnapshotManagementRequest;
 import org.apache.ratis.protocol.exceptions.NotLeaderException;
 import org.apache.ratis.server.DivisionInfo;
 import org.apache.ratis.server.RaftServer;
@@ -530,7 +531,26 @@ class RatisConsensus implements IConsensus {
 
   @Override
   public ConsensusGenericResponse triggerSnapshot(ConsensusGroupId groupId) {
-    return ConsensusGenericResponse.newBuilder().setSuccess(false).build();
+    RaftGroupId raftGroupId = Utils.fromConsensusGroupIdToRaftGroupId(groupId);
+    RaftGroup groupInfo = getGroupInfo(raftGroupId);
+
+    if (groupInfo == null || !groupInfo.getPeers().contains(myself)) {
+      return failed(new ConsensusGroupNotExistException(groupId));
+    }
+
+    // TODO tuning snapshot create timeout
+    SnapshotManagementRequest request =
+        SnapshotManagementRequest.newCreate(
+            localFakeId, myself.getId(), raftGroupId, 
localFakeCallId.incrementAndGet(), 30000);
+
+    RaftClientReply reply;
+    try {
+      reply = server.submitClientRequest(request);
+    } catch (IOException ioException) {
+      return failed(new RatisRequestFailedException(ioException));
+    }
+
+    return 
ConsensusGenericResponse.newBuilder().setSuccess(reply.isSuccess()).build();
   }
 
   private ConsensusGenericResponse failed(ConsensusException e) {

Reply via email to