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 5b6edb9 RATIS-693. Combine notifyLeader and notifyLeaderChanged calls
on StateMachine. Contributed by Siddharth Wagle
5b6edb9 is described below
commit 5b6edb9adbdd2c62dad3a9992a5ac96dfe110d68
Author: Tsz Wo Nicholas Sze <[email protected]>
AuthorDate: Thu Oct 3 12:01:33 2019 +0800
RATIS-693. Combine notifyLeader and notifyLeaderChanged calls on
StateMachine. Contributed by Siddharth Wagle
---
.../main/java/org/apache/ratis/server/impl/LeaderState.java | 1 -
.../main/java/org/apache/ratis/server/impl/ServerState.java | 2 +-
.../main/java/org/apache/ratis/statemachine/StateMachine.java | 11 +++--------
.../apache/ratis/statemachine/SimpleStateMachine4Testing.java | 10 +++++++---
4 files changed, 11 insertions(+), 13 deletions(-)
diff --git
a/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderState.java
b/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderState.java
index 478e3ed..17e4664 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderState.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderState.java
@@ -238,7 +238,6 @@ public class LeaderState {
CodeInjectionForTesting.execute(APPEND_PLACEHOLDER,
server.getId().toString(), null);
raftLog.append(placeHolder);
- server.getStateMachine().notifyLeader(server.getGroup().getGroupId(),
raftLog.getLastCommittedIndex());
processor.start();
senders.forEach(LogAppender::startAppender);
return placeHolder;
diff --git
a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
index 21f3a57..b91f029 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/ServerState.java
@@ -250,7 +250,7 @@ public class ServerState implements Closeable {
Timestamp previous = lastNoLeaderTime;
lastNoLeaderTime = null;
suffix = ", leader elected after " + previous.elapsedTimeMs() + "ms";
-
server.getStateMachine().notifyLeaderChanged(server.getGroup().getGroupId(),
newLeaderId);
+ server.getStateMachine().notifyLeaderChanged(getMemberId(),
newLeaderId);
}
LOG.info("{}: change Leader from {} to {} at term {} for {}{}",
getMemberId(), leaderId, newLeaderId, getCurrentTerm(), op, suffix);
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 a8cfc1d..ee78014 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
@@ -20,6 +20,7 @@ package org.apache.ratis.statemachine;
import org.apache.ratis.protocol.Message;
import org.apache.ratis.protocol.RaftClientRequest;
import org.apache.ratis.protocol.RaftGroupId;
+import org.apache.ratis.protocol.RaftGroupMemberId;
import org.apache.ratis.protocol.RaftPeerId;
import org.apache.ratis.server.RaftServer;
import org.apache.ratis.server.RaftServerConfigKeys;
@@ -279,15 +280,9 @@ public interface StateMachine extends Closeable {
}
/**
- * Notify the state machine that the raft peer is a leader now.
+ * Notify the state machine that a RaftPeer has been elected as leader.
*/
- default void notifyLeader(RaftGroupId groupId, long lastCommittedIndex){
- }
-
- /**
- * Notify the follower state machine that a RaftPeer has been elected as
leader.
- */
- default void notifyLeaderChanged(RaftGroupId groupId, RaftPeerId raftPeerId)
{
+ default void notifyLeaderChanged(RaftGroupMemberId groupMemberId, RaftPeerId
raftPeerId) {
}
/**
diff --git
a/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
b/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
index d0eeb21..9d2a3da 100644
---
a/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
+++
b/ratis-server/src/test/java/org/apache/ratis/statemachine/SimpleStateMachine4Testing.java
@@ -26,6 +26,8 @@ import org.apache.ratis.protocol.Message;
import org.apache.ratis.protocol.RaftClientRequest;
import org.apache.ratis.protocol.RaftGroup;
import org.apache.ratis.protocol.RaftGroupId;
+import org.apache.ratis.protocol.RaftGroupMemberId;
+import org.apache.ratis.protocol.RaftPeerId;
import org.apache.ratis.protocol.StateMachineException;
import org.apache.ratis.server.RaftServer;
import org.apache.ratis.server.RaftServerConfigKeys;
@@ -418,13 +420,15 @@ public class SimpleStateMachine4Testing extends
BaseStateMachine {
leaderElectionTimeoutInfo = roleInfoProto;
}
- @Override public void notifyNotLeader(Collection<TransactionContext>
pendingEntries)
+ @Override
+ public void notifyNotLeader(Collection<TransactionContext> pendingEntries)
throws IOException {
}
- @Override public void notifyLeader(RaftGroupId groupId, long
lastCommittedIndex) {
- notifiedAsLeader = true;
+ @Override
+ public void notifyLeaderChanged(RaftGroupMemberId groupMemberId, RaftPeerId
raftPeerId) {
+
}
public boolean isNotifiedAsLeader() {