szetszwo commented on code in PR #1647:
URL: https://github.com/apache/ratis/pull/1647#discussion_r4303235487


##########
ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java:
##########
@@ -243,6 +243,33 @@ default void notifyServerShutdown(RoleInfoProto roleInfo) {
      * @param allServer whether all raft servers will be shutdown at this time
      */
     default void notifyServerShutdown(RoleInfoProto roleInfo, boolean 
allServer) {}
+
+    /**
+     * Notify the {@link StateMachine} that the shutdown of the server for 
this division has started.
+     * @deprecated please use/override {@link 
#notifyServerShutdownStarted(RoleInfoProto, boolean)} instead
+     */
+    @Deprecated
+    default void notifyServerShutdownStarted(RoleInfoProto roleInfo) {
+      notifyServerShutdownStarted(roleInfo, false);
+    }
+
+    /**
+     * Notify the {@link StateMachine} that the shutdown of either the server 
for this division
+     * or all the servers has started.
+     * <p>
+     * In contrast to {@link #notifyServerShutdown(RoleInfoProto, boolean)}, 
which is invoked once the shutdown
+     * has completed, this method is invoked before the shutdown has closed 
any resources.
+     * In particular, it is invoked before waiting for the committed log 
entries to be applied to this
+     * {@link StateMachine}, which is unbounded in time.  An application 
embedding a {@link RaftServer} can use
+     * this notification to react immediately, e.g. to reject incoming 
requests or to terminate itself,
+     * instead of waiting for the shutdown to complete.
+     * <p>
+     * This method is invoked from the shutdown path, so an implementation 
must return promptly.
+     *
+     * @param roleInfo roleInfo this server
+     * @param allServer whether all raft servers will be shutdown at this time
+     */
+    default void notifyServerShutdownStarted(RoleInfoProto roleInfo, boolean 
allServer) {}

Review Comment:
   @amaliujia , thanks for working on this!
   
   Please deprecate and override the existing `notifyServerShutdown` method:
   ```diff
   diff --git 
a/ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java
 
b/ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java
   index bd009b0e9..d12cc3f3f 100644
   --- 
a/ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java
   +++ 
b/ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java
   @@ -58,6 +58,11 @@ import java.util.function.Function;
    public interface StateMachine extends Closeable {
      Logger LOG = LoggerFactory.getLogger(StateMachine.class);
    
   +  enum TaskStatus {
   +    INITIATED,
   +    COMPLETED
   +  }
   +
      /** A registry to support different state machines in multi-raft 
environment. */
      interface Registry extends Function<RaftGroupId, StateMachine> {
      }
   @@ -229,20 +234,33 @@ public interface StateMachine extends Closeable {
        default void notifySnapshotInstalled(InstallSnapshotResult result, long 
snapshotIndex,  RaftPeer peer) {}
    
        /**
   -     * Notify the {@link StateMachine} that the server for this division 
has been shut down.
   -     * @deprecated please use/override {@link 
#notifyServerShutdown(RoleInfoProto, boolean)} instead
   +     * The same as notifyServerShutdown(roleInfo, false, 
TaskStatus.COMPLETED).
   +     *
   +     * @deprecated please use/override {@link 
#notifyServerShutdown(RoleInfoProto, boolean, TaskStatus)} instead
         */
        @Deprecated
        default void notifyServerShutdown(RoleInfoProto roleInfo) {
   -      notifyServerShutdown(roleInfo, false);
   +      notifyServerShutdown(roleInfo, false, TaskStatus.COMPLETED);
   +    }
   +
   +    /**
   +     * The same as notifyServerShutdown(roleInfo, allServer, 
TaskStatus.COMPLETED).
   +     *
   +     * @deprecated please use/override {@link 
#notifyServerShutdown(RoleInfoProto, boolean, TaskStatus)} instead
   +     */
   +    @Deprecated
   +    default void notifyServerShutdown(RoleInfoProto roleInfo, boolean 
allServer) {
   +      notifyServerShutdown(roleInfo, allServer, TaskStatus.COMPLETED);
        }
    
        /**
   -     * Notify the {@link StateMachine} that either the server for this 
division or all the servers have been shut down.
   +     * Notify the {@link StateMachine} server shutdown.
   +     *
         * @param roleInfo roleInfo this server
         * @param allServer whether all raft servers will be shutdown at this 
time
   +     * @param taskStatus {@link TaskStatus#INITIATED} or {@link 
TaskStatus#COMPLETED}
         */
   -    default void notifyServerShutdown(RoleInfoProto roleInfo, boolean 
allServer) {}
   +    default void notifyServerShutdown(RoleInfoProto roleInfo, boolean 
allServer, TaskStatus taskStatus) {}
      }
    
      /**
   ```



-- 
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