|
|
|
@ -59,18 +59,21 @@ public class RocksDB extends RocksObject { |
|
|
|
|
if (compressionType.getLibraryName() != null) { |
|
|
|
|
System.loadLibrary(compressionType.getLibraryName()); |
|
|
|
|
} |
|
|
|
|
} catch (UnsatisfiedLinkError e) { |
|
|
|
|
} catch (final UnsatisfiedLinkError e) { |
|
|
|
|
// since it may be optional, we ignore its loading failure here.
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
try { |
|
|
|
|
NativeLibraryLoader.getInstance().loadLibrary(tmpDir); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
} catch (final IOException e) { |
|
|
|
|
libraryLoaded.set(LibraryState.NOT_LOADED); |
|
|
|
|
throw new RuntimeException("Unable to load the RocksDB shared library", |
|
|
|
|
e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final int encodedVersion = version(); |
|
|
|
|
version = Version.fromEncodedVersion(encodedVersion); |
|
|
|
|
|
|
|
|
|
libraryLoaded.set(LibraryState.LOADED); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -107,7 +110,7 @@ public class RocksDB extends RocksObject { |
|
|
|
|
System.load(path + "/" + Environment.getSharedLibraryFileName( |
|
|
|
|
compressionType.getLibraryName())); |
|
|
|
|
break; |
|
|
|
|
} catch (UnsatisfiedLinkError e) { |
|
|
|
|
} catch (final UnsatisfiedLinkError e) { |
|
|
|
|
// since they are optional, we ignore loading fails.
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -120,7 +123,7 @@ public class RocksDB extends RocksObject { |
|
|
|
|
Environment.getJniLibraryFileName("rocksdbjni")); |
|
|
|
|
success = true; |
|
|
|
|
break; |
|
|
|
|
} catch (UnsatisfiedLinkError e) { |
|
|
|
|
} catch (final UnsatisfiedLinkError e) { |
|
|
|
|
err = e; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -129,6 +132,9 @@ public class RocksDB extends RocksObject { |
|
|
|
|
throw err; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final int encodedVersion = version(); |
|
|
|
|
version = Version.fromEncodedVersion(encodedVersion); |
|
|
|
|
|
|
|
|
|
libraryLoaded.set(LibraryState.LOADED); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
@ -142,6 +148,10 @@ public class RocksDB extends RocksObject { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static Version rocksdbVersion() { |
|
|
|
|
return version; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Private constructor. |
|
|
|
|
* |
|
|
|
@ -4531,5 +4541,47 @@ public class RocksDB extends RocksObject { |
|
|
|
|
private native static void destroyDB(final String path, |
|
|
|
|
final long optionsHandle) throws RocksDBException; |
|
|
|
|
|
|
|
|
|
private native static int version(); |
|
|
|
|
|
|
|
|
|
protected DBOptionsInterface options_; |
|
|
|
|
private static Version version; |
|
|
|
|
|
|
|
|
|
public static class Version { |
|
|
|
|
private final byte major; |
|
|
|
|
private final byte minor; |
|
|
|
|
private final byte patch; |
|
|
|
|
|
|
|
|
|
public Version(final byte major, final byte minor, final byte patch) { |
|
|
|
|
this.major = major; |
|
|
|
|
this.minor = minor; |
|
|
|
|
this.patch = patch; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int getMajor() { |
|
|
|
|
return major; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int getMinor() { |
|
|
|
|
return minor; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public int getPatch() { |
|
|
|
|
return patch; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public String toString() { |
|
|
|
|
return getMajor() + "." + getMinor() + "." + getPatch(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Version fromEncodedVersion(int encodedVersion) { |
|
|
|
|
final byte patch = (byte) (encodedVersion & 0xff); |
|
|
|
|
encodedVersion >>= 8; |
|
|
|
|
final byte minor = (byte) (encodedVersion & 0xff); |
|
|
|
|
encodedVersion >>= 8; |
|
|
|
|
final byte major = (byte) (encodedVersion & 0xff); |
|
|
|
|
|
|
|
|
|
return new Version(major, minor, patch); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|