[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-25 Thread GitBox


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



##
File path: 
java/memory/src/test/java/org/apache/arrow/memory/TestNettyAllocationManager.java
##
@@ -0,0 +1,98 @@
+/*
+ * 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 static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import io.netty.buffer.ArrowBuf;
+
+/**
+ * Test cases for {@link NettyAllocationManager}.
+ */
+public class TestNettyAllocationManager {
+
+  private void readWriteArrowBuf(ArrowBuf buffer) {
+// write buffer
+for (long i = 0; i < buffer.capacity() / 8; i++) {
+  buffer.setLong(i * 8, i);
+}
+
+// read buffer
+for (long i = 0; i < buffer.capacity() / 8; i++) {
+  long val = buffer.getLong(i * 8);
+  assertEquals(i, val);
+}
+  }
+
+  /**
+   * Test the allocation strategy for small buffers..
+   */
+  @Test
+  public void testSmallBufferAllocation() {
+final long bufSize = 512L;
+try (RootAllocator allocator = new RootAllocator(bufSize);
+ ArrowBuf buffer = allocator.buffer(bufSize)) {
+  // make sure the buffer is small enough, so we wil use the allocation 
strategy for small buffers
+  assertTrue(bufSize < 
NettyAllocationManager.DEFAULT_ALLOCATION_CUTOFF_VALUE);
+
+  assertTrue(buffer.getReferenceManager() instanceof BufferLedger);
+  BufferLedger bufferLedger = (BufferLedger) buffer.getReferenceManager();
+
+  // make sure we are using netty allocation manager
+  AllocationManager allocMgr = bufferLedger.getAllocationManager();
+  assertTrue(allocMgr instanceof NettyAllocationManager);
+  NettyAllocationManager nettyMgr = (NettyAllocationManager) allocMgr;
+
+  // for the small buffer allocation strategy, the chunk is not null
+  assertNotNull(nettyMgr.getMemoryChunk());
+
+  readWriteArrowBuf(buffer);
+}
+  }
+
+  /**
+   * Test the allocation strategy for large buffers..
+   */
+  @Test
+  public void testLargeBufferAllocation() {
+final long bufSize = 2048L;

Review comment:
   Sounds good. Revised accordingly. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-25 Thread GitBox


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



##
File path: 
java/memory/src/test/java/org/apache/arrow/memory/TestNettyAllocationManager.java
##
@@ -0,0 +1,98 @@
+/*
+ * 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 static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+import io.netty.buffer.ArrowBuf;
+
+/**
+ * Test cases for {@link NettyAllocationManager}.
+ */
+public class TestNettyAllocationManager {
+
+  private void readWriteArrowBuf(ArrowBuf buffer) {
+// write buffer
+for (long i = 0; i < buffer.capacity() / 8; i++) {
+  buffer.setLong(i * 8, i);
+}
+
+// read buffer
+for (long i = 0; i < buffer.capacity() / 8; i++) {
+  long val = buffer.getLong(i * 8);
+  assertEquals(i, val);
+}
+  }
+
+  /**
+   * Test the allocation strategy for small buffers..
+   */
+  @Test
+  public void testSmallBufferAllocation() {
+final long bufSize = 512L;
+try (RootAllocator allocator = new RootAllocator(bufSize);
+ ArrowBuf buffer = allocator.buffer(bufSize)) {
+  // make sure the buffer is small enough, so we wil use the allocation 
strategy for small buffers
+  assertTrue(bufSize < 
NettyAllocationManager.DEFAULT_ALLOCATION_CUTOFF_VALUE);
+
+  assertTrue(buffer.getReferenceManager() instanceof BufferLedger);
+  BufferLedger bufferLedger = (BufferLedger) buffer.getReferenceManager();
+
+  // make sure we are using netty allocation manager
+  AllocationManager allocMgr = bufferLedger.getAllocationManager();
+  assertTrue(allocMgr instanceof NettyAllocationManager);
+  NettyAllocationManager nettyMgr = (NettyAllocationManager) allocMgr;
+
+  // for the small buffer allocation strategy, the chunk is not null
+  assertNotNull(nettyMgr.getMemoryChunk());
+
+  readWriteArrowBuf(buffer);
+}
+  }
+
+  /**
+   * Test the allocation strategy for large buffers..
+   */
+  @Test
+  public void testLargeBufferAllocation() {
+final long bufSize = 2048L;
+try (RootAllocator allocator = new RootAllocator(bufSize);
+ ArrowBuf buffer = allocator.buffer(bufSize)) {
+  // make sure the buffer is large enough, so we wil use the allocation 
strategy for large buffers

Review comment:
   Sorry about the typo. This comment is removed. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-25 Thread GitBox


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



##
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##
@@ -17,48 +17,97 @@
 
 package org.apache.arrow.memory;
 
-import org.apache.arrow.memory.util.LargeMemoryUtil;
-
 import io.netty.buffer.PooledByteBufAllocatorL;
 import io.netty.buffer.UnsafeDirectLittleEndian;
+import io.netty.util.internal.PlatformDependent;
 
 /**
- * The default implementation of AllocationManagerBase. The implementation is 
responsible for managing when memory
+ * The default implementation of {@link AllocationManager}. The implementation 
is responsible for managing when memory
  * is allocated and returned to the Netty-based PooledByteBufAllocatorL.
  */
 public class NettyAllocationManager extends AllocationManager {
 
   public static final Factory FACTORY = new Factory();
 
+  /**
+   * The default cut-off value for switching allocation strategies.
+   * If the request size is not greater than the cut-off value, we will 
allocate memory by
+   * {@link PooledByteBufAllocatorL} APIs,
+   * otherwise, we will use {@link PlatformDependent} APIs.
+   */
+  public static final long DEFAULT_ALLOCATION_CUTOFF_VALUE;
+
+  public static final String DEFAULT_ALLOCATION_CUTOFF_NAME = 
"default.allocation.cutoff.name";
+
+  static {
+long cutOffValue;
+try {
+  cutOffValue = 
Long.parseLong(System.getProperty(DEFAULT_ALLOCATION_CUTOFF_NAME));
+} catch (Exception e) {
+  cutOffValue = Integer.MAX_VALUE;
+}
+DEFAULT_ALLOCATION_CUTOFF_VALUE = cutOffValue;
+  }
+
   private static final PooledByteBufAllocatorL INNER_ALLOCATOR = new 
PooledByteBufAllocatorL();
   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;
+
+  /**
+   * The cut-off value for switching allocation strategies.
+   */
+  private final long allocationCutOffValue;
 
-  NettyAllocationManager(BaseAllocator accountingAllocator, int requestedSize) 
{
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize, long allocationCutOffValue) {
 super(accountingAllocator);
-this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
-this.allocatedSize = memoryChunk.capacity();
+if (allocationCutOffValue > Integer.MAX_VALUE) {
+  throw new IllegalArgumentException("The cut-off value cannot be larger 
than Integer.MAX_VALUE");
+}
+this.allocationCutOffValue = allocationCutOffValue;
+
+if (requestedSize > allocationCutOffValue) {
+  this.memoryChunk = null;
+  this.allocatedAddress = PlatformDependent.allocateMemory(requestedSize);
+  this.allocatedSize = requestedSize;
+} else {
+  this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
+  this.allocatedAddress = memoryChunk.memoryAddress();
+  this.allocatedSize = memoryChunk.capacity();
+}
+  }
+
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize) {
+this(accountingAllocator, requestedSize, DEFAULT_ALLOCATION_CUTOFF_VALUE);
   }
 
   /**
* Get the underlying memory chunk managed by this AllocationManager.
-   * @return buffer
+   * @return the underlying memory chunk if the request size is not greater 
than the
+   *   {@link NettyAllocationManager#allocationCutOffValue}, or null otherwise.
+   *
+   * @deprecated this method will be removed in a future release.
*/
+  @Deprecated
   UnsafeDirectLittleEndian getMemoryChunk() {
-return memoryChunk;
+return allocatedSize > allocationCutOffValue ? null : memoryChunk;

Review comment:
   Sorry. This is not needed. Reverted.





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-25 Thread GitBox


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



##
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##
@@ -17,48 +17,97 @@
 
 package org.apache.arrow.memory;
 
-import org.apache.arrow.memory.util.LargeMemoryUtil;
-
 import io.netty.buffer.PooledByteBufAllocatorL;
 import io.netty.buffer.UnsafeDirectLittleEndian;
+import io.netty.util.internal.PlatformDependent;
 
 /**
- * The default implementation of AllocationManagerBase. The implementation is 
responsible for managing when memory
+ * The default implementation of {@link AllocationManager}. The implementation 
is responsible for managing when memory
  * is allocated and returned to the Netty-based PooledByteBufAllocatorL.
  */
 public class NettyAllocationManager extends AllocationManager {
 
   public static final Factory FACTORY = new Factory();
 
+  /**
+   * The default cut-off value for switching allocation strategies.
+   * If the request size is not greater than the cut-off value, we will 
allocate memory by
+   * {@link PooledByteBufAllocatorL} APIs,
+   * otherwise, we will use {@link PlatformDependent} APIs.
+   */
+  public static final long DEFAULT_ALLOCATION_CUTOFF_VALUE;
+
+  public static final String DEFAULT_ALLOCATION_CUTOFF_NAME = 
"default.allocation.cutoff.name";
+
+  static {
+long cutOffValue;
+try {
+  cutOffValue = 
Long.parseLong(System.getProperty(DEFAULT_ALLOCATION_CUTOFF_NAME));
+} catch (Exception e) {
+  cutOffValue = Integer.MAX_VALUE;
+}
+DEFAULT_ALLOCATION_CUTOFF_VALUE = cutOffValue;
+  }
+

Review comment:
   Removed. Thank you for the good suggestion. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-25 Thread GitBox


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



##
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
+ *Make sure there are 4GB memory available in the system.
+ * 
+ *   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}.
+ * 
+ */
+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) % 1 == 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) % 1 == 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:
   Yes, it needs to run manually. 
   I have updated the javadoc accordingly.





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-25 Thread GitBox


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



##
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##
@@ -17,48 +17,97 @@
 
 package org.apache.arrow.memory;
 
-import org.apache.arrow.memory.util.LargeMemoryUtil;
-
 import io.netty.buffer.PooledByteBufAllocatorL;
 import io.netty.buffer.UnsafeDirectLittleEndian;
+import io.netty.util.internal.PlatformDependent;
 
 /**
- * The default implementation of AllocationManagerBase. The implementation is 
responsible for managing when memory
+ * The default implementation of {@link AllocationManager}. The implementation 
is responsible for managing when memory
  * is allocated and returned to the Netty-based PooledByteBufAllocatorL.
  */
 public class NettyAllocationManager extends AllocationManager {
 
   public static final Factory FACTORY = new Factory();
 
+  /**
+   * The default cut-off value for switching allocation strategies.
+   * If the request size is not greater than the cut-off value, we will 
allocate memory by
+   * {@link PooledByteBufAllocatorL} APIs,
+   * otherwise, we will use {@link PlatformDependent} APIs.
+   */
+  public static final long DEFAULT_ALLOCATION_CUTOFF_VALUE;
+
+  public static final String DEFAULT_ALLOCATION_CUTOFF_NAME = 
"default.allocation.cutoff.name";
+
+  static {
+long cutOffValue;
+try {
+  cutOffValue = 
Long.parseLong(System.getProperty(DEFAULT_ALLOCATION_CUTOFF_NAME));
+} catch (Exception e) {
+  cutOffValue = Integer.MAX_VALUE;
+}
+DEFAULT_ALLOCATION_CUTOFF_VALUE = cutOffValue;
+  }
+
   private static final PooledByteBufAllocatorL INNER_ALLOCATOR = new 
PooledByteBufAllocatorL();
   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;
+
+  /**
+   * The cut-off value for switching allocation strategies.
+   */
+  private final long allocationCutOffValue;

Review comment:
   Changed to int. Thanks for the good suggestion. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-25 Thread GitBox


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



##
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##
@@ -17,48 +17,97 @@
 
 package org.apache.arrow.memory;
 
-import org.apache.arrow.memory.util.LargeMemoryUtil;
-
 import io.netty.buffer.PooledByteBufAllocatorL;
 import io.netty.buffer.UnsafeDirectLittleEndian;
+import io.netty.util.internal.PlatformDependent;
 
 /**
- * The default implementation of AllocationManagerBase. The implementation is 
responsible for managing when memory
+ * The default implementation of {@link AllocationManager}. The implementation 
is responsible for managing when memory
  * is allocated and returned to the Netty-based PooledByteBufAllocatorL.
  */
 public class NettyAllocationManager extends AllocationManager {
 
   public static final Factory FACTORY = new Factory();
 
+  /**
+   * The default cut-off value for switching allocation strategies.
+   * If the request size is not greater than the cut-off value, we will 
allocate memory by
+   * {@link PooledByteBufAllocatorL} APIs,
+   * otherwise, we will use {@link PlatformDependent} APIs.
+   */
+  public static final long DEFAULT_ALLOCATION_CUTOFF_VALUE;
+
+  public static final String DEFAULT_ALLOCATION_CUTOFF_NAME = 
"default.allocation.cutoff.name";
+
+  static {
+long cutOffValue;
+try {
+  cutOffValue = 
Long.parseLong(System.getProperty(DEFAULT_ALLOCATION_CUTOFF_NAME));
+} catch (Exception e) {
+  cutOffValue = Integer.MAX_VALUE;
+}
+DEFAULT_ALLOCATION_CUTOFF_VALUE = cutOffValue;
+  }
+
   private static final PooledByteBufAllocatorL INNER_ALLOCATOR = new 
PooledByteBufAllocatorL();
   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;
+
+  /**
+   * The cut-off value for switching allocation strategies.
+   */
+  private final long allocationCutOffValue;
 
-  NettyAllocationManager(BaseAllocator accountingAllocator, int requestedSize) 
{
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize, long allocationCutOffValue) {
 super(accountingAllocator);
-this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
-this.allocatedSize = memoryChunk.capacity();
+if (allocationCutOffValue > Integer.MAX_VALUE) {
+  throw new IllegalArgumentException("The cut-off value cannot be larger 
than Integer.MAX_VALUE");
+}
+this.allocationCutOffValue = allocationCutOffValue;
+
+if (requestedSize > allocationCutOffValue) {
+  this.memoryChunk = null;
+  this.allocatedAddress = PlatformDependent.allocateMemory(requestedSize);
+  this.allocatedSize = requestedSize;
+} else {
+  this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);
+  this.allocatedAddress = memoryChunk.memoryAddress();
+  this.allocatedSize = memoryChunk.capacity();
+}
+  }
+
+  NettyAllocationManager(BaseAllocator accountingAllocator, long 
requestedSize) {
+this(accountingAllocator, requestedSize, DEFAULT_ALLOCATION_CUTOFF_VALUE);
   }
 
   /**
* Get the underlying memory chunk managed by this AllocationManager.
-   * @return buffer
+   * @return the underlying memory chunk if the request size is not greater 
than the
+   *   {@link NettyAllocationManager#allocationCutOffValue}, or null otherwise.
+   *
+   * @deprecated this method will be removed in a future release.
*/
+  @Deprecated
   UnsafeDirectLittleEndian getMemoryChunk() {
-return memoryChunk;
+return allocatedSize > allocationCutOffValue ? null : memoryChunk;
   }
 
   @Override
   protected long memoryAddress() {
-return memoryChunk.memoryAddress();
+return allocatedAddress;
   }
 
   @Override
   protected void release0() {
-memoryChunk.release();
+if (allocatedSize > allocationCutOffValue) {

Review comment:
   Revised accordingly. Thank you.





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-23 Thread GitBox


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



##
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
+ *Make sure there are 4GB memory available in the system.
+ * 
+ *   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}.
+ * 
+ */
+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) % 1 == 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) % 1 == 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:
   Sounds good. 
   I have revised the code to make the cut-off value configurable, and added 
cases to test the scenarios when the request size is below/above the cut-off 
value. Please see if it looks good to you. Thanks. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-23 Thread GitBox


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



##
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:
   Revised accordingly. Thank you. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-23 Thread GitBox


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



##
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:
   Sure. Revised. Please check. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-23 Thread GitBox


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



##
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:
   Sounds good. Reverted this accordingly. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-21 Thread GitBox


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



##
File path: 
java/vector/src/test/java/org/apache/arrow/vector/TestLargeVector.java
##
@@ -0,0 +1,187 @@
+/*
+ * 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 static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+
+import io.netty.buffer.ArrowBuf;
+
+/**
+ * Integration test for a vector with a large (more than 2GB) {@link 
io.netty.buffer.ArrowBuf} as
+ * the data buffer.
+ * To run this test, please
+ *Make sure there are 4GB memory available in the system.
+ * 
+ *   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}.
+ * 
+ */
+public class TestLargeVector {
+  private static void testLargeLongVector() {
+System.out.println("Testing large big int vector.");
+
+final long bufSize = 4 * 1024 * 1024 * 1024L;
+final int vecLength = (int) (bufSize / BigIntVector.TYPE_WIDTH);
+
+try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
+BigIntVector largeVec = new BigIntVector("vec", allocator)) {
+  largeVec.allocateNew(vecLength);
+
+  System.out.println("Successfully allocated a vector with capacity " + 
vecLength);
+
+  for (int i = 0; i < vecLength; i++) {
+largeVec.set(i, i * 10L);
+
+if ((i + 1) % 1 == 0) {
+  System.out.println("Successfully written " + (i + 1) + " values");
+}
+  }
+  System.out.println("Successfully written " + vecLength + " values");
+
+  for (int i = 0; i < vecLength; i++) {
+long val = largeVec.get(i);
+assertEquals(i * 10L, val);
+
+if ((i + 1) % 1 == 0) {
+  System.out.println("Successfully read " + (i + 1) + " values");
+}
+  }
+  System.out.println("Successfully read " + vecLength + " values");
+}
+System.out.println("Successfully released the large vector.");
+  }
+
+  private static void testLargeIntVector() {
+System.out.println("Testing large int vector.");
+
+final long bufSize = 4 * 1024 * 1024 * 1024L;
+final int vecLength = (int) (bufSize / IntVector.TYPE_WIDTH);
+
+try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
+ IntVector largeVec = new IntVector("vec", allocator)) {
+  largeVec.allocateNew(vecLength);
+
+  System.out.println("Successfully allocated a vector with capacity " + 
vecLength);
+
+  for (int i = 0; i < vecLength; i++) {
+largeVec.set(i, i);
+
+if ((i + 1) % 1 == 0) {
+  System.out.println("Successfully written " + (i + 1) + " values");
+}
+  }
+  System.out.println("Successfully written " + vecLength + " values");
+
+  for (int i = 0; i < vecLength; i++) {
+long val = largeVec.get(i);
+assertEquals(i, val);
+
+if ((i + 1) % 1 == 0) {
+  System.out.println("Successfully read " + (i + 1) + " values");
+}
+  }
+  System.out.println("Successfully read " + vecLength + " values");
+}
+System.out.println("Successfully released the large vector.");
+  }
+
+  private static void testLargeDecimalVector() {
+System.out.println("Testing large decimal vector.");
+
+final long bufSize = 4 * 1024 * 1024 * 1024L;
+final int vecLength = (int) (bufSize / DecimalVector.TYPE_WIDTH);
+
+try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
+ DecimalVector largeVec = new DecimalVector("vec", allocator, 38, 16)) 
{
+  largeVec.allocateNew(vecLength);
+
+  System.out.println("Successfully allocated a vector with capacity " + 
vecLength);
+
+  for (int i = 0; i < vecLength; i++) {
+largeVec.set(i, 0);
+
+if ((i + 1) % 1 == 0) {
+  System.out.println("Successfully written " + (i + 1) + " values");
+}
+  }
+  System.out.println("Successfully written " + 

[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-21 Thread GitBox


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



##
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
+ *Make sure there are 4GB memory available in the system.
+ * 
+ *   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}.
+ * 
+ */
+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) % 1 == 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) % 1 == 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:
   Sounds good to me. 
   The problem is that we set arrow.vector.max_allocation_bytes to 1048576 for 
every test case (to avoid OOM).  Please see the pom.xml file. 
   
   So if we convert it to a test case, we cannot allocate too much memory. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-21 Thread GitBox


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



##
File path: 
java/vector/src/test/java/org/apache/arrow/vector/TestLargeVector.java
##
@@ -0,0 +1,187 @@
+/*
+ * 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 static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.arrow.memory.BufferAllocator;
+import org.apache.arrow.memory.RootAllocator;
+
+import io.netty.buffer.ArrowBuf;
+
+/**
+ * Integration test for a vector with a large (more than 2GB) {@link 
io.netty.buffer.ArrowBuf} as
+ * the data buffer.
+ * To run this test, please
+ *Make sure there are 4GB memory available in the system.
+ * 
+ *   Make sure the default allocation manager type is unsafe.

Review comment:
   Revised. Thank you.





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-21 Thread GitBox


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



##
File path: 
java/memory/src/main/java/org/apache/arrow/memory/NettyAllocationManager.java
##
@@ -34,31 +33,24 @@
   static final UnsafeDirectLittleEndian EMPTY = INNER_ALLOCATOR.empty;
   static final long CHUNK_SIZE = INNER_ALLOCATOR.getChunkSize();
 
-  private final int allocatedSize;
-  private final UnsafeDirectLittleEndian memoryChunk;
+  private final long allocatedSize;
 
-  NettyAllocationManager(BaseAllocator accountingAllocator, int requestedSize) 
{
-super(accountingAllocator);
-this.memoryChunk = INNER_ALLOCATOR.allocate(requestedSize);

Review comment:
   Revised. Thank you for the good suggestion. 





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




[GitHub] [arrow] liyafan82 commented on a change in pull request #6323: ARROW-7610: [Java] Finish support for 64 bit int allocations

2020-04-21 Thread GitBox


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



##
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
+ *Make sure there are 4GB memory available in the system.
+ * 
+ *   Make sure the default allocation manager type is unsafe.

Review comment:
   Nice catch. Thank you. 





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