Skip to content

Commit

Permalink
DRILL-8485: HashJoinPOP memory leak is caused by an oom exception whe…
Browse files Browse the repository at this point in the history
…n read data from InputStream (#2891)
  • Loading branch information
shfshihuafeng authored Mar 25, 2024
1 parent 26f4d30 commit 749772c
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.OutputStream;
import java.util.List;

import org.apache.drill.common.exceptions.UserException;
import org.apache.drill.exec.expr.TypeHelper;
import org.apache.drill.exec.memory.BufferAllocator;
import org.apache.drill.exec.metrics.DrillMetrics;
Expand Down Expand Up @@ -124,11 +125,19 @@ private void readVectors(InputStream input, RecordBatchDef batchDef) throws IOEx
for (SerializedField metaData : fieldList) {
final int dataLength = metaData.getBufferLength();
final MaterializedField field = MaterializedField.create(metaData);
final DrillBuf buf = allocator.read(dataLength, input);
final ValueVector vector = TypeHelper.getNewVector(field, allocator);
vector.load(metaData, buf);
buf.release(); // Vector now owns the buffer
vectorList.add(vector);
DrillBuf buf = null;
try {
buf = allocator.read(dataLength, input);
final ValueVector vector = TypeHelper.getNewVector(field, allocator);
vector.load(metaData, buf);
buf.release(); // Vector now owns the buffer
vectorList.add(vector);
} catch (OutOfMemoryError oom) {
for (ValueVector valueVector : vectorList) {
valueVector.clear();
}
throw UserException.memoryError(oom).message("Allocator memory failed").build(logger);
}
}
container.addCollection(vectorList);
container.buildSchema(svMode);
Expand Down

0 comments on commit 749772c

Please sign in to comment.