rymarm commented on a change in pull request #2185:
URL: https://github.com/apache/drill/pull/2185#discussion_r591259363
##########
File path:
exec/memory/base/src/main/java/org/apache/drill/exec/memory/DrillByteBufAllocator.java
##########
@@ -111,31 +118,68 @@ public boolean isDirectBufferPooled() {
@Override
public ByteBuf heapBuffer() {
- throw fail();
+ return HEAP_ALLOCATOR.allocateHeap();
}
@Override
public ByteBuf heapBuffer(int initialCapacity) {
- throw fail();
+ return HEAP_ALLOCATOR.allocateHeap(initialCapacity);
}
@Override
public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) {
- throw fail();
+ return HEAP_ALLOCATOR.allocateHeap(initialCapacity, maxCapacity);
}
@Override
public CompositeByteBuf compositeHeapBuffer() {
- throw fail();
+ return compositeHeapBuffer(DEFAULT_MAX_COMPOSITE_COMPONENTS);
}
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
- throw fail();
- }
-
- private RuntimeException fail() {
- throw new UnsupportedOperationException("Allocator doesn't support
heap-based memory.");
+ return new CompositeByteBuf(this, false, maxNumComponents);
+ }
+
+ /**
+ * This method was copied from AbstractByteBufAllocator. Netty 4.1.x moved
this method from
+ * AbstractByteBuf to AbstractByteBufAllocator. However, as
DrillByteBufAllocator doesn't extend
+ * AbstractByteBufAllocator, it doesn't get the implementation automatically
and we have to copy
+ * the codes.
+ */
+ @Override
+ public int calculateNewCapacity(int minNewCapacity, int maxCapacity) {
Review comment:
Yea, you are right. I were thinking about it, but for some reason decide
to not do like that. But yes, it's a better solution that also let remove
redundant code in `DrillByteBufAllocator` and in `PooledByteBufAllocatorL`.
Done.
##########
File path:
exec/memory/base/src/main/java/org/apache/drill/exec/memory/DrillByteBufAllocator.java
##########
@@ -111,31 +118,68 @@ public boolean isDirectBufferPooled() {
@Override
public ByteBuf heapBuffer() {
- throw fail();
+ return HEAP_ALLOCATOR.allocateHeap();
}
@Override
public ByteBuf heapBuffer(int initialCapacity) {
- throw fail();
+ return HEAP_ALLOCATOR.allocateHeap(initialCapacity);
}
@Override
public ByteBuf heapBuffer(int initialCapacity, int maxCapacity) {
- throw fail();
+ return HEAP_ALLOCATOR.allocateHeap(initialCapacity, maxCapacity);
}
@Override
public CompositeByteBuf compositeHeapBuffer() {
- throw fail();
+ return compositeHeapBuffer(DEFAULT_MAX_COMPOSITE_COMPONENTS);
}
@Override
public CompositeByteBuf compositeHeapBuffer(int maxNumComponents) {
- throw fail();
- }
-
- private RuntimeException fail() {
- throw new UnsupportedOperationException("Allocator doesn't support
heap-based memory.");
+ return new CompositeByteBuf(this, false, maxNumComponents);
+ }
+
+ /**
+ * This method was copied from AbstractByteBufAllocator. Netty 4.1.x moved
this method from
+ * AbstractByteBuf to AbstractByteBufAllocator. However, as
DrillByteBufAllocator doesn't extend
+ * AbstractByteBufAllocator, it doesn't get the implementation automatically
and we have to copy
+ * the codes.
+ */
+ @Override
+ public int calculateNewCapacity(int minNewCapacity, int maxCapacity) {
Review comment:
Yeah, you are right. I were thinking about it, but for some reason
decide to not do like that. But yes, it's a better solution that also let
remove redundant code in `DrillByteBufAllocator` and in
`PooledByteBufAllocatorL`.
Done.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]