Skip to content

Commit 5313608

Browse files
authored
[AMORO-4147] [Improvement]: Resource leak in CombinedDeleteFilter and MixedDeleteFilter position delete iterators. (#4148)
1 parent 45f074d commit 5313608

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

amoro-format-iceberg/src/main/java/org/apache/amoro/io/reader/CombinedDeleteFilter.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,18 @@ private Predicate<StructForDelete<T>> applyPosDeletes() {
397397
if (positionMap == null) {
398398
positionMap = new HashMap<>();
399399
List<CloseableIterable<Record>> deletes = Lists.transform(posDeletes, this::openPosDeletes);
400-
CloseableIterator<Record> iterator = CloseableIterable.concat(deletes).iterator();
401-
while (iterator.hasNext()) {
402-
Record deleteRecord = iterator.next();
403-
String path = FILENAME_ACCESSOR.get(deleteRecord).toString();
404-
if (positionPathSets != null && !positionPathSets.contains(path)) {
405-
continue;
400+
try (CloseableIterator<Record> iterator = CloseableIterable.concat(deletes).iterator()) {
401+
while (iterator.hasNext()) {
402+
Record deleteRecord = iterator.next();
403+
String path = FILENAME_ACCESSOR.get(deleteRecord).toString();
404+
if (positionPathSets != null && !positionPathSets.contains(path)) {
405+
continue;
406+
}
407+
Roaring64Bitmap posBitMap = positionMap.computeIfAbsent(path, k -> new Roaring64Bitmap());
408+
posBitMap.add((Long) POSITION_ACCESSOR.get(deleteRecord));
406409
}
407-
Roaring64Bitmap posBitMap = positionMap.computeIfAbsent(path, k -> new Roaring64Bitmap());
408-
posBitMap.add((Long) POSITION_ACCESSOR.get(deleteRecord));
410+
} catch (IOException e) {
411+
throw new RuntimeException("Failed to close position delete iterator", e);
409412
}
410413
}
411414

amoro-format-iceberg/src/main/java/org/apache/amoro/io/reader/MixedDeleteFilter.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,19 +369,22 @@ private Predicate<T> applyPosDeletes() {
369369
if (positionMap == null) {
370370
positionMap = new HashMap<>();
371371
List<CloseableIterable<Record>> deletes = Lists.transform(posDeletes, this::openPosDeletes);
372-
CloseableIterator<Record> iterator = CloseableIterable.concat(deletes).iterator();
373-
while (iterator.hasNext()) {
374-
Record deleteRecord = iterator.next();
375-
String path = FILENAME_ACCESSOR.get(deleteRecord).toString();
376-
if (!pathSets.contains(path)) {
377-
continue;
378-
}
379-
Set<Long> posSet = positionMap.get(path);
380-
if (posSet == null) {
381-
posSet = new HashSet<>();
382-
positionMap.put(path, posSet);
372+
try (CloseableIterator<Record> iterator = CloseableIterable.concat(deletes).iterator()) {
373+
while (iterator.hasNext()) {
374+
Record deleteRecord = iterator.next();
375+
String path = FILENAME_ACCESSOR.get(deleteRecord).toString();
376+
if (!pathSets.contains(path)) {
377+
continue;
378+
}
379+
Set<Long> posSet = positionMap.get(path);
380+
if (posSet == null) {
381+
posSet = new HashSet<>();
382+
positionMap.put(path, posSet);
383+
}
384+
posSet.add((Long) POSITION_ACCESSOR.get(deleteRecord));
383385
}
384-
posSet.add((Long) POSITION_ACCESSOR.get(deleteRecord));
386+
} catch (IOException e) {
387+
throw new RuntimeException("Failed to close position delete iterator", e);
385388
}
386389
}
387390

0 commit comments

Comments
 (0)