Skip to content

Commit

Permalink
DRILL-8483: SpilledRecordBatch memory leak when the program threw an …
Browse files Browse the repository at this point in the history
…exception during the process of building a hash table (#2887) (#2888)
  • Loading branch information
shfshihuafeng authored and jnturton committed Apr 12, 2024
1 parent f0c07cf commit 264537f
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ public IterOutcome innerNext() {
return rightUpstream;
}

boolean isExistException = false;

try {
/*
* If we are here for the first time, execute the build phase of the hash
Expand Down Expand Up @@ -687,6 +689,24 @@ public IterOutcome innerNext() {
return IterOutcome.NONE;
} catch (SchemaChangeException e) {
throw UserException.schemaChangeError(e).build(logger);
} catch (OutOfMemoryException oom) {
isExistException = true;
throw UserException.memoryError(oom).build(logger);
} catch (Exception e) {
//Internal catch OutOfMemoryException, resulting in throwing other exceptions or others
isExistException = true;
throw UserException.executionError(e).build(logger);
} finally {
boolean isReleaseBuildBatch = buildBatch != null && buildBatch instanceof SpilledRecordBatch;
boolean isReleaseProbeBatch = probeBatch != null && probeBatch instanceof SpilledRecordBatch;
//release buildBatch spill memory
if (isExistException && isReleaseBuildBatch) {
buildBatch.cancel();
}
//release probeBatch spill memory
if (isExistException && isReleaseProbeBatch) {
probeBatch.cancel();
}
}
}

Expand Down

0 comments on commit 264537f

Please sign in to comment.