Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions common/src/main/java/org/apache/uniffle/common/util/RssUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -407,44 +407,25 @@ public static void checkProcessedBlockIds(
Roaring64NavigableMap exceptedBlockIds, Set<Long> processedBlockIds) {
Iterator<Long> it = exceptedBlockIds.iterator();
int expectedCount = 0;
int actualCount = 0;
int matchedCount = 0;
while (it.hasNext()) {
expectedCount++;
if (processedBlockIds.contains(it.next())) {
actualCount++;
if (processedBlockIds.remove(it.next())) {

Copilot AI Dec 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method now mutates the input parameter processedBlockIds by calling remove(). This is a breaking behavioral change that could affect callers who reuse this Set. Consider either documenting this side effect clearly, cloning the Set before modification, or renaming the parameter to indicate it will be modified (e.g., mutableProcessedBlockIds).

Copilot uses AI. Check for mistakes.
matchedCount++;
}
}
if (expectedCount != actualCount) {
if (expectedCount != matchedCount || !processedBlockIds.isEmpty()) {
throw new RssException(
"Blocks read inconsistent: expected "
+ expectedCount
+ " blocks, actual "
+ actualCount
+ " blocks, matched "
+ matchedCount
+ " blocks, illegal "
+ processedBlockIds.size()
+ " blocks");
}
}

public static void checkProcessedBlockIds(
Roaring64NavigableMap blockIdBitmap, Roaring64NavigableMap processedBlockIds) {
// processedBlockIds can be a superset of blockIdBitmap,
// here we check that processedBlockIds has all bits of blockIdBitmap set
// first a quick check:
// we only need to do the bitwise AND when blockIdBitmap is not equal to processedBlockIds
if (!blockIdBitmap.equals(processedBlockIds)) {
Roaring64NavigableMap cloneBitmap;
cloneBitmap = RssUtils.cloneBitMap(blockIdBitmap);
cloneBitmap.and(processedBlockIds);
if (!blockIdBitmap.equals(cloneBitmap)) {
throw new RssException(
"Blocks read inconsistent: expected "
+ blockIdBitmap.getLongCardinality()
+ " blocks, actual "
+ cloneBitmap.getLongCardinality()
+ " blocks");
}
}
}

public static Roaring64NavigableMap generateTaskIdBitMap(
Roaring64NavigableMap blockIdBitmap, IdHelper idHelper) {
Iterator<Long> iterator = blockIdBitmap.iterator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.net.Socket;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -59,6 +60,32 @@

public class RssUtilsTest {

@Test
public void testCheckProcessedBlockIds() throws Exception {
Roaring64NavigableMap exceptedBlockIds = new Roaring64NavigableMap();

Copilot AI Dec 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'excepted' to 'expected'.

Copilot uses AI. Check for mistakes.
exceptedBlockIds.add(1);
exceptedBlockIds.add(2);

// case1: illegal should throw exception
Set<Long> processedBlockIds = new HashSet<>();
processedBlockIds.add(1L);
processedBlockIds.add(2L);
processedBlockIds.add(3L);

try {
RssUtils.checkProcessedBlockIds(exceptedBlockIds, processedBlockIds);
fail();
Comment on lines +76 to +77

Copilot AI Dec 12, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should verify the exception message or type, not just that any exception is thrown. Consider using assertThrows with a specific exception type check and optionally validating the error message contains expected text like 'illegal' and '1 blocks'.

Copilot uses AI. Check for mistakes.
} catch (Exception e) {
// ignore
}

// case2: legal invoke
processedBlockIds = new HashSet<>();
processedBlockIds.add(1L);
processedBlockIds.add(2L);
RssUtils.checkProcessedBlockIds(exceptedBlockIds, processedBlockIds);
}

@Test
public void testGetPropertiesFromFile() {
final String filePath =
Expand Down
Loading