Repository navigation
Conversation
amaliujia
force-pushed
the
robus_server_and_ratis
branch
from
October 17, 2026 14:10
0f1bd8b to
b55f83b
Compare
szetszwo
reviewed
Oct 17, 2026
Comment on lines
245
to
+272
| 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) {} |
Contributor
There was a problem hiding this comment.
@amaliujia , thanks for working on this!
Please deprecate and override the existing notifyServerShutdown method:
(revision: renamed the new enum to EventStatus)
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..967debb04 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 EventStatus {
+ 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, 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, allServer, EventStatus.COMPLETED).
+ *
+ * @deprecated please use/override {@link #notifyServerShutdown(RoleInfoProto, boolean, EventStatus)} instead
+ */
+ @Deprecated
+ default void notifyServerShutdown(RoleInfoProto roleInfo, boolean allServer) {
+ notifyServerShutdown(roleInfo, allServer, 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.
+ *
* @param roleInfo roleInfo this server
* @param allServer 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 allServer, EventStatus eventStatus) {}
}
/**This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
Notify the StateMachine when a server shutdown starts
What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/RATIS-2721
Please replace this section with the link to the Apache JIRA)
How was this patch tested?
Unit test