szetszwo commented on PR #1207:
URL: https://github.com/apache/ratis/pull/1207#issuecomment-2575998526

   @OneSizeFitsQuorum , The manual trigger snapshot cannot be completed since 
StateMachineUpdater is looping in waitForCommit().  IoTDB may retry 
indefinitely but it could never succeed.
   
   However, if we let StateMachineUpdater pass waitForCommit() without 
satisfying the basic Raft condition
   - `appliedIndex <= commitIndex`,
   
   we may get some wired bugs later on.
   
   So, how about we let it take snapshot within waitForCommit()?
   ```java
   diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotManagementRequestHandler.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotManagementRequestHandler.java
   index 8632242b18..9c73cb1e32 100644
   --- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotManagementRequestHandler.java
   +++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/SnapshotManagementRequestHandler.java
   @@ -113,6 +113,10 @@ class SnapshotManagementRequestHandler {
        return 
pending.get().map(PendingRequest::shouldTriggerTakingSnapshot).orElse(false);
      }
    
   +  boolean hasPendingRequest() {
   +    return pending.get().isPresent();
   +  }
   +
      void completeTakingSnapshot(long index) {
        pending.getAndSetNull().ifPresent(p -> p.complete(index));
      }
   diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java
   index f13ee0d6d2..7474d2606f 100644
   --- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java
   +++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/StateMachineUpdater.java
   @@ -216,6 +216,10 @@ class StateMachineUpdater implements Runnable {
        // Thus it is possible to have applied > committed initially.
        final long applied = getLastAppliedIndex();
        for(; applied >= raftLog.getLastCommittedIndex() && state == 
State.RUNNING && !shouldStop(); ) {
   +      if (server.getSnapshotRequestHandler().hasPendingRequest()) {
   +        takeSnapshot();
   +      }
   +
          if (awaitForSignal.await(100, TimeUnit.MILLISECONDS)) {
            return;
          }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to