You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by sz...@apache.org on 2020/11/03 09:10:45 UTC
[incubator-ratis] branch master updated: RATIS-1109. Notify
StateMachine on Configuration change (#251)
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/incubator-ratis.git
The following commit(s) were added to refs/heads/master by this push:
new fbdcccc RATIS-1109. Notify StateMachine on Configuration change (#251)
fbdcccc is described below
commit fbdcccc771ac886f93b5ff756e14d2d6c1cb8085
Author: Hanisha Koneru <ha...@apache.org>
AuthorDate: Tue Nov 3 01:10:35 2020 -0800
RATIS-1109. Notify StateMachine on Configuration change (#251)
---
.../apache/ratis/server/impl/RaftServerImpl.java | 4 +++-
.../org/apache/ratis/statemachine/StateMachine.java | 21 ++++++++++++++++++---
2 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
index bee3ca3..5143f31 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java
@@ -1489,8 +1489,10 @@ public class RaftServerImpl implements RaftServerProtocol, RaftServerAsynchronou
}
if (next.hasConfigurationEntry()) {
// the reply should have already been set. only need to record
- // the new conf in the metadata file.
+ // the new conf in the metadata file and notify the StateMachine.
state.writeRaftConfiguration(next);
+ stateMachine.notifyConfigurationChange(next.getTerm(), next.getIndex(),
+ next.getConfigurationEntry());
} else if (next.hasStateMachineLogEntry()) {
// check whether there is a TransactionContext because we are the leader.
TransactionContext trx = role.getLeaderState()
diff --git a/ratis-server/src/main/java/org/apache/ratis/statemachine/StateMachine.java b/ratis-server/src/main/java/org/apache/ratis/statemachine/StateMachine.java
index e4cf833..2be7316 100644
--- a/ratis-server/src/main/java/org/apache/ratis/statemachine/StateMachine.java
+++ b/ratis-server/src/main/java/org/apache/ratis/statemachine/StateMachine.java
@@ -18,6 +18,9 @@
package org.apache.ratis.statemachine;
import org.apache.ratis.proto.RaftProtos;
+import org.apache.ratis.proto.RaftProtos.RaftConfigurationProto;
+import org.apache.ratis.proto.RaftProtos.RoleInfoProto;
+import org.apache.ratis.proto.RaftProtos.LogEntryProto;
import org.apache.ratis.protocol.Message;
import org.apache.ratis.protocol.RaftClientRequest;
import org.apache.ratis.protocol.RaftGroupId;
@@ -27,8 +30,6 @@ import org.apache.ratis.server.RaftServer;
import org.apache.ratis.server.impl.ServerProtoUtils;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.ratis.server.storage.RaftStorage;
-import org.apache.ratis.proto.RaftProtos.RoleInfoProto;
-import org.apache.ratis.proto.RaftProtos.LogEntryProto;
import org.apache.ratis.thirdparty.com.google.protobuf.ByteString;
import org.apache.ratis.util.LifeCycle;
import org.slf4j.Logger;
@@ -264,7 +265,7 @@ public interface StateMachine extends Closeable {
/**
* Called to notify state machine about indexes which are processed
- * internally by Raft Server, this currently happens when conf entries are
+ * internally by Raft Server, this currently happens when metadata entries are
* processed in raft Server. This keep state machine to keep a track of index
* updates.
* @param term term of the current log entry
@@ -275,6 +276,20 @@ public interface StateMachine extends Closeable {
}
/**
+ * Called to notify state machine about configuration changes to the Raft
+ * Server. This currently happens when conf entries are processed in raft
+ * server. This allows state machine to keep track of configuration changes
+ * on the raft server and also track the index updates corresponding to
+ * configuration changes.
+ * @param term term of the current log entry
+ * @param index index which is being updated
+ * @param newRaftConfiguration new configuration
+ */
+ default void notifyConfigurationChange(long term, long index,
+ RaftConfigurationProto newRaftConfiguration) {
+ }
+
+ /**
* Apply a committed log entry to the state machine. This method can be called concurrently with
* the other calls, and there is no guarantee that the calls will be ordered according to the
* log commit order.