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


##########
ratis-server-api/src/main/java/org/apache/ratis/statemachine/StateMachine.java:
##########
@@ -229,20 +234,39 @@ default void notifyLogFailed(Throwable cause, 
LogEntryProto failedEntry) {}
     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, 
EventStatus.COMPLETED).
+     *
+     * @deprecated please use/override {@link 
#notifyServerShutdown(RoleInfoProto, boolean, EventStatus)} instead
      */
     @Deprecated
     default void notifyServerShutdown(RoleInfoProto roleInfo) {
-      notifyServerShutdown(roleInfo, false);
+      notifyServerShutdown(roleInfo, false, EventStatus.COMPLETED);
+    }
+
+    /**
+     * The same as notifyServerShutdown(roleInfo, allServers, 
EventStatus.COMPLETED).
+     *
+     * @deprecated please use/override {@link 
#notifyServerShutdown(RoleInfoProto, boolean, EventStatus)} instead
+     */
+    @Deprecated
+    default void notifyServerShutdown(RoleInfoProto roleInfo, boolean 
allServers) {
+      notifyServerShutdown(roleInfo, allServers, EventStatus.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.
+     * <p>
+     * {@link EventStatus#INITIATED} is notified before the shutdown has 
closed any resources,
+     * in particular, before waiting for the committed log entries to be 
applied to this {@link StateMachine},
+     * which is unbounded in time.  An implementation must return promptly for 
{@link EventStatus#INITIATED}.
+     * <p>
+     * {@link EventStatus#COMPLETED} is notified after the shutdown has 
completed.
+     *
      * @param roleInfo roleInfo this server
-     * @param allServer whether all raft servers will be shutdown at this time
+     * @param allServers whether all raft servers will be shutdown at this time
+     * @param eventStatus {@link EventStatus#INITIATED} or {@link 
EventStatus#COMPLETED}
      */
-    default void notifyServerShutdown(RoleInfoProto roleInfo, boolean 
allServer) {}
+    default void notifyServerShutdown(RoleInfoProto roleInfo, boolean 
allServers, EventStatus eventStatus) {}

Review Comment:
   If the user does not implement these functions but happen to call 
`notifyServerShutdown(roleInfo, allServers);`, it will turn into an infinite 
loop rather than a harmless no-op.
   
   One approach is we actually throw exception in the default implementation 
but that would be a behavior change for the existing API.
   
   As of now I feel like the better way is we do not migrate existing 
`notifyServerShutdown(RoleInfoProto roleInfo, boolean allServer)` calls to the 
EventStatus based calls, which then will preserve existing behavior:
   1. so the complete status report still uses 
`notifyServerShutdown(RoleInfoProto roleInfo, boolean allServer)`
   2. only the initialized status report uses `default void 
notifyServerShutdown(RoleInfoProto roleInfo, boolean allServers, EventStatus 
eventStatus)`.
   
   I will adopt this way for now.



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