jerqi commented on code in PR #2657:
URL: https://github.com/apache/uniffle/pull/2657#discussion_r2481300823


##########
client-spark/common/src/main/java/org/apache/uniffle/shuffle/ShuffleReadTaskStats.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.uniffle.shuffle;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ShuffleReadTaskStats {
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(ShuffleReadTaskStats.class);
+
+  // partition_id -> upstream_map_id -> records_read
+  private Map<Integer, Map<Long, Long>> partitionRecordsReadPerMap = new 
HashMap<>();
+  // partition_id -> upstream_map_id -> blocks_read
+  private Map<Integer, Map<Long, Long>> partitionBlocksReadPerMap = new 
HashMap<>();
+
+  public void incPartitionRecord(int partitionId, long taskAttemptId) {
+    Map<Long, Long> records =
+        partitionRecordsReadPerMap.computeIfAbsent(partitionId, k -> new 
HashMap<>());
+    records.compute(taskAttemptId, (k, v) -> v == null ? 1 : v + 1);
+  }
+
+  public void incPartitionBlock(int partitionId, long taskAttemptId) {
+    Map<Long, Long> records =
+        partitionBlocksReadPerMap.computeIfAbsent(partitionId, k -> new 
HashMap<>());
+    records.compute(taskAttemptId, (k, v) -> v == null ? 1 : v + 1);
+  }
+
+  public Map<Long, Long> getPartitionRecords(int partitionId) {
+    return partitionRecordsReadPerMap.get(partitionId);
+  }
+
+  public Map<Long, Long> getPartitionBlocks(int partitionId) {
+    return partitionBlocksReadPerMap.get(partitionId);
+  }
+
+  public boolean diff(
+      Map<Long, ShuffleWriteTaskStats> writeStats, int startPartition, int 
endPartition) {
+    StringBuilder infoBuilder = new StringBuilder();
+    for (int idx = startPartition; idx < endPartition; idx++) {
+      for (Map.Entry<Long, Long> recordEntry : 
partitionRecordsReadPerMap.get(idx).entrySet()) {
+        long taskAttemptId = recordEntry.getKey();
+        long recordsRead = recordEntry.getValue();
+        long blocksRead =
+            Optional.ofNullable(partitionBlocksReadPerMap.get(idx))
+                .map(m -> m.getOrDefault(taskAttemptId, 0L))
+                .orElse(0L);
+
+        ShuffleWriteTaskStats stats = writeStats.get(taskAttemptId);
+        if (stats == null) {
+          // ignore but this should not happen

Review Comment:
   You should log here.



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


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

Reply via email to