Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build RocksDB JNI cross-platform fat jar #318

Merged
merged 28 commits into from
Oct 7, 2014
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9db1398
Update RocksDB's Java bindings to support multiple native RocksDB bui…
Sep 26, 2014
82a8f43
Document RELEASE.mdgit status
Sep 26, 2014
4e735bb
Rsync files to VM rather than sync folders, since sync folders was ca…
Sep 26, 2014
b8e2661
since we're not sharing folders with the vm, copy built .so files and…
Sep 27, 2014
c4519c7
fix mis-named jar in JNI loader
Sep 29, 2014
6a64ea6
add note about java 7
Sep 29, 2014
0b923f0
add centos 5.6 build instead of ubuntu.
Sep 29, 2014
a2f98ef
fix tabs in Makefile
Sep 30, 2014
726ac5b
shrink vagrant commands to single line
Sep 30, 2014
3a0d498
rebase master
Sep 30, 2014
d0916f4
add major minor micro version to java jars
Oct 2, 2014
fd2545c
add maven publication target and instructions
Oct 2, 2014
deefcf4
make fat jar unclassified to satisfy sonatype
Oct 2, 2014
df08a2d
add single rocksdbjni pom
Oct 2, 2014
2e80124
add javadoc and sources targets for sonatype
Oct 2, 2014
8322cf0
use javadoc instead of javadocs
Oct 2, 2014
2d72f78
update release docs in java
Oct 2, 2014
2a1add6
use proper major/minor/micro version rather than hard coding 3.5.0
Oct 2, 2014
c832f16
add not about updating pom version and rename pom to be unversioned
Oct 2, 2014
a1d3f0d
don't fail if javadocs diretory doesn't exist
Oct 2, 2014
378f321
merge master to resolve merge conflicts
Oct 2, 2014
45d526e
singular javadoc directory
Oct 2, 2014
99744e0
bump version to 3.6
Oct 2, 2014
e869fc6
remove proper javadoc directory
Oct 2, 2014
6b2c1d9
make publish jni jars depend on release jni jars
Oct 6, 2014
2a4d6e7
merge master to resolve merge conflicts
Oct 6, 2014
d44871e
fix java doc directory in git ignore
Oct 6, 2014
1e5a528
update release readme
Oct 6, 2014
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ tags
java/*.log
java/include/org_rocksdb_*.h
unity.cc
java/crossbuild/.vagrant
.vagrant/
java/**.asc
java/javadocs
31 changes: 27 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ endif
LIBRARY = ${LIBNAME}.a
MEMENVLIBRARY = libmemenv.a

ROCKSDB_MAJOR = $(shell egrep "ROCKSDB_MAJOR.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)
ROCKSDB_MINOR = $(shell egrep "ROCKSDB_MINOR.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)
ROCKSDB_PATCH = $(shell egrep "ROCKSDB_PATCH.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)

default: all

#-----------------------------------------------
Expand Down Expand Up @@ -273,6 +277,7 @@ clean:
-rm -rf ios-x86/* ios-arm/*
-find . -name "*.[oda]" -exec rm {} \;
-find . -type f -regex ".*\.\(\(gcda\)\|\(gcno\)\)" -exec rm {} \;
-rm -rf bzip2* snappy* zlib*
tags:
ctags * -R
cscope -b `find . -name '*.cc'` `find . -name '*.h'`
Expand Down Expand Up @@ -513,11 +518,16 @@ ldb: tools/ldb.o $(LIBOBJECTS)

JNI_NATIVE_SOURCES = ./java/rocksjni/*.cc
JAVA_INCLUDE = -I$(JAVA_HOME)/include/ -I$(JAVA_HOME)/include/linux
ROCKSDBJNILIB = librocksdbjni.so
ROCKSDB_JAR = rocksdbjni.jar
ARCH := $(shell getconf LONG_BIT)
ROCKSDBJNILIB = librocksdbjni-linux$(ARCH).so
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-linux$(ARCH).jar
ROCKSDB_JAR_ALL = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH).jar
ROCKSDB_JAVADOCS_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-javadoc.jar
ROCKSDB_SOURCES_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-sources.jar

ifeq ($(PLATFORM), OS_MACOSX)
ROCKSDBJNILIB = librocksdbjni.jnilib
ROCKSDBJNILIB = librocksdbjni-osx.jnilib
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar
JAVA_INCLUDE = -I/System/Library/Frameworks/JavaVM.framework/Headers/
endif

Expand Down Expand Up @@ -550,7 +560,20 @@ rocksdbjavastatic: libz.a libbz2.a libsnappy.a
rm -f ./java/$(ROCKSDBJNILIB)
$(CXX) $(CXXFLAGS) -I./java/. $(JAVA_INCLUDE) -shared -fPIC -o ./java/$(ROCKSDBJNILIB) $(JNI_NATIVE_SOURCES) $(LIBOBJECTS) $(COVERAGEFLAGS) libz.a libbz2.a libsnappy.a
cd java;jar -cf $(ROCKSDB_JAR) org/rocksdb/*.class org/rocksdb/util/*.class HISTORY*.md $(ROCKSDBJNILIB)

cd java/javadoc;jar -cf ../$(ROCKSDB_JAVADOCS_JAR) *
cd java;jar -cf $(ROCKSDB_SOURCES_JAR) org

rocksdbjavastaticrelease: rocksdbjavastatic
cd java/crossbuild && vagrant destroy -f && vagrant up linux32 && vagrant halt linux32 && vagrant up linux64 && vagrant halt linux64
cd java;jar -cf $(ROCKSDB_JAR_ALL) org/rocksdb/*.class org/rocksdb/util/*.class HISTORY*.md librocksdbjni-*.so librocksdbjni-*.jnilib

rocksdbjavastaticpublish:
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this depend on rocksdbjavastaticrelease?

mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=java/rocksjni.pom -Dfile=java/rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-javadoc.jar -Dclassifier=javadoc
mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=java/rocksjni.pom -Dfile=java/rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-sources.jar -Dclassifier=sources
mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=java/rocksjni.pom -Dfile=java/rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-linux64.jar -Dclassifier=linux64
mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=java/rocksjni.pom -Dfile=java/rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-linux32.jar -Dclassifier=linux32
mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=java/rocksjni.pom -Dfile=java/rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar -Dclassifier=osx
mvn gpg:sign-and-deploy-file -Durl=https://oss.sonatype.org/service/local/staging/deploy/maven2/ -DrepositoryId=sonatype-nexus-staging -DpomFile=java/rocksjni.pom -Dfile=java/rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH).jar

rocksdbjava:
OPT="-fPIC -DNDEBUG -O2" $(MAKE) $(LIBRARY) -j32
Expand Down
18 changes: 15 additions & 3 deletions java/Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.BackupableDB org.rocksdb.BackupableDBOptions org.rocksdb.Statistics org.rocksdb.RocksIterator org.rocksdb.VectorMemTableConfig org.rocksdb.SkipListMemTableConfig org.rocksdb.HashLinkedListMemTableConfig org.rocksdb.HashSkipListMemTableConfig org.rocksdb.PlainTableConfig org.rocksdb.BlockBasedTableConfig org.rocksdb.ReadOptions org.rocksdb.Filter org.rocksdb.BloomFilter org.rocksdb.RestoreOptions org.rocksdb.RestoreBackupableDB org.rocksdb.RocksEnv org.rocksdb.GenericRateLimiterConfig

ROCKSDB_MAJOR = $(shell egrep "ROCKSDB_MAJOR.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)
ROCKSDB_MINOR = $(shell egrep "ROCKSDB_MINOR.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)
ROCKSDB_PATCH = $(shell egrep "ROCKSDB_PATCH.[0-9]" include/rocksdb/version.h | cut -d ' ' -f 3)

NATIVE_INCLUDE = ./include
ROCKSDB_JAR = rocksdbjni.jar
ARCH := $(shell getconf LONG_BIT)
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-linux$(ARCH).jar

ifeq ($(PLATFORM), OS_MACOSX)
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar
endif

clean:
-find . -name "*.class" -exec rm {} \;
-find . -name "hs*.log" -exec rm {} \;
rm -f $(ROCKSDB_JAR)
rm -rf javadoc/*

javadocs:
mkdir -p javadoc; javadoc -d javadoc -sourcepath . -subpackages org

java:
java: javadocs
javac org/rocksdb/util/*.java org/rocksdb/*.java
@cp ../HISTORY.md ./HISTORY-CPP.md
@rm -f ./HISTORY-CPP.md
Expand Down
60 changes: 60 additions & 0 deletions java/RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## Cross-building

RocksDB can be built as a single self contained cross-platform JAR. The cross-platform jar can be usd on any 64-bit OSX system, 32-bit Linux system, or 64-bit Linux system.

Building a cross-platform JAR requires:

* [Vagrant](https://www.vagrantup.com/)
* [Virtualbox](https://www.virtualbox.org/)
* A Mac OSX machine that can compile RocksDB.
* Java 7 set as JAVA_HOME.

Once you have these items, run this make command from RocksDB's root source directory:

make jclean clean rocksdbjavastaticrelease

This command will build RocksDB natively on OSX, and will then spin up two Vagrant Virtualbox Ubuntu images to build RocksDB for both 32-bit and 64-bit Linux.

You can find all native binaries and JARs in the java directory upon completion:

librocksdbjni-linux32.so
librocksdbjni-linux64.so
librocksdbjni-osx.jnilib
rocksdbjni-3.5.0-javadoc.jar
rocksdbjni-3.5.0-linux32.jar
rocksdbjni-3.5.0-linux64.jar
rocksdbjni-3.5.0-osx.jar
rocksdbjni-3.5.0-sources.jar
rocksdbjni-3.5.0.jar

## Maven publication

Set ~/.m2/settings.xml to contain:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>sonatype-nexus-staging</id>
<username>your-sonatype-jira-username</username>
<password>your-sonatype-jira-password</password>
</server>
</servers>
</settings>

Then update rocksjni.pom's version tag to reflect the release version.

From RocksDB's root directory, first build the Java static JARs:

make jclean clean rocksdbjavastaticrelease

Then publish the release to Sonatype:

make rocksdbjavastaticpublish

This command will [stage the JAR artifacts on the Sonatype staging repository](http://central.sonatype.org/pages/manual-staging-bundle-creation-and-deployment.html). To release the staged artifacts.

1. Go to [https://oss.sonatype.org/#stagingRepositories](https://oss.sonatype.org/#stagingRepositories) and search for "rocksdb" in the upper right hand search box.
2. Select the rocksdb staging repository, and inspect its contents.
3. If all is well, follow [these steps](https://oss.sonatype.org/#stagingRepositories) to close the repository and release it.

After the release has occurred, the artifacts will be synced to Maven central within 24-48 hours.
25 changes: 25 additions & 0 deletions java/crossbuild/Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.define "linux32" do |linux32|
linux32.vm.box = "hansode/centos-5.6-i386"
end

config.vm.define "linux64" do |linux64|
linux64.vm.box = "hansode/centos-5.6-x86_64"
end

config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 4
end

config.vm.provision :shell, path: "build-linux-centos.sh"
config.vm.synced_folder "../", "/rocksdb-build"
config.vm.synced_folder "../..", "/rocksdb", type: "rsync"
end
23 changes: 23 additions & 0 deletions java/crossbuild/build-linux-centos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# install all required packages for rocksdb that are available through yum
ARCH=$(uname -i)
sudo yum -y install java-1.6.0-openjdk-devel.$ARCH zlib zlib-devel bzip2 bzip2-devel

# install gcc/g++ 4.7 via CERN (http://linux.web.cern.ch/linux/devtoolset/)
sudo wget -O /etc/yum.repos.d/slc5-devtoolset.repo http://linuxsoft.cern.ch/cern/devtoolset/slc5-devtoolset.repo
sudo wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-cern http://ftp.mirrorservice.org/sites/ftp.scientificlinux.org/linux/scientific/51/i386/RPM-GPG-KEYs/RPM-GPG-KEY-cern
sudo yum -y install devtoolset-1.1
wget http://gflags.googlecode.com/files/gflags-1.6.tar.gz
tar xvfz gflags-1.6.tar.gz; cd gflags-1.6; scl enable devtoolset-1.1 ./configure; scl enable devtoolset-1.1 make; sudo make install
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

# set java home so we can build rocksdb jars
export JAVA_HOME=/usr/lib/jvm/java-1.6.0

# build rocksdb
cd /rocksdb
scl enable devtoolset-1.1 'make jclean clean'
scl enable devtoolset-1.1 'make -j 4 rocksdbjavastatic'
cp /rocksdb/java/librocksdbjni-* /rocksdb-build
cp /rocksdb/java/rocksdbjni-* /rocksdb-build

14 changes: 14 additions & 0 deletions java/crossbuild/build-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash
# install all required packages for rocksdb
sudo apt-get update
sudo apt-get -y install git make gcc g++ libgflags-dev libsnappy-dev zlib1g-dev libbz2-dev default-jdk

# set java home so we can build rocksdb jars
export JAVA_HOME=$(echo /usr/lib/jvm/java-7-openjdk*)
cd /rocksdb
make jclean clean
make -j 4 rocksdbjavastatic
cp /rocksdb/java/librocksdbjni-* /rocksdb-build
cp /rocksdb/java/rocksdbjni-* /rocksdb-build
sudo shutdown -h now

6 changes: 3 additions & 3 deletions java/org/rocksdb/NativeLibraryLoader.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package org.rocksdb;

import java.io.*;

import org.rocksdb.util.Environment;

/**
* This class is used to load the RocksDB shared library from within the jar.
* The shared library is extracted to a temp folder and loaded from there.
*/
public class NativeLibraryLoader {
private static String sharedLibraryName = "librocksdbjni.so";
private static String sharedLibraryName = Environment.getJniLibraryName("rocksdb");
private static String tempFilePrefix = "librocksdbjni";
private static String tempFileSuffix = ".so";
private static String tempFileSuffix = "." + Environment.getJniLibraryExtension();

public static void loadLibraryFromJar(String tmpDir)
throws IOException {
Expand Down
18 changes: 14 additions & 4 deletions java/org/rocksdb/util/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class Environment {
private static String OS = System.getProperty("os.name").toLowerCase();
private static String ARCH = System.getProperty("os.arch").toLowerCase();

public static boolean isWindows() {
return (OS.indexOf("win") >= 0);
Expand All @@ -17,21 +18,30 @@ public static boolean isUnix() {
OS.indexOf("aix") >= 0);
}

public static boolean is64Bit() {
return (ARCH.indexOf("64") > 0);
}

public static String getSharedLibraryName(String name) {
if (isUnix()) {
return String.format("lib%s.so", name);
return String.format("lib%sjni.so", name);
} else if (isMac()) {
return String.format("lib%s.dylib", name);
return String.format("lib%sjni.dylib", name);
}
throw new UnsupportedOperationException();
}

public static String getJniLibraryName(String name) {
if (isUnix()) {
return String.format("lib%s.so", name);
String arch = (is64Bit()) ? "64" : "32";
return String.format("lib%sjni-linux%s.so", name, arch);
} else if (isMac()) {
return String.format("lib%s.jnilib", name);
return String.format("lib%sjni-osx.jnilib", name);
}
throw new UnsupportedOperationException();
}

public static String getJniLibraryExtension() {
return (isMac()) ? ".jnilib" : ".so";
}
}
34 changes: 34 additions & 0 deletions java/rocksjni.pom
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<name>RocksDB JNI</name>
<url>http://rocksdb.org/</url>
<groupId>org.rocksdb</groupId>
<artifactId>rocksdbjni</artifactId>
<version>3.6.0</version>
<description>RocksDB fat jar that contains .so files for linux32 and linux64, and jnilib files for Mac OSX.</description>
<licenses>
<license>
<name>Apache License 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<connection>scm:git:git://github.com/dropwizard/metrics.git</connection>
<developerConnection>scm:git:[email protected]:dropwizard/metrics.git</developerConnection>
<url>http://github.com/dropwizard/metrics/</url>
<tag>HEAD</tag>
</scm>
<developers>
<developer>
<name>Facebook</name>
<email>[email protected]</email>
<timezone>America/New_York</timezone>
<roles>
<role>architect</role>
</roles>
</developer>
</developers>
</project>