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 a0a812d1 RATIS-1570. Add getLeaderId method to DivisionInfo (#640)
a0a812d1 is described below
commit a0a812d11b72fae8201404b298f318bfcecb6ba1
Author: Potato <[email protected]>
AuthorDate: Mon May 9 21:02:01 2022 +0800
RATIS-1570. Add getLeaderId method to DivisionInfo (#640)
---
.../src/main/java/org/apache/ratis/server/DivisionInfo.java | 7 +++++++
.../src/main/java/org/apache/ratis/server/impl/RaftServerImpl.java | 5 +++++
2 files changed, 12 insertions(+)
diff --git
a/ratis-server-api/src/main/java/org/apache/ratis/server/DivisionInfo.java
b/ratis-server-api/src/main/java/org/apache/ratis/server/DivisionInfo.java
index e59cba57..c07317bd 100644
--- a/ratis-server-api/src/main/java/org/apache/ratis/server/DivisionInfo.java
+++ b/ratis-server-api/src/main/java/org/apache/ratis/server/DivisionInfo.java
@@ -20,6 +20,7 @@ package org.apache.ratis.server;
import org.apache.ratis.proto.RaftProtos.RaftPeerRole;
import org.apache.ratis.proto.RaftProtos.RoleInfoProto;
+import org.apache.ratis.protocol.RaftPeerId;
import org.apache.ratis.util.LifeCycle;
/**
@@ -51,6 +52,12 @@ public interface DivisionInfo {
/** Is this server division currently the leader and ready? */
boolean isLeaderReady();
+ /**
+ * @return the id of the current leader if the leader is known to this
server division;
+ * otherwise, return null.
+ */
+ RaftPeerId getLeaderId();
+
/** @return the life cycle state of this server division. */
LifeCycle.State getLifeCycleState();
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 a7b6ac76..f6c45faa 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
@@ -113,6 +113,11 @@ class RaftServerImpl implements RaftServer.Division,
return isLeader() && getRole().isLeaderReady();
}
+ @Override
+ public RaftPeerId getLeaderId() {
+ return getState().getLeaderId();
+ }
+
@Override
public LifeCycle.State getLifeCycleState() {
return lifeCycle.getCurrentState();