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
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.arrow.memory.OutOfMemoryException;
import org.apache.arrow.memory.util.LargeMemoryUtil;

import io.netty.util.internal.OutOfDirectMemoryError;
import io.netty.util.internal.StringUtil;

/**
Expand Down Expand Up @@ -56,9 +57,17 @@ public UnsafeDirectLittleEndian allocate(long size) {
try {
return allocator.directBuffer(LargeMemoryUtil.checkedCastToInt(size), Integer.MAX_VALUE);
} catch (OutOfMemoryError e) {
throw new OutOfMemoryException("Failure allocating buffer.", e);
/*
* OutOfDirectMemoryError is thrown by Netty when we exceed the direct memory limit defined by
* -XX:MaxDirectMemorySize. OutOfMemoryError with "Direct buffer memory" message is thrown by
* java.nio.Bits when we exceed the direct memory limit. This should never be hit in practice
* as Netty is expected to throw an OutOfDirectMemoryError first.
*/
if (e instanceof OutOfDirectMemoryError || "Direct buffer memory".equals(e.getMessage())) {
throw new OutOfMemoryException("Failure allocating buffer.", e);
}
throw e;
}

}

public int getChunkSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
* the signature and the fact that this Allocator returns ExpandableByteBufs which enable
* otherwise non-expandable
* ArrowBufs to be expandable.
*
* @deprecated This class may be removed in a future release.
*/
@Deprecated
public class ArrowByteBufAllocator extends AbstractByteBufAllocator {

private static final int DEFAULT_BUFFER_SIZE = 4096;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.immutables.value.Value;

import io.netty.buffer.ArrowBuf;
import io.netty.util.internal.OutOfDirectMemoryError;

/**
* A base-class that implements all functionality of {@linkplain BufferAllocator}s.
Expand Down Expand Up @@ -319,22 +318,12 @@ public ArrowBuf buffer(final long initialRequestSize, BufferManager manager) {
listener.onAllocation(actualRequestSize);
return buffer;
} catch (OutOfMemoryError e) {
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be moved to someplace netty specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the good suggestion. I have moved it into class PooledByteBufAllocatorL.

* OutOfDirectMemoryError is thrown by Netty when we exceed the direct memory limit defined by
* -XX:MaxDirectMemorySize. OutOfMemoryError with "Direct buffer memory" message is thrown by
* java.nio.Bits when we exceed the direct memory limit. This should never be hit in practice
* as Netty is expected to throw an OutOfDirectMemoryError first.
*/
if (e instanceof OutOfDirectMemoryError || "Direct buffer memory".equals(e.getMessage())) {
throw new OutOfMemoryException(e);
}
throw e;
} finally {
if (!success) {
releaseBytes(actualRequestSize);
}
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ public interface BufferAllocator extends AutoCloseable {
* Returns the allocator this allocator falls back to when it needs more memory.
*
* @return the underlying allocator used by this allocator
*
* @deprecated This method may be removed in a future release.
*/
@Deprecated
ByteBufAllocator getAsByteBufAllocator();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ void print(StringBuilder sb, int indent, BaseAllocator.Verbosity verbosity) {
/**
* Returns the underlying {@link UnsafeDirectLittleEndian} instance used by this BufferLedger.
*
* @deprecated Use #unwrap(UnsafeDirectLittleEndian.class) instead.
* @deprecated This method may be removed in a future release.
*/
@Deprecated
public UnsafeDirectLittleEndian getUnderlying() {
Expand Down Expand Up @@ -554,6 +554,7 @@ public <T> T unwrap(Class<T> clazz) {
return clazz.cast(allocationManager);
}

// TODO: remove this in a future release.
if (clazz == UnsafeDirectLittleEndian.class) {
Preconditions.checkState(allocationManager instanceof NettyAllocationManager,
"Underlying memory was not allocated by Netty");
Expand Down