Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions java/memory/src/main/java/io/netty/buffer/ArrowBuf.java
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,12 @@ public ByteBuffer internalNioBuffer(int index, int length) {

@Override
public ByteBuffer[] nioBuffers() {
return new ByteBuffer[]{nioBuffer()};
return new ByteBuffer[] {nioBuffer()};
}

@Override
public ByteBuffer[] nioBuffers(int index, int length) {
return new ByteBuffer[]{nioBuffer(index, length)};
return new ByteBuffer[] {nioBuffer(index, length)};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ public long getPeakMemoryAllocation() {
return peakAllocation.get();
}

public long getHeadroom(){
public long getHeadroom() {
long localHeadroom = allocationLimit.get() - locallyHeldMemory.get();
if(parent == null){
if (parent == null) {
return localHeadroom;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ private void inc() {
* Decrement the ledger's reference count. If the ledger is decremented to zero, this ledger
* should release its
* ownership back to the AllocationManager
*
* @param decrement amout to decrease the reference count by
* @return the new reference count
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ public ArrowBuf buffer(final int initialRequestSize, BufferManager manager) {
throw new OutOfMemoryException(e);
}
throw e;
}
finally {
} finally {
if (!success) {
releaseBytes(actualRequestSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ public interface BufferAllocator extends AutoCloseable {
* Create an allocation reservation. A reservation is a way of building up
* a request for a buffer whose size is not known in advance. See
*
* @see AllocationReservation
*
* @return the newly created reservation
* @see AllocationReservation
*/
public AllocationReservation newReservation();

Expand All @@ -128,6 +127,7 @@ public interface BufferAllocator extends AutoCloseable {
* special because we don't
* worry about them leaking or managing reference counts on them since they don't actually
* point to any memory.
*
* @return the empty buffer
*/
public ArrowBuf getEmpty();
Expand All @@ -136,6 +136,7 @@ public interface BufferAllocator extends AutoCloseable {
* Return the name of this allocator. This is a human readable name that can help debugging.
* Typically provides
* coordinates about where this allocator was created
*
* @return the name of the allocator
*/
public String getName();
Expand All @@ -145,6 +146,7 @@ public interface BufferAllocator extends AutoCloseable {
* that an allocator is
* over its limit, all consumers of that allocator should aggressively try to addrss the
* overlimit situation.
*
* @return whether or not this allocator (or one if its parents) is over its limits
*/
public boolean isOverLimit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public synchronized void recordEvent(final String noteFormat, Object... args) {
* includes the identifying string provided at construction time, and all the recorded
* events with their stack traces.
*
* @param sb {@link StringBuilder} to write to
* @param sb {@link StringBuilder} to write to
* @param includeStackTrace whether to include the stacktrace of each event in the history
*/
public void buildHistory(final StringBuilder sb, boolean includeStackTrace) {
Expand All @@ -106,8 +106,9 @@ public void buildHistory(final StringBuilder sb, boolean includeStackTrace) {

/**
* build the history and write it to sb
* @param sb output
* @param indent starting indent (usually "")
*
* @param sb output
* @param indent starting indent (usually "")
* @param includeStackTrace whether to include the stacktrace of each event.
*/
public synchronized void buildHistory(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.memory;

import static org.junit.Assert.assertEquals;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.memory;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -59,13 +60,13 @@ public void checkBuffers() {

@Test
public void test_privateMax() throws Exception {
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
final ArrowBuf arrowBuf1 = rootAllocator.buffer(MAX_ALLOCATION / 2);
assertNotNull("allocation failed", arrowBuf1);

try(final BufferAllocator childAllocator =
rootAllocator.newChildAllocator("noLimits", 0, MAX_ALLOCATION)) {
try (final BufferAllocator childAllocator =
rootAllocator.newChildAllocator("noLimits", 0, MAX_ALLOCATION)) {
final ArrowBuf arrowBuf2 = childAllocator.buffer(MAX_ALLOCATION / 2);
assertNotNull("allocation failed", arrowBuf2);
arrowBuf2.release();
Expand All @@ -75,11 +76,11 @@ public void test_privateMax() throws Exception {
}
}

@Test(expected=IllegalStateException.class)
@Test(expected = IllegalStateException.class)
public void testRootAllocator_closeWithOutstanding() throws Exception {
try {
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
final ArrowBuf arrowBuf = rootAllocator.buffer(512);
assertNotNull("allocation failed", arrowBuf);
}
Expand All @@ -100,8 +101,8 @@ public void testRootAllocator_closeWithOutstanding() throws Exception {

@Test
public void testRootAllocator_getEmpty() throws Exception {
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
final ArrowBuf arrowBuf = rootAllocator.buffer(0);
assertNotNull("allocation failed", arrowBuf);
assertEquals("capacity was non-zero", 0, arrowBuf.capacity());
Expand All @@ -112,17 +113,17 @@ public void testRootAllocator_getEmpty() throws Exception {
@Ignore // TODO(DRILL-2740)
@Test(expected = IllegalStateException.class)
public void testAllocator_unreleasedEmpty() throws Exception {
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
@SuppressWarnings("unused")
final ArrowBuf arrowBuf = rootAllocator.buffer(0);
}
}

@Test
public void testAllocator_transferOwnership() throws Exception {
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
final BufferAllocator childAllocator1 =
rootAllocator.newChildAllocator("changeOwnership1", 0, MAX_ALLOCATION);
final BufferAllocator childAllocator2 =
Expand Down Expand Up @@ -197,7 +198,7 @@ public void testRootAllocator_createChildAndUse() throws Exception {
}
}

@Test(expected=IllegalStateException.class)
@Test(expected = IllegalStateException.class)
public void testRootAllocator_createChildDontClose() throws Exception {
try {
try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
Expand Down Expand Up @@ -232,33 +233,33 @@ private static void allocateAndFree(final BufferAllocator allocator) {

final int nBufs = 8;
final ArrowBuf[] arrowBufs = new ArrowBuf[nBufs];
for(int i = 0; i < arrowBufs.length; ++i) {
for (int i = 0; i < arrowBufs.length; ++i) {
ArrowBuf arrowBufi = allocator.buffer(MAX_ALLOCATION / nBufs);
assertNotNull("allocation failed", arrowBufi);
arrowBufs[i] = arrowBufi;
}
for(ArrowBuf arrowBufi : arrowBufs) {
for (ArrowBuf arrowBufi : arrowBufs) {
arrowBufi.release();
}
}

@Test
public void testAllocator_manyAllocations() throws Exception {
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try(final BufferAllocator childAllocator =
rootAllocator.newChildAllocator("manyAllocations", 0, MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final BufferAllocator childAllocator =
rootAllocator.newChildAllocator("manyAllocations", 0, MAX_ALLOCATION)) {
allocateAndFree(childAllocator);
}
}
}

@Test
public void testAllocator_overAllocate() throws Exception {
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try(final BufferAllocator childAllocator =
rootAllocator.newChildAllocator("overAllocate", 0, MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final BufferAllocator childAllocator =
rootAllocator.newChildAllocator("overAllocate", 0, MAX_ALLOCATION)) {
allocateAndFree(childAllocator);

try {
Expand All @@ -273,10 +274,10 @@ public void testAllocator_overAllocate() throws Exception {

@Test
public void testAllocator_overAllocateParent() throws Exception {
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try(final BufferAllocator childAllocator =
rootAllocator.newChildAllocator("overAllocateParent", 0, MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final BufferAllocator childAllocator =
rootAllocator.newChildAllocator("overAllocateParent", 0, MAX_ALLOCATION)) {
final ArrowBuf arrowBuf1 = rootAllocator.buffer(MAX_ALLOCATION / 2);
assertNotNull("allocation failed", arrowBuf1);
final ArrowBuf arrowBuf2 = childAllocator.buffer(MAX_ALLOCATION / 2);
Expand Down Expand Up @@ -326,7 +327,7 @@ public void testAllocator_createSlices() throws Exception {

try (final BufferAllocator childAllocator = rootAllocator.newChildAllocator("createSlices", 0, MAX_ALLOCATION)) {
try (final BufferAllocator childAllocator2 =
childAllocator.newChildAllocator("createSlices", 0, MAX_ALLOCATION)) {
childAllocator.newChildAllocator("createSlices", 0, MAX_ALLOCATION)) {
final ArrowBuf arrowBuf1 = childAllocator2.buffer(MAX_ALLOCATION / 8);
@SuppressWarnings("unused")
final ArrowBuf arrowBuf2 = arrowBuf1.slice(MAX_ALLOCATION / 16, MAX_ALLOCATION / 16);
Expand All @@ -345,8 +346,8 @@ public void testAllocator_createSlices() throws Exception {
@Test
public void testAllocator_sliceRanges() throws Exception {
// final AllocatorOwner allocatorOwner = new NamedOwner("sliceRanges");
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
// Populate a buffer with byte values corresponding to their indices.
final ArrowBuf arrowBuf = rootAllocator.buffer(256);
assertEquals(256, arrowBuf.capacity());
Expand All @@ -362,7 +363,7 @@ public void testAllocator_sliceRanges() throws Exception {
// assertEquals(256, slice3.capacity());
// assertEquals(256, slice3.writableBytes());

for(int i = 0; i < 256; ++i) {
for (int i = 0; i < 256; ++i) {
arrowBuf.writeByte(i);
}
assertEquals(0, arrowBuf.readerIndex());
Expand All @@ -373,18 +374,18 @@ public void testAllocator_sliceRanges() throws Exception {
final ArrowBuf slice1 = (ArrowBuf) arrowBuf.slice();
assertEquals(0, slice1.readerIndex());
assertEquals(256, slice1.readableBytes());
for(int i = 0; i < 10; ++i) {
for (int i = 0; i < 10; ++i) {
assertEquals(i, slice1.readByte());
}
assertEquals(256 - 10, slice1.readableBytes());
for(int i = 0; i < 256; ++i) {
for (int i = 0; i < 256; ++i) {
assertEquals((byte) i, slice1.getByte(i));
}

final ArrowBuf slice2 = arrowBuf.slice(25, 25);
assertEquals(0, slice2.readerIndex());
assertEquals(25, slice2.readableBytes());
for(int i = 25; i < 50; ++i) {
for (int i = 25; i < 50; ++i) {
assertEquals(i, slice2.readByte());
}

Expand All @@ -404,32 +405,32 @@ public void testAllocator_sliceRanges() throws Exception {
@Test
public void testAllocator_slicesOfSlices() throws Exception {
// final AllocatorOwner allocatorOwner = new NamedOwner("slicesOfSlices");
try(final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
try (final RootAllocator rootAllocator =
new RootAllocator(MAX_ALLOCATION)) {
// Populate a buffer with byte values corresponding to their indices.
final ArrowBuf arrowBuf = rootAllocator.buffer(256);
for(int i = 0; i < 256; ++i) {
for (int i = 0; i < 256; ++i) {
arrowBuf.writeByte(i);
}

// Slice it up.
final ArrowBuf slice0 = arrowBuf.slice(0, arrowBuf.capacity());
for(int i = 0; i < 256; ++i) {
for (int i = 0; i < 256; ++i) {
assertEquals((byte) i, arrowBuf.getByte(i));
}

final ArrowBuf slice10 = slice0.slice(10, arrowBuf.capacity() - 10);
for(int i = 10; i < 256; ++i) {
for (int i = 10; i < 256; ++i) {
assertEquals((byte) i, slice10.getByte(i - 10));
}

final ArrowBuf slice20 = slice10.slice(10, arrowBuf.capacity() - 20);
for(int i = 20; i < 256; ++i) {
for (int i = 20; i < 256; ++i) {
assertEquals((byte) i, slice20.getByte(i - 20));
}

final ArrowBuf slice30 = slice20.slice(10, arrowBuf.capacity() - 30);
for(int i = 30; i < 256; ++i) {
final ArrowBuf slice30 = slice20.slice(10, arrowBuf.capacity() - 30);
for (int i = 30; i < 256; ++i) {
assertEquals((byte) i, slice30.getByte(i - 30));
}

Expand Down Expand Up @@ -556,8 +557,8 @@ public void testAllocator_transferShared() throws Exception {
public void testAllocator_unclaimedReservation() throws Exception {
try (final RootAllocator rootAllocator = new RootAllocator(MAX_ALLOCATION)) {
try (final BufferAllocator childAllocator1 =
rootAllocator.newChildAllocator("unclaimedReservation", 0, MAX_ALLOCATION)) {
try(final AllocationReservation reservation = childAllocator1.newReservation()) {
rootAllocator.newChildAllocator("unclaimedReservation", 0, MAX_ALLOCATION)) {
try (final AllocationReservation reservation = childAllocator1.newReservation()) {
assertTrue(reservation.add(64));
}
rootAllocator.verify();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.arrow.memory;

import static org.junit.Assert.assertEquals;

import io.netty.buffer.ByteBuf;

import org.apache.arrow.memory.BufferAllocator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public void run() throws IOException {
LOGGER.info("Closed connection with client");
}
} catch (java.net.SocketException ex) {
if (!closed) throw ex;
if (!closed) {
throw ex;
}
} finally {
serverSocket.close();
LOGGER.info("Server closed.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class FileRoundtrip {
private final Options options;
private final PrintStream out;
private final PrintStream err;

FileRoundtrip(PrintStream out, PrintStream err) {
this.out = out;
this.err = err;
Expand Down
Loading