This is an automated email from the ASF dual-hosted git repository.
szetszwo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ratis.git
The following commit(s) were added to refs/heads/master by this push:
new c81902a09 RATIS-2066. RaftServerProxy supports close callback (#1072)
c81902a09 is described below
commit c81902a094344d953f2fc5f5d7ed08dc7c171cdf
Author: Sammi Chen <[email protected]>
AuthorDate: Wed May 15 22:33:27 2024 +0800
RATIS-2066. RaftServerProxy supports close callback (#1072)
---
.../java/org/apache/ratis/statemachine/StateMachine.java | 15 +++++++++++++--
.../java/org/apache/ratis/server/impl/LeaderElection.java | 2 +-
.../org/apache/ratis/server/impl/RaftServerProxy.java | 1 +
3 files changed, 15 insertions(+), 3 deletions(-)
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 b68c724ab..3960ab828 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
@@ -263,9 +263,20 @@ public interface StateMachine extends Closeable {
default void notifySnapshotInstalled(InstallSnapshotResult result, long
snapshotIndex, RaftPeer peer) {}
/**
- * Notify the {@link StateMachine} that a raft server has step down.
+ * Notify the {@link StateMachine} that the server for this division has
been shut down.
+ * @Deprecated please use/override {@link
#notifyServerShutdown(RoleInfoProto, boolean)} instead
*/
- default void notifyServerShutdown(RoleInfoProto roleInfo) {}
+ @Deprecated
+ default void notifyServerShutdown(RoleInfoProto roleInfo) {
+ notifyServerShutdown(roleInfo, false);
+ }
+
+ /**
+ * Notify the {@link StateMachine} that either the server for this
division or all the servers have been shut down.
+ * @param roleInfo roleInfo this server
+ * @param allServer whether all raft servers will be shutdown at this time
+ */
+ default void notifyServerShutdown(RoleInfoProto roleInfo, boolean
allServer) {}
}
/**
diff --git
a/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java
b/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java
index b31fbaba6..da9c51348 100644
---
a/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java
+++
b/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderElection.java
@@ -334,7 +334,7 @@ class LeaderElection implements Runnable {
case NOT_IN_CONF:
case SHUTDOWN:
server.close();
-
server.getStateMachine().event().notifyServerShutdown(server.getRoleInfoProto());
+
server.getStateMachine().event().notifyServerShutdown(server.getRoleInfoProto(),
false);
return false;
case TIMEOUT:
return false; // should retry
diff --git
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java
index 589c7eeb1..e5e74e991 100644
---
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java
+++
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerProxy.java
@@ -138,6 +138,7 @@ class RaftServerProxy implements RaftServer {
} catch (Throwable t) {
LOG.warn("{}: Failed to close the division for {}", getId(), groupId,
t);
}
+
impl.getStateMachine().event().notifyServerShutdown(impl.getRoleInfoProto(),
true);
}
synchronized List<RaftGroupId> getGroupIds() {