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
12 changes: 10 additions & 2 deletions java/adapter/avro/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@

<dependencies>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory -->
<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory-core -->
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory</artifactId>
<artifactId>arrow-memory-core</artifactId>
<version>${project.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory-netty -->
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory-netty</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-vector -->
<dependency>
<groupId>org.apache.arrow</groupId>
Expand Down
12 changes: 10 additions & 2 deletions java/adapter/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,21 @@

<dependencies>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory -->
<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory-core -->
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory</artifactId>
<artifactId>arrow-memory-core</artifactId>
<version>${project.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-memory-netty -->
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory-netty</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.arrow/arrow-vector -->
<dependency>
<groupId>org.apache.arrow</groupId>
Expand Down
8 changes: 7 additions & 1 deletion java/adapter/orc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@
<dependencies>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory</artifactId>
<artifactId>arrow-memory-core</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory-netty</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-vector</artifactId>
Expand Down
8 changes: 7 additions & 1 deletion java/algorithm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory</artifactId>
<artifactId>arrow-memory-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory-netty</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-common</artifactId>
Expand Down
8 changes: 7 additions & 1 deletion java/flight/flight-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,15 @@
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory</artifactId>
<artifactId>arrow-memory-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory-netty</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
Expand Down
12 changes: 9 additions & 3 deletions java/flight/flight-grpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,17 @@
<artifactId>grpc-stub</artifactId>
<version>${dep.grpc.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory-core</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory</artifactId>
<artifactId>arrow-memory-netty</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
Expand Down
8 changes: 7 additions & 1 deletion java/gandiva/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,15 @@
<dependencies>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory</artifactId>
<artifactId>arrow-memory-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-memory-netty</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.arrow</groupId>
<artifactId>arrow-vector</artifactId>
Expand Down
60 changes: 60 additions & 0 deletions java/memory/memory-core/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- 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. -->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>arrow-memory</artifactId>
<groupId>org.apache.arrow</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>arrow-memory-core</artifactId>

<name>Arrow Memory - Core</name>
<description>Core off-heap memory management libraries for Arrow ValueVectors.</description>

<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.immutables</groupId>
<artifactId>value</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<enableAssertions>true</enableAssertions>
<childDelegation>true</childDelegation>
<forkCount>${forkCount}</forkCount>
<reuseForks>true</reuseForks>
<systemPropertyVariables>
<java.io.tmpdir>${project.build.directory}</java.io.tmpdir>
<user.timezone>UTC</user.timezone>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ private static URL assertOnlyOne(Set<URL> urls) {
logger.warn("More than one DefaultAllocationManager on classpath. Choosing first found");
}
if (urls.isEmpty()) {
throw new RuntimeException("No DefaultAllocationManager found on classpath. Can't allocate Arrow buffers.");
throw new RuntimeException("No DefaultAllocationManager found on classpath. Can't allocate Arrow buffers." +
" Please consider adding arrow-memory-netty or arrow-memory-unsafe as a dependency.");
}
return urls.iterator().next();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,20 @@ private static AllocationManager.Factory getFactory(String clazzName) {
}

private static AllocationManager.Factory getUnsafeFactory() {
return getFactory("org.apache.arrow.memory.UnsafeAllocationManager");
try {
return getFactory("org.apache.arrow.memory.UnsafeAllocationManager");
} catch (RuntimeException e) {
throw new RuntimeException("Please add arrow-memory-unsafe to your classpath," +
" No DefaultAllocationManager found to instantiate an UnsafeAllocationManager", e);
}
}

private static AllocationManager.Factory getNettyFactory() {
return getFactory("org.apache.arrow.memory.NettyAllocationManager");
try {
return getFactory("org.apache.arrow.memory.NettyAllocationManager");
} catch (RuntimeException e) {
throw new RuntimeException("Please add arrow-memory-netty to your classpath," +
" No DefaultAllocationManager found to instantiate an NettyAllocationManager", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.util.internal.SystemPropertyUtil;

/**
* The default rounding policy. That is, if the requested size is within the chunk size,
* the rounded size will be the next power of two. Otherwise, the rounded size
Expand All @@ -45,7 +43,7 @@ public class DefaultRoundingPolicy implements RoundingPolicy {


static {
int defaultPageSize = SystemPropertyUtil.getInt("org.apache.memory.allocator.pageSize", 8192);
int defaultPageSize = Integer.getInteger("org.apache.memory.allocator.pageSize", 8192);
Throwable pageSizeFallbackCause = null;
try {
validateAndCalculatePageShifts(defaultPageSize);
Expand All @@ -54,7 +52,7 @@ public class DefaultRoundingPolicy implements RoundingPolicy {
defaultPageSize = 8192;
}

int defaultMaxOrder = SystemPropertyUtil.getInt("org.apache.memory.allocator.maxOrder", 11);
int defaultMaxOrder = Integer.getInteger("org.apache.memory.allocator.maxOrder", 11);
Throwable maxOrderFallbackCause = null;
try {
validateAndCalculateChunkSize(defaultPageSize, defaultMaxOrder);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* 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 org.apache.arrow.memory.util.MemoryUtil;

/**
* The default Allocation Manager Factory for a module.
*
* This is only used by tests and contains only a simplistic allocator method.
*
*/
public class DefaultAllocationManagerFactory implements AllocationManager.Factory {
Copy link
Contributor

Choose a reason for hiding this comment

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

We have 3 classes in the code base named "DefaultAllocationManagerFactory". Do we need all of them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @liyafan82, yes i think we do:

  1. lives in the netty module.
  2. lives in the unsafe module
  3. lives in the tests portion of the core memory module.

On startup we first check if a specific memory allocator has been requested. If yes we instantiate that. If no specific impl has been requested then we search the classpath for a DefaultAllocationManagerFactory. If we find one then we instantiate it, else we throw a Runtime exception (can't continue without an allocation manager).

So each concrete impl of AllocationManager requires a factory to create it and we have a trivial allocation manager in arrow-memory-core tests to help the core tests finish.


public static final AllocationManager.Factory FACTORY = new DefaultAllocationManagerFactory();
private static final ArrowBuf EMPTY = new ArrowBuf(ReferenceManager.NO_OP,
null,
0,
MemoryUtil.UNSAFE.allocateMemory(0));

@Override
public AllocationManager create(BaseAllocator accountingAllocator, long size) {
return new AllocationManager(accountingAllocator) {
private final long allocatedSize = size;
private final long address = MemoryUtil.UNSAFE.allocateMemory(size);

@Override
public long getSize() {
return allocatedSize;
}

@Override
protected long memoryAddress() {
return address;
}

@Override
protected void release0() {
MemoryUtil.UNSAFE.freeMemory(address);
}
};
}

@Override
public ArrowBuf empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this is a frequently called method, I think it would be beneficial to reuse the empty ArrowBuf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only in tests, but I agree. Fixed

return EMPTY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,11 @@ public class TestAllocationManager {

@Test
public void testAllocationManagerType() {
// test netty allocation manager type
System.setProperty(
DefaultAllocationManagerOption.ALLOCATION_MANAGER_TYPE_PROPERTY_NAME, "Netty");
DefaultAllocationManagerOption.AllocationManagerType mgrType =
DefaultAllocationManagerOption.getDefaultAllocationManagerType();

assertEquals(DefaultAllocationManagerOption.AllocationManagerType.Netty, mgrType);

// test unsafe allocation manager type
System.setProperty(
DefaultAllocationManagerOption.ALLOCATION_MANAGER_TYPE_PROPERTY_NAME, "Unsafe");
mgrType = DefaultAllocationManagerOption.getDefaultAllocationManagerType();

assertEquals(DefaultAllocationManagerOption.AllocationManagerType.Unsafe, mgrType);

// test unknown allocation manager type
System.clearProperty(DefaultAllocationManagerOption.ALLOCATION_MANAGER_TYPE_PROPERTY_NAME);
mgrType = DefaultAllocationManagerOption.getDefaultAllocationManagerType();
DefaultAllocationManagerOption.AllocationManagerType mgrType =
DefaultAllocationManagerOption.getDefaultAllocationManagerType();

assertEquals(DefaultAllocationManagerOption.AllocationManagerType.Unknown, mgrType);
}
Expand Down
Loading