Skip to content

Commit 3da6402

Browse files
1 parent 45d8010 commit 3da6402

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

java/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,8 @@ under the License.
327327
<io.netty.tryReflectionSetAccessible>true</io.netty.tryReflectionSetAccessible>
328328
<user.timezone>UTC</user.timezone>
329329
<!-- Note: changing the below configuration might increase the max allocation size for a vector
330-
which in turn can cause OOM. -->
331-
<arrow.vector.max_allocation_bytes>1048576</arrow.vector.max_allocation_bytes>
330+
which in turn can cause OOM. Using 2MB - 1byte to simulate the defaul limit of 2^31 - 1 bytes. -->
331+
<arrow.vector.max_allocation_bytes>2097151</arrow.vector.max_allocation_bytes>
332332
</systemPropertyVariables>
333333
<useModulePath>false</useModulePath>
334334
</configuration>

java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,13 @@ public void reallocDataBuffer(long desiredAllocSize) {
571571
return;
572572
}
573573

574-
final long newAllocationSize = CommonUtil.nextPowerOfTwo(desiredAllocSize);
574+
final long newAllocationSize =
575+
Math.min(CommonUtil.nextPowerOfTwo(desiredAllocSize), MAX_BUFFER_SIZE);
575576
assert newAllocationSize >= 1;
576577

577-
checkDataBufferSize(newAllocationSize);
578+
if (newAllocationSize < desiredAllocSize) {
579+
checkDataBufferSize(desiredAllocSize);
580+
}
578581

579582
final ArrowBuf newBuf = allocator.buffer(newAllocationSize);
580583
newBuf.setBytes(0, valueBuffer, 0, valueBuffer.capacity());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void init() {
9595
private static final byte[] STR5 = "EEE5".getBytes(utf8Charset);
9696
private static final byte[] STR6 = "FFFFF6".getBytes(utf8Charset);
9797
private static final int MAX_VALUE_COUNT =
98-
(int) (Integer.getInteger("arrow.vector.max_allocation_bytes", Integer.MAX_VALUE) / 7);
98+
(int) (Integer.getInteger("arrow.vector.max_allocation_bytes", Integer.MAX_VALUE) / 9);
9999
private static final int MAX_VALUE_COUNT_8BYTE = (int) (MAX_VALUE_COUNT / 2);
100100

101101
@AfterEach

java/vector/src/test/java/org/apache/arrow/vector/TestVectorReAlloc.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.nio.charset.StandardCharsets;
2525
import org.apache.arrow.memory.BufferAllocator;
2626
import org.apache.arrow.memory.RootAllocator;
27+
import org.apache.arrow.memory.util.CommonUtil;
2728
import org.apache.arrow.vector.complex.DenseUnionVector;
2829
import org.apache.arrow.vector.complex.FixedSizeListVector;
2930
import org.apache.arrow.vector.complex.ListVector;
@@ -222,6 +223,17 @@ public void testVariableAllocateAfterReAlloc() throws Exception {
222223
}
223224
}
224225

226+
@Test
227+
public void testVariableReAllocAbove1GB() throws Exception {
228+
try (final VarCharVector vector = new VarCharVector("", allocator)) {
229+
long desiredSizeAboveLastPowerOf2 =
230+
CommonUtil.nextPowerOfTwo(BaseVariableWidthVector.MAX_ALLOCATION_SIZE) / 2 + 1;
231+
vector.reallocDataBuffer(desiredSizeAboveLastPowerOf2);
232+
233+
assertTrue(vector.getDataBuffer().capacity() >= desiredSizeAboveLastPowerOf2);
234+
}
235+
}
236+
225237
@Test
226238
public void testLargeVariableAllocateAfterReAlloc() throws Exception {
227239
try (final LargeVarCharVector vector = new LargeVarCharVector("", allocator)) {

java/vector/src/test/java/org/apache/arrow/vector/util/TestVectorAppender.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.List;
2727
import org.apache.arrow.memory.BufferAllocator;
2828
import org.apache.arrow.memory.RootAllocator;
29+
import org.apache.arrow.memory.util.CommonUtil;
2930
import org.apache.arrow.vector.BaseValueVector;
3031
import org.apache.arrow.vector.BigIntVector;
3132
import org.apache.arrow.vector.BitVector;
@@ -192,7 +193,15 @@ public void testAppendEmptyVariableWidthVector() {
192193

193194
@Test
194195
public void testAppendLargeAndSmallVariableVectorsWithinLimit() {
195-
int sixteenthOfMaxAllocation = Math.toIntExact(BaseValueVector.MAX_ALLOCATION_SIZE / 16);
196+
// Using the max power of 2 allocation size to avoid hitting the max limit at round ups
197+
long maxPowerOfTwoAllocationSize =
198+
CommonUtil.nextPowerOfTwo(BaseValueVector.MAX_ALLOCATION_SIZE);
199+
if (maxPowerOfTwoAllocationSize > BaseValueVector.MAX_ALLOCATION_SIZE) {
200+
maxPowerOfTwoAllocationSize =
201+
CommonUtil.nextPowerOfTwo(BaseValueVector.MAX_ALLOCATION_SIZE / 2);
202+
}
203+
204+
int sixteenthOfMaxAllocation = Math.toIntExact(maxPowerOfTwoAllocationSize / 16);
196205
try (VarCharVector target = makeVarCharVec(1, sixteenthOfMaxAllocation);
197206
VarCharVector delta = makeVarCharVec(sixteenthOfMaxAllocation, 1)) {
198207
new VectorAppender(delta).visit(target, null);

0 commit comments

Comments
 (0)