Copilot commented on code in PR #2698:
URL: https://github.com/apache/uniffle/pull/2698#discussion_r2612680995
##########
client-spark/spark3/src/main/java/org/apache/spark/shuffle/writer/RssShuffleWriter.java:
##########
@@ -1127,9 +1098,43 @@ protected void setTaskId(String taskId) {
@VisibleForTesting
protected Map<ShuffleServerInfo, Map<Integer, Set<Long>>>
getServerToPartitionToBlockIds() {
+ Map<ShuffleServerInfo, Map<Integer, Set<Long>>>
serverToPartitionToBlockIds = new HashMap<>();
+ Map<ShuffleServerInfo, Map<Integer, BlockStats>> allBlockStats =
+ shuffleTaskStats.getAllBlockStats();
+ for (Map.Entry<ShuffleServerInfo, Map<Integer, BlockStats>> entry :
allBlockStats.entrySet()) {
+ ShuffleServerInfo server = entry.getKey();
+ for (Map.Entry<Integer, BlockStats> childEntry :
entry.getValue().entrySet()) {
+ int partitionId = childEntry.getKey();
+ BlockStats stats = childEntry.getValue();
+ serverToPartitionToBlockIds
+ .computeIfAbsent(server, k -> new HashMap<>())
+ .computeIfAbsent(partitionId, z -> new HashSet<>())
+ .addAll(stats.getBlockIds());
+ }
+ }
return serverToPartitionToBlockIds;
}
+ @VisibleForTesting
+ protected Map<ShuffleServerInfo, Map<Integer, Long>>
getServerToPartitionToRecordNumbers() {
+ Map<ShuffleServerInfo, Map<Integer, Long>>
serverToPartitionToRecordNumbers = new HashMap<>();
+ Map<ShuffleServerInfo, Map<Integer, BlockStats>> allBlockStats =
+ shuffleTaskStats.getAllBlockStats();
+ for (Map.Entry<ShuffleServerInfo, Map<Integer, BlockStats>> entry :
allBlockStats.entrySet()) {
+ ShuffleServerInfo server = entry.getKey();
+ for (Map.Entry<Integer, BlockStats> childEntry :
entry.getValue().entrySet()) {
+ int partitionId = childEntry.getKey();
+ BlockStats stats = childEntry.getValue();
+ serverToPartitionToRecordNumbers
+ .computeIfAbsent(server, k -> new HashMap<>())
+ .compute(
+ partitionId,
+ (k, v) -> (v == null) ? stats.getRecordNumber() :
stats.getRecordNumber() + v);
Review Comment:
The ternary operator pattern for null-checking in `compute` can be
simplified to use `merge` method. Consider replacing with `.merge(partitionId,
stats.getRecordNumber(), Long::sum)` for cleaner code.
```suggestion
.merge(partitionId, stats.getRecordNumber(), Long::sum);
```
##########
client-spark/common/src/main/java/org/apache/uniffle/shuffle/ShuffleWriteTaskStats.java:
##########
@@ -199,5 +225,53 @@ public void check(long[] partitionLens) {
+ length);
}
}
+
+ // 2. blockIds check
+ if (blockNumberCheckEnabled) {
+ long expected = 0L;
+ for (long partitionBlockNumber : partitionBlocks) {
+ expected += partitionBlockNumber;
+ }
+ long actual =
+ serverToPartitionToBlockStats.entrySet().stream()
+ .flatMap(x -> x.getValue().entrySet().stream())
+ .map(x -> x.getValue().getBlockIds().size())
+ .reduce((x, y) -> x + y)
Review Comment:
Replace the lambda expression with method reference `Integer::sum` for
better readability and consistency with Java best practices.
```suggestion
.reduce(Integer::sum)
```
##########
client-spark/common/src/main/java/org/apache/uniffle/shuffle/BlockStats.java:
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.HashSet;
+import java.util.Set;
+
+/** Multi blocks stats */
+public class BlockStats {
+ private long recordNumber;
+ private Set<Long> blockIds;
+
+ public BlockStats() {
+ this.recordNumber = 0;
+ this.blockIds = new HashSet<Long>();
Review Comment:
Use diamond operator for the generic type instead of explicit type
parameter. Change to `new HashSet<>()` for consistency with modern Java
conventions and the pattern used in line 35.
```suggestion
this.blockIds = new HashSet<>();
```
--
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]