Skip to content

Commit f9d9833

Browse files
BryanCutlerwesm
authored andcommitted
ARROW-1283: [JAVA] Allow VectorSchemaRoot to close more than once
This change allows the VectorSchemaRoot/FieldVectors to close more than once, even if the allocator has already been closed. Before, an empty ArrowBuf was created during closing which required the allocator to not be closed, however this empty buffer is not needed once the FieldVector has been closed. Author: Bryan Cutler <cutlerb@gmail.com> Closes apache#898 from BryanCutler/java-vectorSchemaRoot-close-twice-ARROW-1283 and squashes the following commits: 2921d84 [Bryan Cutler] removed resolved comment 3b3718b [Bryan Cutler] Merge remote-tracking branch 'upstream/master' into java-vectorSchemaRoot-close-twice-ARROW-1283 e992fc7 [Bryan Cutler] BaseDataValueVector.close will now just clear, which releases previous and assigns an empty buffer 8ecfce2 [Bryan Cutler] Merge remote-tracking branch 'upstream/master' into java-vectorSchemaRoot-close-twice-ARROW-1283 ca38d3d [Bryan Cutler] use clear to release data, ensure that an empty buffer is never allocated again after closing 10ff7c3 [Bryan Cutler] Added regression test
1 parent c0acb86 commit f9d9833

3 files changed

Lines changed: 11 additions & 18 deletions

File tree

‎java/memory/src/main/java/org/apache/arrow/memory/BaseAllocator.java‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ public String getName() {
171171

172172
@Override
173173
public ArrowBuf getEmpty() {
174-
assertOpen();
175174
return empty;
176175
}
177176

@@ -236,8 +235,6 @@ public ArrowBuf buffer(final int initialRequestSize) {
236235
}
237236

238237
private ArrowBuf createEmpty() {
239-
assertOpen();
240-
241238
return new ArrowBuf(new AtomicInteger(), null, AllocationManager.EMPTY, null, null, 0, 0, true);
242239
}
243240

‎java/vector/src/main/java/org/apache/arrow/vector/BaseDataValueVector.java‎

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ public static List<ArrowBuf> unload(List<BufferBacked> vectors) {
5959
return result;
6060
}
6161

62-
// TODO: Nullable vectors extend BaseDataValueVector but do not use the data field
63-
// We should fix the inheritance tree
6462
protected ArrowBuf data;
6563

6664
public BaseDataValueVector(String name, BufferAllocator allocator) {
@@ -70,23 +68,11 @@ public BaseDataValueVector(String name, BufferAllocator allocator) {
7068

7169
@Override
7270
public void clear() {
73-
if (data != null) {
74-
data.release();
75-
}
71+
data.release();
7672
data = allocator.getEmpty();
7773
super.clear();
7874
}
7975

80-
@Override
81-
public void close() {
82-
clear();
83-
if (data != null) {
84-
data.release();
85-
data = null;
86-
}
87-
super.close();
88-
}
89-
9076
@Override
9177
public TransferPair getTransferPair(String ref, BufferAllocator allocator, CallBack callBack) {
9278
return getTransferPair(ref, allocator);

‎java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,16 @@ public void testFillEmptiesUsage() {
736736
}
737737
}
738738

739+
@Test
740+
public void testMultipleClose() {
741+
BufferAllocator vectorAllocator = allocator.newChildAllocator("vector_allocator", 0, Long.MAX_VALUE);
742+
NullableIntVector vector = newVector(NullableIntVector.class, EMPTY_SCHEMA_PATH, MinorType.INT, vectorAllocator);
743+
vector.close();
744+
vectorAllocator.close();
745+
vector.close();
746+
vectorAllocator.close();
747+
}
748+
739749
public static void setBytes(int index, byte[] bytes, NullableVarCharVector vector) {
740750
final int currentOffset = vector.values.offsetVector.getAccessor().get(index);
741751

0 commit comments

Comments
 (0)