Skip to content

Commit

Permalink
DRILL-8478. HashPartition memory leak when it allocate memory excepti…
Browse files Browse the repository at this point in the history
…on with OutOfMemoryException (#2874)
  • Loading branch information
shfshihuafeng committed Jan 23, 2024
1 parent bfdafd9 commit 31ca454
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ public HashPartition(FragmentContext context, BufferAllocator allocator, Chained

try {
this.hashTable = baseHashTable.createAndSetupHashTable(null);
this.hjHelper = semiJoin ? null : new HashJoinHelper(context, allocator);
tmpBatchesList = new ArrayList<>();
if (numPartitions > 1) {
allocateNewCurrentBatchAndHV();
}
} catch (ClassTransformationException e) {
throw UserException.unsupportedError(e)
.message("Code generation error - likely an error in the code.")
Expand All @@ -157,11 +162,11 @@ public HashPartition(FragmentContext context, BufferAllocator allocator, Chained
.build(logger);
} catch (SchemaChangeException sce) {
throw new IllegalStateException("Unexpected Schema Change while creating a hash table",sce);
}
this.hjHelper = semiJoin ? null : new HashJoinHelper(context, allocator);
tmpBatchesList = new ArrayList<>();
if (numPartitions > 1) {
allocateNewCurrentBatchAndHV();
} catch (OutOfMemoryException oom) {
close();
throw UserException.memoryError(oom)
.message("OutOfMemory while allocate memory for hash partition.")
.build(logger);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import static org.apache.drill.exec.record.RecordBatch.IterOutcome.EMIT;
Expand Down Expand Up @@ -1312,7 +1313,9 @@ private void cleanup() {
}
// clean (and deallocate) each partition, and delete its spill file
for (HashPartition partn : partitions) {
partn.close();
if (Objects.nonNull(partn)) {
partn.close();
}
}

// delete any spill file left in unread spilled partitions
Expand Down

0 comments on commit 31ca454

Please sign in to comment.