Skip to content

Commit

Permalink
DRILL-8478. HashPartition memory leak when OutOfMemoryException is en…
Browse files Browse the repository at this point in the history
…countered (apache#2874) (apache#2875)
  • Loading branch information
shfshihuafeng authored Jan 23, 2024
1 parent bfdafd9 commit 051d059
Show file tree
Hide file tree
Showing 2 changed files with 13 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("Failed to allocate hash partition.")
.build(logger);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,9 @@ private void cleanup() {
}
// clean (and deallocate) each partition, and delete its spill file
for (HashPartition partn : partitions) {
partn.close();
if (partn != null) {
partn.close();
}
}

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

0 comments on commit 051d059

Please sign in to comment.