You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/04/20 16:26:31 UTC

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

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



##########
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:
       I don't think we should remove this which effectively replaces all allocations done in Arrow Java, which is a big change. `INNER_ALLOCATOR` also uses a pool which has some benefits. Instead, can you just change `requestedSize` to be a long, then check if it is over the max Int size and only then use `PlatformDependent.allocateMemory`?

##########
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.

Review comment:
       please update

##########
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:
       Can this be converted to a standard unit test now?

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

Review comment:
       update

##########
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
+ *<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 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) % 10000 == 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) % 10000 == 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) % 10000 == 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) % 10000 == 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) % 10000 == 0) {
+          System.out.println("Successfully written " + (i + 1) + " values");
+        }
+      }
+      System.out.println("Successfully written " + vecLength + " values");
+
+      for (int i = 0; i < vecLength; i++) {
+        ArrowBuf buf = largeVec.get(i);
+        assertEquals(buf.capacity(), DecimalVector.TYPE_WIDTH);
+        assertEquals(0, buf.getLong(0));
+        assertEquals(0, buf.getLong(8));
+
+        if ((i + 1) % 10000 == 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 testLargeFixedSizeBinaryVector() {
+    System.out.println("Testing large fixed size binary vector.");
+
+    final long bufSize = 4 * 1024 * 1024 * 1024L;
+    final int typeWidth = 8;
+    final int vecLength = (int) (bufSize / typeWidth);
+
+    try (BufferAllocator allocator = new RootAllocator(Long.MAX_VALUE);
+         FixedSizeBinaryVector largeVec = new FixedSizeBinaryVector("vec", allocator, typeWidth)) {
+      largeVec.allocateNew(vecLength);
+
+      System.out.println("Successfully allocated a vector with capacity " + vecLength);
+
+      byte[] value = new byte[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'};
+      for (int i = 0; i < vecLength; i++) {
+        largeVec.set(i, value);
+
+        if ((i + 1) % 10000 == 0) {
+          System.out.println("Successfully written " + (i + 1) + " values");
+        }
+      }
+      System.out.println("Successfully written " + vecLength + " values");
+
+      for (int i = 0; i < vecLength; i++) {
+        byte[] buf = largeVec.get(i);
+        assertEquals(typeWidth, buf.length);
+        assertArrayEquals(buf, value);
+
+        if ((i + 1) % 10000 == 0) {
+          System.out.println("Successfully read " + (i + 1) + " values");
+        }
+      }
+      System.out.println("Successfully read " + vecLength + " values");
+    }
+    System.out.println("Successfully released the large vector.");
+  }
+
+  public static void main(String[] args) {

Review comment:
       same here about making these standard unit 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:
users@infra.apache.org