BryanCutler commented on a change in pull request #6323:
URL: https://github.com/apache/arrow/pull/6323#discussion_r414120706



##########
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##########
@@ -34,31 +33,34 @@
   static final UnsafeDirectLittleEndian EMPTY = INNER_ALLOCATOR.empty;
   static final long CHUNK_SIZE = INNER_ALLOCATOR.getChunkSize();
 
-  private final int allocatedSize;
+  private final long allocatedSize;
   private final UnsafeDirectLittleEndian memoryChunk;
+  private final long allocatedAddress;
 
-  NettyAllocationManager(BaseAllocator accountingAllocator, int requestedSize) 
{
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize) {
     super(accountingAllocator);
-    this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
-    this.allocatedSize = memoryChunk.capacity();
-  }
-
-  /**
-   * Get the underlying memory chunk managed by this AllocationManager.
-   * @return buffer
-   */
-  UnsafeDirectLittleEndian getMemoryChunk() {
-    return memoryChunk;
+    if (requestedSize > Integer.MAX_VALUE) {
+      memoryChunk = null;

Review comment:
       use `this.memoryChunk` to be consistent

##########
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##########
@@ -34,31 +33,34 @@
   static final UnsafeDirectLittleEndian EMPTY = INNER_ALLOCATOR.empty;
   static final long CHUNK_SIZE = INNER_ALLOCATOR.getChunkSize();
 
-  private final int allocatedSize;
+  private final long allocatedSize;
   private final UnsafeDirectLittleEndian memoryChunk;
+  private final long allocatedAddress;
 
-  NettyAllocationManager(BaseAllocator accountingAllocator, int requestedSize) 
{
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize) {
     super(accountingAllocator);
-    this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
-    this.allocatedSize = memoryChunk.capacity();
-  }
-
-  /**
-   * Get the underlying memory chunk managed by this AllocationManager.
-   * @return buffer
-   */
-  UnsafeDirectLittleEndian getMemoryChunk() {
-    return memoryChunk;
+    if (requestedSize > Integer.MAX_VALUE) {
+      memoryChunk = null;
+      allocatedAddress = PlatformDependent.allocateMemory(requestedSize);
+    } else {
+      this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
+      allocatedAddress = memoryChunk.memoryAddress();

Review comment:
       could you keep `allocatedSize = memoryChunk.capacity()` for this case?

##########
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##########
@@ -34,31 +33,34 @@
   static final UnsafeDirectLittleEndian EMPTY = INNER_ALLOCATOR.empty;
   static final long CHUNK_SIZE = INNER_ALLOCATOR.getChunkSize();
 
-  private final int allocatedSize;
+  private final long allocatedSize;
   private final UnsafeDirectLittleEndian memoryChunk;
+  private final long allocatedAddress;
 
-  NettyAllocationManager(BaseAllocator accountingAllocator, int requestedSize) 
{
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize) {
     super(accountingAllocator);
-    this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
-    this.allocatedSize = memoryChunk.capacity();
-  }
-
-  /**
-   * Get the underlying memory chunk managed by this AllocationManager.
-   * @return buffer
-   */
-  UnsafeDirectLittleEndian getMemoryChunk() {

Review comment:
       instead of removing this, could you deprecate and note it will be 
removed in future releases?  also note that it will return null if allocated 
size is more than max int.

##########
File path: 
java/memory/src/test/java/org/apache/arrow/memory/TestLargeArrowBuf.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.memory;
+
+import static org.junit.Assert.assertEquals;
+
+import io.netty.buffer.ArrowBuf;
+
+/**
+ * Integration test for large (more than 2GB) {@link io.netty.buffer.ArrowBuf}.
+ * To run this test, please
+ *<li>Make sure there are 4GB memory available in the system.</li>
+ * <li>
+ *   Make sure the default allocation manager type is unsafe.
+ *   This can be achieved by the environmental variable or system property.
+ *   The details can be found in {@link DefaultAllocationManagerOption}.
+ * </li>
+ */
+public class TestLargeArrowBuf {
+
+  private static void testLargeArrowBuf() {
+    final long bufSize = 4 * 1024 * 1024 * 1024L;
+    try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
+         ArrowBuf largeBuf = allocator.buffer(bufSize)) {
+      assertEquals(bufSize, largeBuf.capacity());
+      System.out.println("Successfully allocated a buffer with capacity " + 
largeBuf.capacity());
+
+      for (long i = 0; i < bufSize / 8; i++) {
+        largeBuf.setLong(i * 8, i);
+
+        if ((i + 1) % 10000 == 0) {
+          System.out.println("Successfully written " + (i + 1) + " long 
words");
+        }
+      }
+      System.out.println("Successfully written " + (bufSize / 8) + " long 
words");
+
+      for (long i = 0; i < bufSize / 8; i++) {
+        long val = largeBuf.getLong(i * 8);
+        assertEquals(i, val);
+
+        if ((i + 1) % 10000 == 0) {
+          System.out.println("Successfully read " + (i + 1) + " long words");
+        }
+      }
+      System.out.println("Successfully read " + (bufSize / 8) + " long words");
+    }
+    System.out.println("Successfully released the large buffer.");
+  }
+
+  public static void main(String[] args) {

Review comment:
       What do you think about adding an additional constructor for 
`NettyAllocationManager` that also takes a cut-off value that will determine if 
`PlatformDependent.allocateMemory(requestedSize)` is used with a default of 
`Int.MAX_VALUE`? Then you could create a new `NettyAllocationManager` for 
testing with a small cut-off value that can be used to run normal tests.




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to