This is an automated email from the ASF dual-hosted git repository.
shashikant 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 f36acab RATIS-717. NPE thrown on the follower while instantiating
RaftLeaderMetrics. Contributed by Aravindan Vijayan.
f36acab is described below
commit f36acabc58d6ed0146a9998150b5d7a038bdda7d
Author: Shashikant Banerjee <[email protected]>
AuthorDate: Fri Oct 18 15:42:47 2019 +0530
RATIS-717. NPE thrown on the follower while instantiating
RaftLeaderMetrics. Contributed by Aravindan Vijayan.
---
.../java/org/apache/ratis/server/impl/RaftLeaderMetrics.java | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftLeaderMetrics.java
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftLeaderMetrics.java
index 44f6b2f..245aa39 100644
---
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftLeaderMetrics.java
+++
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftLeaderMetrics.java
@@ -26,7 +26,9 @@ import java.util.Map;
import java.util.SortedMap;
import com.codahale.metrics.Gauge;
+
import org.apache.ratis.metrics.RatisMetricRegistry;
+import org.apache.ratis.proto.RaftProtos;
import org.apache.ratis.protocol.RaftPeer;
import org.apache.ratis.server.metrics.RatisMetrics;
import
org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting;
@@ -82,8 +84,13 @@ public final class RaftLeaderMetrics {
public void addPeerCommitIndexGauge(RaftPeer peer) {
String followerCommitIndexKey = String.format(
LEADER_METRIC_PEER_COMMIT_INDEX, peer.getId().toString());
- registry.gauge(followerCommitIndexKey,
- () -> () -> commitInfoCache.get(peer.getId()).getCommitIndex());
+ registry.gauge(followerCommitIndexKey, () -> () -> {
+ RaftProtos.CommitInfoProto commitInfoProto =
commitInfoCache.get(peer.getId());
+ if (commitInfoProto != null) {
+ return commitInfoProto.getCommitIndex();
+ }
+ return 0L;
+ });
}
/**