clintropolis commented on a change in pull request #10359:
URL: https://github.com/apache/druid/pull/10359#discussion_r485371746



##########
File path: 
indexing-service/src/main/java/org/apache/druid/indexing/worker/shuffle/ShuffleMetrics.java
##########
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.indexing.worker.shuffle;
+
+import com.google.common.annotations.VisibleForTesting;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class ShuffleMetrics
+{
+  private final AtomicReference<ConcurrentHashMap<String, 
PerDatasourceShuffleMetrics>> datasourceMetrics =
+      new AtomicReference<>();
+
+  public ShuffleMetrics()
+  {
+    datasourceMetrics.set(new ConcurrentHashMap<>());
+  }
+
+  public void shuffleRequested(String supervisorTaskId, long fileLength)
+  {
+    datasourceMetrics
+        .get()
+        .computeIfAbsent(supervisorTaskId, k -> new 
PerDatasourceShuffleMetrics()).accumulate(fileLength);

Review comment:
       I think this needs to use something like `AtomicReference.getAndUpdate` 
so that it isn't racy with the monitor/emitter? Though I'm not sure 
`getAndUpdate` or the similar methods are actually appropriate since they are 
supposed to be side-effect free, so I'm not really sure how exactly to resolve 
this.
   
   Like, the potentially problematic scenario I'm thinking of is where 
`shuffleRequested` is called "before" `snapshotAndReset`. It seems like once 
`AtomicReference.get` has completed, `snapshotAndReset` can proceed, so now the 
shuffle monitor has the same concurrent map we are still actively updating, and 
it is preparing to build the metrics to emit. It seems super unlikely that it 
would be a problem, but unless I'm missing something it does seem possible.




----------------------------------------------------------------
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.

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



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to