szetszwo commented on code in PR #1587:
URL: https://github.com/apache/ratis/pull/1587#discussion_r4008185866


##########
ratis-server/src/main/java/org/apache/ratis/server/metrics/LogAppenderMetrics.java:
##########
@@ -47,8 +47,16 @@ private static RatisMetricRegistry createRegistry(String 
serverId) {
 
   public void addFollowerGauges(RaftPeerId id, LongSupplier getNextIndex, 
LongSupplier getMatchIndex,
       Supplier<Timestamp> getLastRpcTime) {
+    // The registry does not replace an existing gauge; remove it so that the 
new suppliers take effect.
+    removeFollowerGauges(id);
     getRegistry().gauge(String.format(FOLLOWER_NEXT_INDEX, id), () -> 
getNextIndex::getAsLong);
     getRegistry().gauge(String.format(FOLLOWER_MATCH_INDEX, id), () -> 
getMatchIndex::getAsLong);
     getRegistry().gauge(String.format(FOLLOWER_RPC_RESP_TIME, id), () -> () -> 
getLastRpcTime.get().elapsedTimeMs());
   }
+
+  public void removeFollowerGauges(RaftPeerId id) {
+    getRegistry().remove(String.format(FOLLOWER_NEXT_INDEX, id));
+    getRegistry().remove(String.format(FOLLOWER_MATCH_INDEX, id));
+    getRegistry().remove(String.format(FOLLOWER_RPC_RESP_TIME, id));
+  }

Review Comment:
   Let's add a private replaceGauge method:
   ```java
     public void addFollowerGauges(RaftPeerId id, LongSupplier getNextIndex, 
LongSupplier getMatchIndex,
         Supplier<Timestamp> getLastRpcTime) {
       replaceGauge(String.format(FOLLOWER_NEXT_INDEX, id), getNextIndex);
       replaceGauge(String.format(FOLLOWER_MATCH_INDEX, id), getMatchIndex);
       replaceGauge(String.format(FOLLOWER_RPC_RESP_TIME, id), () -> 
getLastRpcTime.get().elapsedTimeMs());
     }
   
     private void replaceGauge(String name, LongSupplier supplier) {
       getRegistry().remove(name);
       getRegistry().gauge(name, () -> supplier::getAsLong);
     }
   ```



##########
ratis-server/src/main/java/org/apache/ratis/server/impl/LeaderStateImpl.java:
##########
@@ -698,6 +698,7 @@ private void stopAndRemoveSenders(Predicate<LogAppender> 
predicate) {
   private void stopAndRemoveSenders(Collection<LogAppender> toStop) {
     toStop.forEach(LogAppender::stopAsync);
     senders.removeAll(toStop);
+    toStop.forEach(s -> 
logAppenderMetrics.removeFollowerGauges(s.getFollowerId()));

Review Comment:
   After the change in LogAppenderMetrics, this is not needed.  Let's don't add 
this line?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to