You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ratis.apache.org by lj...@apache.org on 2020/04/21 10:22:30 UTC

[incubator-ratis] branch master updated: RATIS-857. Thread unsafe RaftServerMetrics::metricsMap HashMap in multi thread. Contributed by runzhiwang.

This is an automated email from the ASF dual-hosted git repository.

ljain 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 c2e855d  RATIS-857. Thread unsafe RaftServerMetrics::metricsMap HashMap in multi thread. Contributed by runzhiwang.
c2e855d is described below

commit c2e855db82b3027241d387b404bd56b51279cfbf
Author: Lokesh Jain <lj...@apache.org>
AuthorDate: Tue Apr 21 15:45:36 2020 +0530

    RATIS-857. Thread unsafe RaftServerMetrics::metricsMap HashMap in multi thread. Contributed by runzhiwang.
---
 .../src/main/java/org/apache/ratis/server/impl/RaftServerMetrics.java  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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 898b8a4..ebbd346 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
@@ -20,6 +20,7 @@ package org.apache.ratis.server.impl;
 
 import static org.apache.ratis.server.metrics.RaftLogMetrics.FOLLOWER_APPEND_ENTRIES_LATENCY;
 
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.SortedMap;
@@ -68,7 +69,7 @@ public final class RaftServerMetrics extends RatisMetrics {
   private Map<String, Long> followerLastHeartbeatElapsedTimeMap = new HashMap<>();
   private CommitInfoCache commitInfoCache;
 
-  private static Map<String, RaftServerMetrics> metricsMap = new HashMap<>();
+  private static Map<String, RaftServerMetrics> metricsMap = new ConcurrentHashMap<>();
 
   public static RaftServerMetrics getRaftServerMetrics(
       RaftServerImpl raftServer) {