-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-260: TestValueVector.testFixedVectorReallocation and testVariableVectorReallocation are flaky #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
ARROW-260: TestValueVector.testFixedVectorReallocation and testVariableVectorReallocation are flaky #118
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7d1444f
Limit max allocation bytes for a vector as 1 KB
jihoonson 8fd43ef
Remove System.setProperty() in TestValueVector
jihoonson 062e312
Move tests which test OversizedAllocationException for ValueVector in…
jihoonson 5989a2e
Add a comment for the new test
jihoonson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
java/vector/src/test/java/org/apache/arrow/vector/TestOversizedAllocationForValueVector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.apache.arrow.vector; | ||
|
|
||
| import org.apache.arrow.memory.BufferAllocator; | ||
| import org.apache.arrow.memory.RootAllocator; | ||
| import org.apache.arrow.vector.holders.UInt4Holder; | ||
| import org.apache.arrow.vector.types.MaterializedField; | ||
| import org.apache.arrow.vector.util.OversizedAllocationException; | ||
| import org.junit.After; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| /** | ||
| * This class tests that OversizedAllocationException occurs when a large memory is allocated for a vector. | ||
| * Typically, arrow allows the allocation of the size of at most Integer.MAX_VALUE, but this might cause OOM in tests. | ||
| * Thus, the max allocation size is limited to 1 KB in this class. Please see the surefire option in pom.xml. | ||
| */ | ||
| public class TestOversizedAllocationForValueVector { | ||
|
|
||
| private final static String EMPTY_SCHEMA_PATH = ""; | ||
|
|
||
| private BufferAllocator allocator; | ||
|
|
||
| @Before | ||
| public void init() { | ||
| allocator = new RootAllocator(Long.MAX_VALUE); | ||
| } | ||
|
|
||
| @After | ||
| public void terminate() throws Exception { | ||
| allocator.close(); | ||
| } | ||
|
|
||
| @Test(expected = OversizedAllocationException.class) | ||
| public void testFixedVectorReallocation() { | ||
| final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE); | ||
| final UInt4Vector vector = new UInt4Vector(field, allocator); | ||
| // edge case 1: buffer size = max value capacity | ||
| final int expectedValueCapacity = BaseValueVector.MAX_ALLOCATION_SIZE / 4; | ||
| try { | ||
| vector.allocateNew(expectedValueCapacity); | ||
| assertEquals(expectedValueCapacity, vector.getValueCapacity()); | ||
| vector.reAlloc(); | ||
| assertEquals(expectedValueCapacity * 2, vector.getValueCapacity()); | ||
| } finally { | ||
| vector.close(); | ||
| } | ||
|
|
||
| // common case: value count < max value capacity | ||
| try { | ||
| vector.allocateNew(BaseValueVector.MAX_ALLOCATION_SIZE / 8); | ||
| vector.reAlloc(); // value allocation reaches to MAX_VALUE_ALLOCATION | ||
| vector.reAlloc(); // this should throw an IOOB | ||
| } finally { | ||
| vector.close(); | ||
| } | ||
| } | ||
|
|
||
| @Test(expected = OversizedAllocationException.class) | ||
| public void testBitVectorReallocation() { | ||
| final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE); | ||
| final BitVector vector = new BitVector(field, allocator); | ||
| // edge case 1: buffer size ~ max value capacity | ||
| final int expectedValueCapacity = 1 << 29; | ||
| try { | ||
| vector.allocateNew(expectedValueCapacity); | ||
| assertEquals(expectedValueCapacity, vector.getValueCapacity()); | ||
| vector.reAlloc(); | ||
| assertEquals(expectedValueCapacity * 2, vector.getValueCapacity()); | ||
| } finally { | ||
| vector.close(); | ||
| } | ||
|
|
||
| // common: value count < MAX_VALUE_ALLOCATION | ||
| try { | ||
| vector.allocateNew(expectedValueCapacity); | ||
| for (int i=0; i<3;i++) { | ||
| vector.reAlloc(); // expand buffer size | ||
| } | ||
| assertEquals(Integer.MAX_VALUE, vector.getValueCapacity()); | ||
| vector.reAlloc(); // buffer size ~ max allocation | ||
| assertEquals(Integer.MAX_VALUE, vector.getValueCapacity()); | ||
| vector.reAlloc(); // overflow | ||
| } finally { | ||
| vector.close(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| @Test(expected = OversizedAllocationException.class) | ||
| public void testVariableVectorReallocation() { | ||
| final MaterializedField field = MaterializedField.create(EMPTY_SCHEMA_PATH, UInt4Holder.TYPE); | ||
| final VarCharVector vector = new VarCharVector(field, allocator); | ||
| // edge case 1: value count = MAX_VALUE_ALLOCATION | ||
| final int expectedAllocationInBytes = BaseValueVector.MAX_ALLOCATION_SIZE; | ||
| final int expectedOffsetSize = 10; | ||
| try { | ||
| vector.allocateNew(expectedAllocationInBytes, 10); | ||
| assertTrue(expectedOffsetSize <= vector.getValueCapacity()); | ||
| assertTrue(expectedAllocationInBytes <= vector.getBuffer().capacity()); | ||
| vector.reAlloc(); | ||
| assertTrue(expectedOffsetSize * 2 <= vector.getValueCapacity()); | ||
| assertTrue(expectedAllocationInBytes * 2 <= vector.getBuffer().capacity()); | ||
| } finally { | ||
| vector.close(); | ||
| } | ||
|
|
||
| // common: value count < MAX_VALUE_ALLOCATION | ||
| try { | ||
| vector.allocateNew(BaseValueVector.MAX_ALLOCATION_SIZE / 2, 0); | ||
| vector.reAlloc(); // value allocation reaches to MAX_VALUE_ALLOCATION | ||
| vector.reAlloc(); // this tests if it overflows | ||
| } finally { | ||
| vector.close(); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a short comment here about how the pom changes allow this to work in less memory than typically required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment.
Besides, I think it would be nice if we have a wiki for arrow developers. In wiki, we can easily search this information about limiting the max allocation size in tests.