This is an automated email from the ASF dual-hosted git repository.
tanxinyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new fbb74cd83e Add comment on getLeader (#6371)
fbb74cd83e is described below
commit fbb74cd83e9dce402d876d34be9e01de6c9ad56d
Author: William Song <[email protected]>
AuthorDate: Wed Jun 22 00:11:19 2022 +0800
Add comment on getLeader (#6371)
* add comment on getLeader
* add comment on getLeader
---
.../java/org/apache/iotdb/consensus/ratis/RatisConsensus.java | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git
a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
index 33a523eb06..82418e7740 100644
---
a/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
+++
b/consensus/src/main/java/org/apache/iotdb/consensus/ratis/RatisConsensus.java
@@ -515,6 +515,12 @@ class RatisConsensus implements IConsensus {
return divisionInfo.isLeader();
}
+ /**
+ * returns the known leader to the given group. NOTICE: if the local peer
isn't a member of given
+ * group, getLeader will return null.
+ *
+ * @return null if local peer isn't in group, otherwise group leader.
+ */
@Override
public Peer getLeader(ConsensusGroupId groupId) {
RaftGroupId raftGroupId = Utils.fromConsensusGroupIdToRaftGroupId(groupId);
@@ -526,6 +532,9 @@ class RatisConsensus implements IConsensus {
logger.warn("fetch division info for group " + groupId + " failed due
to: ", e);
return null;
}
+ if (leaderId == null) {
+ return null;
+ }
TEndPoint leaderEndpoint = Utils.formRaftPeerIdToTEndPoint(leaderId);
return new Peer(groupId, leaderEndpoint);
}