storm-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [2/6] storm git commit: STORM-3167: Copy map before returning in FakeMetricConsumer, since returning a view of the map is unsafe due to concurrent modification
Date Fri, 03 Aug 2018 15:41:53 GMT
STORM-3167: Copy map before returning in FakeMetricConsumer, since returning a view of the
map is unsafe due to concurrent modification


Project: http://git-wip-us.apache.org/repos/asf/storm/repo
Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/8fb87ed7
Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/8fb87ed7
Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/8fb87ed7

Branch: refs/heads/master
Commit: 8fb87ed7211cfde104ca1f5a2a3689190414ae2c
Parents: 146beff
Author: Stig Rohde Døssing <srdo@apache.org>
Authored: Wed Aug 1 16:32:46 2018 +0200
Committer: Stig Rohde Døssing <srdo@apache.org>
Committed: Wed Aug 1 16:33:04 2018 +0200

----------------------------------------------------------------------
 .../apache/storm/metric/FakeMetricConsumer.java | 22 ++++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/storm/blob/8fb87ed7/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java
----------------------------------------------------------------------
diff --git a/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java b/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java
index 23b1c8f..3cf53e8 100644
--- a/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java
+++ b/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java
@@ -25,36 +25,36 @@ import org.apache.storm.task.TopologyContext;
 
 public class FakeMetricConsumer implements IMetricsConsumer {
 
-    public static final Table<String, String, Multimap<Integer, Object>> buffer
= HashBasedTable.create();
+    public static final Table<String, String, Multimap<Integer, Object>> BUFFER
= HashBasedTable.create();
 
     public static Map<Integer, Collection<Object>> getTaskIdToBuckets(String
componentName, String metricName) {
-        synchronized (buffer) {
-            Multimap<Integer, Object> taskIdToBuckets = buffer.get(componentName, metricName);
-            return (null != taskIdToBuckets) ? taskIdToBuckets.asMap() : null;
+        synchronized (BUFFER) {
+            Multimap<Integer, Object> taskIdToBuckets = BUFFER.get(componentName, metricName);
+            return (null != taskIdToBuckets) ? new HashMap<>(taskIdToBuckets.asMap())
: null;
         }
     }
 
     @Override
     public void prepare(Map<String, Object> topoConf, Object registrationArgument,
TopologyContext context, IErrorReporter errorReporter) {
-        synchronized (buffer) {
-            buffer.clear();
+        synchronized (BUFFER) {
+            BUFFER.clear();
         }
     }
 
     @Override
     public void handleDataPoints(TaskInfo taskInfo, Collection<DataPoint> dataPoints)
{
-        synchronized (buffer) {
+        synchronized (BUFFER) {
             for (DataPoint dp : dataPoints) {
                 for (Map.Entry<String, Object> entry : expandComplexDataPoint(dp).entrySet())
{
                     String metricName = entry.getKey();
-                    Multimap<Integer, Object> taskIdToBucket = buffer.get(taskInfo.srcComponentId,
metricName);
+                    Multimap<Integer, Object> taskIdToBucket = BUFFER.get(taskInfo.srcComponentId,
metricName);
                     if (null == taskIdToBucket) {
                         taskIdToBucket = ArrayListMultimap.create();
                         taskIdToBucket.put(taskInfo.srcTaskId, entry.getValue());
                     } else {
                         taskIdToBucket.get(taskInfo.srcTaskId).add(entry.getValue());
                     }
-                    buffer.put(taskInfo.srcComponentId, metricName, taskIdToBucket);
+                    BUFFER.put(taskInfo.srcComponentId, metricName, taskIdToBucket);
                 }
             }
         }
@@ -62,8 +62,8 @@ public class FakeMetricConsumer implements IMetricsConsumer {
 
     @Override
     public void cleanup() {
-        synchronized (buffer) {
-            buffer.clear();
+        synchronized (BUFFER) {
+            BUFFER.clear();
         }
     }
 


Mime
View raw message