diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java index d0f4c0345f4..2b85d7912bd 100644 --- a/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java +++ b/exec/java-exec/src/main/java/org/apache/drill/exec/cache/VectorAccessibleSerializable.java @@ -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; @@ -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);