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 0731376  RATIS-747. RaftServerMetrics.getRaftServerMetrics throws 
IllegalStateException.  Contributed by Aravindan Vijayan
0731376 is described below

commit 073137602c68559fc6395629c10298f5d055f068
Author: Tsz Wo Nicholas Sze <[email protected]>
AuthorDate: Fri Nov 8 13:49:47 2019 -0800

    RATIS-747. RaftServerMetrics.getRaftServerMetrics throws 
IllegalStateException.  Contributed by Aravindan Vijayan
---
 .../java/org/apache/ratis/server/impl/FollowerState.java     |  3 ---
 .../java/org/apache/ratis/server/impl/RaftServerMetrics.java | 12 ++++++------
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerState.java 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerState.java
index fea78b7..d82af65 100644
--- a/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerState.java
+++ b/ratis-server/src/main/java/org/apache/ratis/server/impl/FollowerState.java
@@ -57,13 +57,10 @@ class FollowerState extends Daemon {
   private volatile Timestamp lastRpcTime = Timestamp.currentTime();
   private volatile boolean isRunning = true;
   private final AtomicInteger outstandingOp = new AtomicInteger();
-  private final RaftServerMetrics raftServerMetrics;
 
   FollowerState(RaftServerImpl server) {
     this.name = server.getMemberId() + "-" + getClass().getSimpleName();
     this.server = server;
-    raftServerMetrics = server.getRaftServerMetrics();
-    raftServerMetrics.addPeerCommitIndexGauge(server.getPeer());
   }
 
   void updateLastRpcTime(UpdateType type) {
diff --git 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerMetrics.java
 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerMetrics.java
index 8834263..22020ec 100644
--- 
a/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerMetrics.java
+++ 
b/ratis-server/src/main/java/org/apache/ratis/server/impl/RaftServerMetrics.java
@@ -41,6 +41,7 @@ import org.apache.ratis.proto.RaftProtos;
 import org.apache.ratis.proto.RaftProtos.RaftClientRequestProto.TypeCase;
 import org.apache.ratis.protocol.RaftClientRequest;
 import org.apache.ratis.protocol.RaftPeer;
+import org.apache.ratis.protocol.RaftPeerId;
 import org.apache.ratis.server.metrics.RatisMetrics;
 import 
org.apache.ratis.thirdparty.com.google.common.annotations.VisibleForTesting;
 import org.apache.ratis.util.Preconditions;
@@ -66,7 +67,7 @@ public final class RaftServerMetrics {
   private RaftServerMetrics(RaftServerImpl server) {
     registry = 
RatisMetrics.getMetricRegistryForRaftServer(server.getMemberId().toString());
     commitInfoCache = server.getCommitInfoCache();
-    addPeerCommitIndexGauge(server.getPeer());
+    addPeerCommitIndexGauge(server.getId());
   }
 
   /**
@@ -83,18 +84,17 @@ public final class RaftServerMetrics {
     registry.gauge(followerHbMetricKey,
         () -> () -> followerLastHeartbeatElapsedTimeMap.get(followerName));
 
-    addPeerCommitIndexGauge(peer);
+    addPeerCommitIndexGauge(peer.getId());
   }
 
   /**
    * Register a commit index tracker for the peer in cluster.
-   * @param peer
    */
-  public void addPeerCommitIndexGauge(RaftPeer peer) {
+  public void addPeerCommitIndexGauge(RaftPeerId peerId) {
     String followerCommitIndexKey = String.format(
-        LEADER_METRIC_PEER_COMMIT_INDEX, peer.getId().toString());
+        LEADER_METRIC_PEER_COMMIT_INDEX, peerId);
     registry.gauge(followerCommitIndexKey, () -> () -> {
-      RaftProtos.CommitInfoProto commitInfoProto = 
commitInfoCache.get(peer.getId());
+      RaftProtos.CommitInfoProto commitInfoProto = commitInfoCache.get(peerId);
       if (commitInfoProto != null) {
         return commitInfoProto.getCommitIndex();
       }

Reply via email to