Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
BP-47 (task1): Add native IO library support (#3189)
* Add native io library support * fix jni compile issue * fix findbugs failed
- Loading branch information
Showing
12 changed files
with
951 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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. | ||
*/ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
dependencies { | ||
compileOnly depLibs.lombok | ||
compileOnly depLibs.spotbugsAnnotations | ||
implementation depLibs.commonsLang3 | ||
implementation depLibs.guava | ||
implementation depLibs.slf4j | ||
testImplementation depLibs.junit | ||
|
||
annotationProcessor depLibs.lombok | ||
} | ||
|
||
compileJava { | ||
options.headerOutputDirectory = file("${buildDir}/javahGenerated") | ||
} | ||
|
||
jar { | ||
from (tasks.getByPath(":native-io:src:main:native-io-jni:linkRelease").outputs.files.filter { f -> f.isFile()} ) { | ||
into "/lib" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,220 @@ | ||
<!-- | ||
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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.bookkeeper</groupId> | ||
<artifactId>bookkeeper</artifactId> | ||
<version>4.16.0-SNAPSHOT</version> | ||
<relativePath>..</relativePath> | ||
</parent> | ||
|
||
<artifactId>native-io</artifactId> | ||
<packaging>nar</packaging> | ||
<name>Apache BookKeeper :: Native IO Library</name> | ||
<description>Native IO Library</description> | ||
|
||
<properties> | ||
<nar.runtime>dynamic</nar.runtime> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-lang3</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<compilerArgs> | ||
<!-- Object.finalize() is deprecated at java 9 --> | ||
<!-- <compilerArg>-Werror</compilerArg> --> | ||
<compilerArg>-Xlint:deprecation</compilerArg> | ||
<compilerArg>-Xlint:unchecked</compilerArg> | ||
<!-- https://issues.apache.org/jira/browse/MCOMPILER-205 --> | ||
<compilerArg>-Xpkginfo:always</compilerArg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>com.github.maven-nar</groupId> | ||
<artifactId>nar-maven-plugin</artifactId> | ||
<version>${nar-maven-plugin.version}</version> | ||
<extensions>true</extensions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<version>${maven-assembly-plugin.version}</version> | ||
<configuration> | ||
<descriptors> | ||
<descriptor>src/main/assembly/assembly.xml</descriptor> | ||
</descriptors> | ||
<appendAssemblyId>false</appendAssemblyId> | ||
<tarLongFileMode>posix</tarLongFileMode> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<id>make-assembly</id> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>single</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.rat</groupId> | ||
<artifactId>apache-rat-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<!-- from JDK10 javah command is not available | ||
see http://openjdk.java.net/jeps/313 | ||
--> | ||
<id>jdk-without-javah</id> | ||
<activation> | ||
<jdk>[10,)</jdk> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.maven-nar</groupId> | ||
<artifactId>nar-maven-plugin</artifactId> | ||
<version>${nar-maven-plugin.version}</version> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<!-- javah is not present in JDK10 onwards, | ||
you have to to use javac -h --> | ||
<id>default-nar-javah</id> | ||
<phase>none</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>${maven-compiler-plugin.version}</version> | ||
<configuration> | ||
<source>1.8</source> | ||
<target>1.8</target> | ||
<compilerArgs> | ||
<!-- Object.finalize() is deprecated at java 9 --> | ||
<!-- <compilerArg>-Werror</compilerArg> --> | ||
<compilerArg>-Xlint:deprecation</compilerArg> | ||
<compilerArg>-Xlint:unchecked</compilerArg> | ||
<!-- https://issues.apache.org/jira/browse/MCOMPILER-205 --> | ||
<compilerArg>-Xpkginfo:always</compilerArg> | ||
<!-- add -h flag to javac --> | ||
<compilerArg>-h</compilerArg> | ||
<compilerArg>${project.build.directory}/nar/javah-include</compilerArg> | ||
</compilerArgs> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>mac</id> | ||
<activation> | ||
<os> | ||
<name>Mac OS X</name> | ||
</os> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.maven-nar</groupId> | ||
<artifactId>nar-maven-plugin</artifactId> | ||
<version>${nar-maven-plugin.version}</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<runtime>${nar.runtime}</runtime> | ||
<output>native-io</output> | ||
<libraries> | ||
<library> | ||
<type>jni</type> | ||
<narSystemPackage>org.apache.bookkeeper.util.nativeio</narSystemPackage> | ||
</library> | ||
</libraries> | ||
<cpp> | ||
<optionSet>${nar.cpp.optionSet}</optionSet> | ||
<exceptions>false</exceptions> | ||
<rtti>false</rtti> | ||
<optimize>full</optimize> | ||
</cpp> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
|
||
<profile> | ||
<id>Linux</id> | ||
<activation> | ||
<os> | ||
<name>Linux</name> | ||
</os> | ||
</activation> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>com.github.maven-nar</groupId> | ||
<artifactId>nar-maven-plugin</artifactId> | ||
<version>${nar-maven-plugin.version}</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<runtime>${nar.runtime}</runtime> | ||
<output>native-io</output> | ||
<libraries> | ||
<library> | ||
<type>jni</type> | ||
<narSystemPackage>org.apache.bookkeeper.util.nativeio</narSystemPackage> | ||
</library> | ||
</libraries> | ||
<cpp> | ||
<optionSet>${nar.cpp.optionSet}</optionSet> | ||
<exceptions>false</exceptions> | ||
<rtti>false</rtti> | ||
<optimize>full</optimize> | ||
</cpp> | ||
<linker> | ||
<libSet>rt</libSet> | ||
</linker> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,62 @@ | ||
<?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. | ||
--> | ||
<assembly> | ||
<id>all</id> | ||
<formats> | ||
<format>jar</format> | ||
</formats> | ||
|
||
<includeBaseDirectory>false</includeBaseDirectory> | ||
<fileSets> | ||
<fileSet> | ||
<directory>${project.build.directory}/nar/${project.artifactId}-${project.version}-${os.arch}-MacOSX-gpp-jni/lib/${os.arch}-MacOSX-gpp/jni | ||
</directory> | ||
<outputDirectory>lib</outputDirectory> | ||
<includes> | ||
<include>lib*</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet> | ||
<directory>${project.build.directory}/nar/${project.artifactId}-${project.version}-${os.arch}-Linux-gpp-jni/lib/${os.arch}-Linux-gpp/jni | ||
</directory> | ||
<outputDirectory>lib</outputDirectory> | ||
<includes> | ||
<include>lib*</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet> | ||
<directory>${project.build.directory}/nar/${project.artifactId}-${project.version}-${os.arch}-${os.name}-gpp-jni/lib/${os.arch}-${os.name}-gpp/jni | ||
</directory> | ||
<outputDirectory>lib</outputDirectory> | ||
<includes> | ||
<include>lib*</include> | ||
</includes> | ||
</fileSet> | ||
<fileSet> | ||
<directory>${project.build.directory}/classes</directory> | ||
<outputDirectory></outputDirectory> | ||
<includes> | ||
<include>**/*</include> | ||
</includes> | ||
</fileSet> | ||
</fileSets> | ||
</assembly> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -0,0 +1,61 @@ | ||
/** | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.bookkeeper.common.util.nativeio; | ||
|
||
/** | ||
* NativeIO API. | ||
*/ | ||
public interface NativeIO { | ||
|
||
// These constants are different per each OS, so the correct values are defined in JNI code | ||
int O_CREAT = 0x01; | ||
int O_RDONLY = 0x02; | ||
int O_WRONLY = 0x04; | ||
int O_TRUNC = 0x08; | ||
int O_DIRECT = 0x10; | ||
int O_DSYNC = 0x20; | ||
|
||
int SEEK_SET = 0; | ||
int SEEK_END = 2; | ||
|
||
int FALLOC_FL_ZERO_RANGE = 0x10; | ||
|
||
int open(String pathname, int flags, int mode) throws NativeIOException; | ||
|
||
int fsync(int fd) throws NativeIOException; | ||
|
||
/** | ||
* fallocate is a linux-only syscall, so callers must handle the possibility that it does | ||
* not exist. | ||
*/ | ||
int fallocate(int fd, int mode, long offset, long len) throws NativeIOException; | ||
|
||
int pwrite(int fd, long pointer, int count, long offset) throws NativeIOException; | ||
|
||
long posix_memalign(int alignment, int size) throws NativeIOException; | ||
|
||
void free(long pointer) throws NativeIOException; | ||
|
||
long lseek(int fd, long offset, int whence) throws NativeIOException; | ||
|
||
long pread(int fd, long pointer, long size, long offset) throws NativeIOException; | ||
|
||
int close(int fd) throws NativeIOException; | ||
} |
Oops, something went wrong.