Merge pull request #390 from fyrz/RocksJava-Cleanup

[RocksJava] Cleanup
main
Yueh-Hsuan Chiang 10 years ago
commit 1033db29f9
  1. 29
      java/org/rocksdb/AbstractComparator.java
  2. 17
      java/org/rocksdb/BackupableDB.java
  3. 18
      java/org/rocksdb/ColumnFamilyOptionsInterface.java
  4. 19
      java/org/rocksdb/DBOptionsInterface.java
  5. 2
      java/org/rocksdb/HashSkipListMemTableConfig.java
  6. 5
      java/org/rocksdb/MemTableConfig.java
  7. 2
      java/org/rocksdb/MergeOperator.java
  8. 6
      java/org/rocksdb/NativeLibraryLoader.java
  9. 8
      java/org/rocksdb/Options.java
  10. 2
      java/org/rocksdb/PlainTableConfig.java
  11. 2
      java/org/rocksdb/RateLimiterConfig.java
  12. 18
      java/org/rocksdb/RestoreBackupableDB.java
  13. 152
      java/org/rocksdb/RocksDB.java
  14. 2
      java/org/rocksdb/RocksDBException.java
  15. 9
      java/org/rocksdb/RocksEnv.java
  16. 6
      java/org/rocksdb/RocksIterator.java
  17. 5
      java/org/rocksdb/RocksObject.java
  18. 42
      java/org/rocksdb/Slice.java
  19. 3
      java/org/rocksdb/Statistics.java
  20. 3
      java/org/rocksdb/StatisticsCollector.java
  21. 6
      java/org/rocksdb/TableFormatConfig.java
  22. 55
      java/org/rocksdb/WriteBatch.java
  23. 7
      java/org/rocksdb/WriteOptions.java
  24. 2
      java/org/rocksdb/test/AbstractComparatorTest.java
  25. 4
      java/org/rocksdb/test/PlatformRandomHelper.java
  26. 10
      java/org/rocksdb/util/Environment.java

@ -46,15 +46,18 @@ public abstract class AbstractComparator<T extends AbstractSlice>
public abstract int compare(final T a, final T b); public abstract int compare(final T a, final T b);
/** /**
* Used to reduce the space requirements * <p>Used to reduce the space requirements
* for internal data structures like index blocks. * for internal data structures like index blocks.</p>
* *
* If start &lt; limit, you may return a new start which is a * <p>If start &lt; limit, you may return a new start which is a
* shorter string in [start, limit). * shorter string in [start, limit).</p>
* *
* Simple comparator implementations may return null if they * <p>Simple comparator implementations may return null if they
* wish to use start unchanged. i.e., an implementation of * wish to use start unchanged. i.e., an implementation of
* this method that does nothing is correct. * this method that does nothing is correct.</p>
*
* @param start String
* @param limit of type T
* *
* @return a shorter start, or null * @return a shorter start, or null
*/ */
@ -63,15 +66,17 @@ public abstract class AbstractComparator<T extends AbstractSlice>
} }
/** /**
* Used to reduce the space requirements * <p>Used to reduce the space requirements
* for internal data structures like index blocks. * for internal data structures like index blocks.</p>
* *
* You may return a new short key (key1) where * <p>You may return a new short key (key1) where
* key1 &ge; key. * key1 &ge; key.</p>
* *
* Simple comparator implementations may return null if they * <p>Simple comparator implementations may return null if they
* wish to leave the key unchanged. i.e., an implementation of * wish to leave the key unchanged. i.e., an implementation of
* this method that does nothing is correct. * this method that does nothing is correct.</p>
*
* @param key String
* *
* @return a shorter key, or null * @return a shorter key, or null
*/ */

@ -23,6 +23,9 @@ public class BackupableDB extends RocksDB {
* @param db_path Path to store data to. The path for storing the backup should be * @param db_path Path to store data to. The path for storing the backup should be
* specified in the {@link org.rocksdb.BackupableDBOptions}. * specified in the {@link org.rocksdb.BackupableDBOptions}.
* @return BackupableDB reference to the opened database. * @return BackupableDB reference to the opened database.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public static BackupableDB open( public static BackupableDB open(
Options opt, BackupableDBOptions bopt, String db_path) Options opt, BackupableDBOptions bopt, String db_path)
@ -45,7 +48,9 @@ public class BackupableDB extends RocksDB {
* *
* @param flushBeforeBackup if true, then all data will be flushed * @param flushBeforeBackup if true, then all data will be flushed
* before creating backup. * before creating backup.
* @throws org.rocksdb.RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void createNewBackup(boolean flushBeforeBackup) public void createNewBackup(boolean flushBeforeBackup)
throws RocksDBException { throws RocksDBException {
@ -56,7 +61,9 @@ public class BackupableDB extends RocksDB {
* Deletes old backups, keeping latest numBackupsToKeep alive. * Deletes old backups, keeping latest numBackupsToKeep alive.
* *
* @param numBackupsToKeep Number of latest backups to keep. * @param numBackupsToKeep Number of latest backups to keep.
* @throws org.rocksdb.RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void purgeOldBackups(int numBackupsToKeep) public void purgeOldBackups(int numBackupsToKeep)
throws RocksDBException { throws RocksDBException {
@ -67,7 +74,9 @@ public class BackupableDB extends RocksDB {
* Deletes a specific backup. * Deletes a specific backup.
* *
* @param backupId of backup to delete. * @param backupId of backup to delete.
* @throws org.rocksdb.RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void deleteBackup(int backupId) throws RocksDBException { public void deleteBackup(int backupId) throws RocksDBException {
deleteBackup0(nativeHandle_, backupId); deleteBackup0(nativeHandle_, backupId);
@ -104,7 +113,7 @@ public class BackupableDB extends RocksDB {
super(); super();
} }
@Override protected void finalize() { @Override protected void finalize() throws Throwable {
close(); close();
super.finalize(); super.finalize();
} }

@ -152,7 +152,8 @@ public interface ColumnFamilyOptionsInterface {
* Default: 4MB * Default: 4MB
* @param writeBufferSize the size of write buffer. * @param writeBufferSize the size of write buffer.
* @return the instance of the current Object. * @return the instance of the current Object.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setWriteBufferSize(long writeBufferSize) Object setWriteBufferSize(long writeBufferSize)
throws RocksDBException; throws RocksDBException;
@ -223,6 +224,7 @@ public interface ColumnFamilyOptionsInterface {
* extract the prefix given a key. * extract the prefix given a key.
* *
* @param n use the first n bytes of a key as its prefix. * @param n use the first n bytes of a key as its prefix.
* @return the reference to the current option.
*/ */
Object useFixedLengthPrefixExtractor(int n); Object useFixedLengthPrefixExtractor(int n);
@ -415,6 +417,8 @@ public interface ColumnFamilyOptionsInterface {
* and total file size for level-3 will be 2GB. * and total file size for level-3 will be 2GB.
* by default 'maxBytesForLevelBase' is 10MB. * by default 'maxBytesForLevelBase' is 10MB.
* *
* @param maxBytesForLevelBase maximum bytes for level base.
*
* @return the reference to the current option. * @return the reference to the current option.
* @see #setMaxBytesForLevelMultiplier(int) * @see #setMaxBytesForLevelMultiplier(int)
*/ */
@ -614,7 +618,8 @@ public interface ColumnFamilyOptionsInterface {
* *
* @param arenaBlockSize the size of an arena block * @param arenaBlockSize the size of an arena block
* @return the reference to the current option. * @return the reference to the current option.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setArenaBlockSize(long arenaBlockSize) Object setArenaBlockSize(long arenaBlockSize)
throws RocksDBException; throws RocksDBException;
@ -762,7 +767,8 @@ public interface ColumnFamilyOptionsInterface {
* *
* @param config the mem-table config. * @param config the mem-table config.
* @return the instance of the current Object. * @return the instance of the current Object.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setMemTableConfig(MemTableConfig config) Object setMemTableConfig(MemTableConfig config)
throws RocksDBException; throws RocksDBException;
@ -826,7 +832,8 @@ public interface ColumnFamilyOptionsInterface {
* @param inplaceUpdateNumLocks the number of locks used for * @param inplaceUpdateNumLocks the number of locks used for
* inplace updates. * inplace updates.
* @return the reference to the current option. * @return the reference to the current option.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setInplaceUpdateNumLocks(long inplaceUpdateNumLocks) Object setInplaceUpdateNumLocks(long inplaceUpdateNumLocks)
throws RocksDBException; throws RocksDBException;
@ -920,7 +927,8 @@ public interface ColumnFamilyOptionsInterface {
* *
* @param maxSuccessiveMerges the maximum number of successive merges. * @param maxSuccessiveMerges the maximum number of successive merges.
* @return the reference to the current option. * @return the reference to the current option.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setMaxSuccessiveMerges(long maxSuccessiveMerges) Object setMaxSuccessiveMerges(long maxSuccessiveMerges)
throws RocksDBException; throws RocksDBException;

@ -123,7 +123,7 @@ public interface DBOptionsInterface {
* Default: 5000 * Default: 5000
* *
* @param maxOpenFiles the maximum number of open files. * @param maxOpenFiles the maximum number of open files.
* @return the reference to the current DBOptions. * @return the instance of the current Object.
*/ */
Object setMaxOpenFiles(int maxOpenFiles); Object setMaxOpenFiles(int maxOpenFiles);
@ -147,6 +147,9 @@ public interface DBOptionsInterface {
* <p>If set to 0 (default), we will dynamically choose the WAL size limit to * <p>If set to 0 (default), we will dynamically choose the WAL size limit to
* be [sum of all write_buffer_size * max_write_buffer_number] * 2</p> * be [sum of all write_buffer_size * max_write_buffer_number] * 2</p>
* <p>Default: 0</p> * <p>Default: 0</p>
*
* @param maxTotalWalSize max total wal size.
* @return the instance of the current Object.
*/ */
Object setMaxTotalWalSize(long maxTotalWalSize); Object setMaxTotalWalSize(long maxTotalWalSize);
@ -197,7 +200,7 @@ public interface DBOptionsInterface {
* *
* @param disableDataSync a boolean flag to specify whether to * @param disableDataSync a boolean flag to specify whether to
* disable data sync. * disable data sync.
* @return the reference to the current DBOptions. * @return the instance of the current Object.
*/ */
Object setDisableDataSync(boolean disableDataSync); Object setDisableDataSync(boolean disableDataSync);
@ -370,7 +373,8 @@ public interface DBOptionsInterface {
* *
* @param maxLogFileSize the maximum size of a info log file. * @param maxLogFileSize the maximum size of a info log file.
* @return the instance of the current Object. * @return the instance of the current Object.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setMaxLogFileSize(long maxLogFileSize) Object setMaxLogFileSize(long maxLogFileSize)
throws RocksDBException; throws RocksDBException;
@ -392,7 +396,8 @@ public interface DBOptionsInterface {
* *
* @param logFileTimeToRoll the time interval in seconds. * @param logFileTimeToRoll the time interval in seconds.
* @return the instance of the current Object. * @return the instance of the current Object.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setLogFileTimeToRoll(long logFileTimeToRoll) Object setLogFileTimeToRoll(long logFileTimeToRoll)
throws RocksDBException; throws RocksDBException;
@ -413,7 +418,8 @@ public interface DBOptionsInterface {
* *
* @param keepLogFileNum the maximum number of info log files to be kept. * @param keepLogFileNum the maximum number of info log files to be kept.
* @return the instance of the current Object. * @return the instance of the current Object.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setKeepLogFileNum(long keepLogFileNum) Object setKeepLogFileNum(long keepLogFileNum)
throws RocksDBException; throws RocksDBException;
@ -584,7 +590,8 @@ public interface DBOptionsInterface {
* *
* @param size the size in byte * @param size the size in byte
* @return the instance of the current Object. * @return the instance of the current Object.
* @throws org.rocksdb.RocksDBException * @throws org.rocksdb.RocksDBException thrown on 32-Bit platforms while
* overflowing the underlying platform specific value.
*/ */
Object setManifestPreallocationSize(long size) Object setManifestPreallocationSize(long size)
throws RocksDBException; throws RocksDBException;

@ -50,6 +50,8 @@ public class HashSkipListMemTableConfig extends MemTableConfig {
/** /**
* Set the height of the skip list. Default = 4. * Set the height of the skip list. Default = 4.
* *
* @param height height to set.
*
* @return the reference to the current HashSkipListMemTableConfig. * @return the reference to the current HashSkipListMemTableConfig.
*/ */
public HashSkipListMemTableConfig setHeight(int height) { public HashSkipListMemTableConfig setHeight(int height) {

@ -22,6 +22,11 @@ public abstract class MemTableConfig {
* that associated with the Java MemTableConfig. * that associated with the Java MemTableConfig.
* *
* @see Options#setMemTableConfig(MemTableConfig) * @see Options#setMemTableConfig(MemTableConfig)
*
* @return native handle address to native memory table instance.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
abstract protected long newMemTableFactoryHandle() abstract protected long newMemTableFactoryHandle()
throws RocksDBException; throws RocksDBException;

@ -5,8 +5,6 @@
package org.rocksdb; package org.rocksdb;
import java.util.*;
/** /**
* MergeOperator holds an operator to be applied when compacting * MergeOperator holds an operator to be applied when compacting
* two merge operands held under the same key in order to obtain a single * two merge operands held under the same key in order to obtain a single

@ -9,12 +9,12 @@ import org.rocksdb.util.Environment;
*/ */
public class NativeLibraryLoader { public class NativeLibraryLoader {
private static String sharedLibraryName = Environment.getJniLibraryName("rocksdb"); private static String sharedLibraryName = Environment.getJniLibraryName("rocksdb");
private static String tempFilePrefix = "librocksdbjni";
private static String tempFileSuffix = "." + Environment.getJniLibraryExtension(); private static String tempFileSuffix = "." + Environment.getJniLibraryExtension();
public static void loadLibraryFromJar(String tmpDir) public static void loadLibraryFromJar(String tmpDir)
throws IOException { throws IOException {
File temp; File temp;
String tempFilePrefix = "librocksdbjni";
if(tmpDir == null || tmpDir.equals("")) if(tmpDir == null || tmpDir.equals(""))
temp = File.createTempFile(tempFilePrefix, tempFileSuffix); temp = File.createTempFile(tempFilePrefix, tempFileSuffix);
else else
@ -43,9 +43,7 @@ public class NativeLibraryLoader {
} finally { } finally {
if(os != null) if(os != null)
os.close(); os.close();
is.close();
if(is != null)
is.close();
} }
System.load(temp.getAbsolutePath()); System.load(temp.getAbsolutePath());

@ -61,6 +61,9 @@ public class Options extends RocksObject
* Use the specified object to interact with the environment, * Use the specified object to interact with the environment,
* e.g. to read/write files, schedule background work, etc. * e.g. to read/write files, schedule background work, etc.
* Default: {@link RocksEnv#getDefault()} * Default: {@link RocksEnv#getDefault()}
*
* @param env {@link RocksEnv} instance.
* @return the instance of the current Options.
*/ */
public Options setEnv(RocksEnv env) { public Options setEnv(RocksEnv env) {
assert(isInitialized()); assert(isInitialized());
@ -69,6 +72,11 @@ public class Options extends RocksObject
return this; return this;
} }
/**
* Returns the set RocksEnv instance.
*
* @return {@link RocksEnv} instance set in the Options.
*/
public RocksEnv getEnv() { public RocksEnv getEnv() {
return env_; return env_;
} }

@ -131,7 +131,7 @@ public class PlainTableConfig extends TableFormatConfig {
* *
* <p>See linux doc Documentation/vm/hugetlbpage.txt</p> * <p>See linux doc Documentation/vm/hugetlbpage.txt</p>
* *
* @param hugePageTlbSize * @param hugePageTlbSize huge page tlb size
* @return the reference to the current config. * @return the reference to the current config.
*/ */
public PlainTableConfig setHugePageTlbSize(int hugePageTlbSize) { public PlainTableConfig setHugePageTlbSize(int hugePageTlbSize) {

@ -16,6 +16,8 @@ public abstract class RateLimiterConfig {
* with a Java RateLimiterConfig. * with a Java RateLimiterConfig.
* *
* @see org.rocksdb.DBOptions#setRateLimiter(long, long) * @see org.rocksdb.DBOptions#setRateLimiter(long, long)
*
* @return native handle address to rate limiter instance.
*/ */
abstract protected long newRateLimiterHandle(); abstract protected long newRateLimiterHandle();
} }

@ -40,8 +40,10 @@ public class RestoreBackupableDB extends RocksObject {
* @param backupId id pointing to backup * @param backupId id pointing to backup
* @param dbDir database directory to restore to * @param dbDir database directory to restore to
* @param walDir directory where wal files are located * @param walDir directory where wal files are located
* @param restoreOptions {@link org.rocksdb.RestoreOptions} instance * @param restoreOptions {@link org.rocksdb.RestoreOptions} instance.
* @throws RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void restoreDBFromBackup(long backupId, String dbDir, String walDir, public void restoreDBFromBackup(long backupId, String dbDir, String walDir,
RestoreOptions restoreOptions) throws RocksDBException { RestoreOptions restoreOptions) throws RocksDBException {
@ -55,7 +57,9 @@ public class RestoreBackupableDB extends RocksObject {
* @param dbDir database directory to restore to * @param dbDir database directory to restore to
* @param walDir directory where wal files are located * @param walDir directory where wal files are located
* @param restoreOptions {@link org.rocksdb.RestoreOptions} instance * @param restoreOptions {@link org.rocksdb.RestoreOptions} instance
* @throws RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void restoreDBFromLatestBackup(String dbDir, String walDir, public void restoreDBFromLatestBackup(String dbDir, String walDir,
RestoreOptions restoreOptions) throws RocksDBException { RestoreOptions restoreOptions) throws RocksDBException {
@ -67,7 +71,9 @@ public class RestoreBackupableDB extends RocksObject {
* Deletes old backups, keeping latest numBackupsToKeep alive. * Deletes old backups, keeping latest numBackupsToKeep alive.
* *
* @param numBackupsToKeep of latest backups to keep * @param numBackupsToKeep of latest backups to keep
* @throws org.rocksdb.RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void purgeOldBackups(int numBackupsToKeep) throws RocksDBException { public void purgeOldBackups(int numBackupsToKeep) throws RocksDBException {
purgeOldBackups0(nativeHandle_, numBackupsToKeep); purgeOldBackups0(nativeHandle_, numBackupsToKeep);
@ -77,7 +83,9 @@ public class RestoreBackupableDB extends RocksObject {
* Deletes a specific backup. * Deletes a specific backup.
* *
* @param backupId of backup to delete. * @param backupId of backup to delete.
* @throws org.rocksdb.RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void deleteBackup(int backupId) throws RocksDBException { public void deleteBackup(int backupId) throws RocksDBException {
deleteBackup0(nativeHandle_, backupId); deleteBackup0(nativeHandle_, backupId);

@ -95,7 +95,8 @@ public class RocksDB extends RocksObject {
* @return a {@link RocksDB} instance on success, null if the specified * @return a {@link RocksDB} instance on success, null if the specified
* {@link RocksDB} can not be opened. * {@link RocksDB} can not be opened.
* *
* @throws org.rocksdb.RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
* @see Options#setCreateIfMissing(boolean) * @see Options#setCreateIfMissing(boolean)
*/ */
public static RocksDB open(String path) throws RocksDBException { public static RocksDB open(String path) throws RocksDBException {
@ -130,7 +131,8 @@ public class RocksDB extends RocksObject {
* @return a {@link RocksDB} instance on success, null if the specified * @return a {@link RocksDB} instance on success, null if the specified
* {@link RocksDB} can not be opened. * {@link RocksDB} can not be opened.
* *
* @throws org.rocksdb.RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
* @see DBOptions#setCreateIfMissing(boolean) * @see DBOptions#setCreateIfMissing(boolean)
*/ */
public static RocksDB open(String path, public static RocksDB open(String path,
@ -161,7 +163,9 @@ public class RocksDB extends RocksObject {
* @return a {@link RocksDB} instance on success, null if the specified * @return a {@link RocksDB} instance on success, null if the specified
* {@link RocksDB} can not be opened. * {@link RocksDB} can not be opened.
* *
* @throws org.rocksdb.RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*
* @see Options#setCreateIfMissing(boolean) * @see Options#setCreateIfMissing(boolean)
*/ */
public static RocksDB open(Options options, String path) public static RocksDB open(Options options, String path)
@ -206,7 +210,9 @@ public class RocksDB extends RocksObject {
* @return a {@link RocksDB} instance on success, null if the specified * @return a {@link RocksDB} instance on success, null if the specified
* {@link RocksDB} can not be opened. * {@link RocksDB} can not be opened.
* *
* @throws org.rocksdb.RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*
* @see DBOptions#setCreateIfMissing(boolean) * @see DBOptions#setCreateIfMissing(boolean)
*/ */
public static RocksDB open(DBOptions options, String path, public static RocksDB open(DBOptions options, String path,
@ -231,7 +237,9 @@ public class RocksDB extends RocksObject {
* @param path the path to the RocksDB. * @param path the path to the RocksDB.
* @return a {@link RocksDB} instance on success, null if the specified * @return a {@link RocksDB} instance on success, null if the specified
* {@link RocksDB} can not be opened. * {@link RocksDB} can not be opened.
* @throws RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public static RocksDB openReadOnly(String path) public static RocksDB openReadOnly(String path)
throws RocksDBException { throws RocksDBException {
@ -252,7 +260,9 @@ public class RocksDB extends RocksObject {
* on open. * on open.
* @return a {@link RocksDB} instance on success, null if the specified * @return a {@link RocksDB} instance on success, null if the specified
* {@link RocksDB} can not be opened. * {@link RocksDB} can not be opened.
* @throws RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public static RocksDB openReadOnly(String path, public static RocksDB openReadOnly(String path,
List<ColumnFamilyDescriptor> columnFamilyDescriptors, List<ColumnFamilyDescriptor> columnFamilyDescriptors,
@ -277,7 +287,9 @@ public class RocksDB extends RocksObject {
* @param path the path to the RocksDB. * @param path the path to the RocksDB.
* @return a {@link RocksDB} instance on success, null if the specified * @return a {@link RocksDB} instance on success, null if the specified
* {@link RocksDB} can not be opened. * {@link RocksDB} can not be opened.
* @throws RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public static RocksDB openReadOnly(Options options, String path) public static RocksDB openReadOnly(Options options, String path)
throws RocksDBException { throws RocksDBException {
@ -309,7 +321,9 @@ public class RocksDB extends RocksObject {
* on open. * on open.
* @return a {@link RocksDB} instance on success, null if the specified * @return a {@link RocksDB} instance on success, null if the specified
* {@link RocksDB} can not be opened. * {@link RocksDB} can not be opened.
* @throws RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public static RocksDB openReadOnly(DBOptions options, String path, public static RocksDB openReadOnly(DBOptions options, String path,
List<ColumnFamilyDescriptor> columnFamilyDescriptors, List<ColumnFamilyDescriptor> columnFamilyDescriptors,
@ -336,7 +350,8 @@ public class RocksDB extends RocksObject {
* @param path Absolute path to rocksdb database * @param path Absolute path to rocksdb database
* @return List&lt;byte[]&gt; List containing the column family names * @return List&lt;byte[]&gt; List containing the column family names
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public static List<byte[]> listColumnFamilies(Options options, String path) public static List<byte[]> listColumnFamilies(Options options, String path)
throws RocksDBException { throws RocksDBException {
@ -366,7 +381,8 @@ public class RocksDB extends RocksObject {
* @param key the specified key to be inserted. * @param key the specified key to be inserted.
* @param value the value associated with the specified key. * @param value the value associated with the specified key.
* *
* @see RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void put(byte[] key, byte[] value) throws RocksDBException { public void put(byte[] key, byte[] value) throws RocksDBException {
put(nativeHandle_, key, key.length, value, value.length); put(nativeHandle_, key, key.length, value, value.length);
@ -383,7 +399,8 @@ public class RocksDB extends RocksObject {
* *
* throws IllegalArgumentException if column family is not present * throws IllegalArgumentException if column family is not present
* *
* @see RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void put(ColumnFamilyHandle columnFamilyHandle, byte[] key, public void put(ColumnFamilyHandle columnFamilyHandle, byte[] key,
byte[] value) throws RocksDBException { byte[] value) throws RocksDBException {
@ -394,10 +411,12 @@ public class RocksDB extends RocksObject {
/** /**
* Set the database entry for "key" to "value". * Set the database entry for "key" to "value".
* *
* @param writeOpts {@link org.rocksdb.WriteOptions} instance.
* @param key the specified key to be inserted. * @param key the specified key to be inserted.
* @param value the value associated with the specified key. * @param value the value associated with the specified key.
* *
* @see RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void put(WriteOptions writeOpts, byte[] key, byte[] value) public void put(WriteOptions writeOpts, byte[] key, byte[] value)
throws RocksDBException { throws RocksDBException {
@ -411,12 +430,14 @@ public class RocksDB extends RocksObject {
* *
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
* instance * instance
* @param writeOpts {@link org.rocksdb.WriteOptions} instance.
* @param key the specified key to be inserted. * @param key the specified key to be inserted.
* @param value the value associated with the specified key. * @param value the value associated with the specified key.
* *
* throws IllegalArgumentException if column family is not present * throws IllegalArgumentException if column family is not present
* *
* @see RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
* @see IllegalArgumentException * @see IllegalArgumentException
*/ */
public void put(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpts, public void put(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpts,
@ -506,7 +527,8 @@ public class RocksDB extends RocksObject {
* @param writeOpts WriteOptions instance * @param writeOpts WriteOptions instance
* @param updates WriteBatch instance * @param updates WriteBatch instance
* *
* @see RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void write(WriteOptions writeOpts, WriteBatch updates) public void write(WriteOptions writeOpts, WriteBatch updates)
throws RocksDBException { throws RocksDBException {
@ -517,8 +539,11 @@ public class RocksDB extends RocksObject {
* Add merge operand for key/value pair. * Add merge operand for key/value pair.
* *
* @param key the specified key to be merged. * @param key the specified key to be merged.
* @param value the value to be nerged with the current value for * @param value the value to be merged with the current value for
* the specified key. * the specified key.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void merge(byte[] key, byte[] value) throws RocksDBException { public void merge(byte[] key, byte[] value) throws RocksDBException {
merge(nativeHandle_, key, key.length, value, value.length); merge(nativeHandle_, key, key.length, value, value.length);
@ -529,8 +554,11 @@ public class RocksDB extends RocksObject {
* *
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance * @param columnFamilyHandle {@link ColumnFamilyHandle} instance
* @param key the specified key to be merged. * @param key the specified key to be merged.
* @param value the value to be nerged with the current value for * @param value the value to be merged with the current value for
* the specified key. * the specified key.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void merge(ColumnFamilyHandle columnFamilyHandle, byte[] key, public void merge(ColumnFamilyHandle columnFamilyHandle, byte[] key,
byte[] value) throws RocksDBException { byte[] value) throws RocksDBException {
@ -545,6 +573,9 @@ public class RocksDB extends RocksObject {
* @param key the specified key to be merged. * @param key the specified key to be merged.
* @param value the value to be merged with the current value for * @param value the value to be merged with the current value for
* the specified key. * the specified key.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void merge(WriteOptions writeOpts, byte[] key, byte[] value) public void merge(WriteOptions writeOpts, byte[] key, byte[] value)
throws RocksDBException { throws RocksDBException {
@ -560,6 +591,9 @@ public class RocksDB extends RocksObject {
* @param key the specified key to be merged. * @param key the specified key to be merged.
* @param value the value to be merged with the current value for * @param value the value to be merged with the current value for
* the specified key. * the specified key.
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void merge(ColumnFamilyHandle columnFamilyHandle, public void merge(ColumnFamilyHandle columnFamilyHandle,
WriteOptions writeOpts, byte[] key, byte[] value) WriteOptions writeOpts, byte[] key, byte[] value)
@ -580,7 +614,8 @@ public class RocksDB extends RocksObject {
* be returned. RocksDB.NOT_FOUND will be returned if the value not * be returned. RocksDB.NOT_FOUND will be returned if the value not
* found. * found.
* *
* @see RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public int get(byte[] key, byte[] value) throws RocksDBException { public int get(byte[] key, byte[] value) throws RocksDBException {
return get(nativeHandle_, key, key.length, value, value.length); return get(nativeHandle_, key, key.length, value, value.length);
@ -600,7 +635,8 @@ public class RocksDB extends RocksObject {
* be returned. RocksDB.NOT_FOUND will be returned if the value not * be returned. RocksDB.NOT_FOUND will be returned if the value not
* found. * found.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public int get(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value) public int get(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)
throws RocksDBException, IllegalArgumentException { throws RocksDBException, IllegalArgumentException {
@ -611,6 +647,7 @@ public class RocksDB extends RocksObject {
/** /**
* Get the value associated with the specified key. * Get the value associated with the specified key.
* *
* @param opt {@link org.rocksdb.ReadOptions} instance.
* @param key the key to retrieve the value. * @param key the key to retrieve the value.
* @param value the out-value to receive the retrieved value. * @param value the out-value to receive the retrieved value.
* @return The size of the actual value that matches the specified * @return The size of the actual value that matches the specified
@ -620,7 +657,8 @@ public class RocksDB extends RocksObject {
* be returned. RocksDB.NOT_FOUND will be returned if the value not * be returned. RocksDB.NOT_FOUND will be returned if the value not
* found. * found.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public int get(ReadOptions opt, byte[] key, byte[] value) public int get(ReadOptions opt, byte[] key, byte[] value)
throws RocksDBException { throws RocksDBException {
@ -632,6 +670,7 @@ public class RocksDB extends RocksObject {
* *
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
* instance * instance
* @param opt {@link org.rocksdb.ReadOptions} instance.
* @param key the key to retrieve the value. * @param key the key to retrieve the value.
* @param value the out-value to receive the retrieved value. * @param value the out-value to receive the retrieved value.
* @return The size of the actual value that matches the specified * @return The size of the actual value that matches the specified
@ -641,7 +680,8 @@ public class RocksDB extends RocksObject {
* be returned. RocksDB.NOT_FOUND will be returned if the value not * be returned. RocksDB.NOT_FOUND will be returned if the value not
* found. * found.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public int get(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, byte[] key, public int get(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, byte[] key,
byte[] value) throws RocksDBException { byte[] value) throws RocksDBException {
@ -658,7 +698,8 @@ public class RocksDB extends RocksObject {
* @return a byte array storing the value associated with the input key if * @return a byte array storing the value associated with the input key if
* any. null if it does not find the specified key. * any. null if it does not find the specified key.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public byte[] get(byte[] key) throws RocksDBException { public byte[] get(byte[] key) throws RocksDBException {
return get(nativeHandle_, key, key.length); return get(nativeHandle_, key, key.length);
@ -675,7 +716,8 @@ public class RocksDB extends RocksObject {
* @return a byte array storing the value associated with the input key if * @return a byte array storing the value associated with the input key if
* any. null if it does not find the specified key. * any. null if it does not find the specified key.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public byte[] get(ColumnFamilyHandle columnFamilyHandle, byte[] key) public byte[] get(ColumnFamilyHandle columnFamilyHandle, byte[] key)
throws RocksDBException { throws RocksDBException {
@ -692,7 +734,8 @@ public class RocksDB extends RocksObject {
* @return a byte array storing the value associated with the input key if * @return a byte array storing the value associated with the input key if
* any. null if it does not find the specified key. * any. null if it does not find the specified key.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public byte[] get(ReadOptions opt, byte[] key) throws RocksDBException { public byte[] get(ReadOptions opt, byte[] key) throws RocksDBException {
return get(nativeHandle_, opt.nativeHandle_, key, key.length); return get(nativeHandle_, opt.nativeHandle_, key, key.length);
@ -710,7 +753,8 @@ public class RocksDB extends RocksObject {
* @return a byte array storing the value associated with the input key if * @return a byte array storing the value associated with the input key if
* any. null if it does not find the specified key. * any. null if it does not find the specified key.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public byte[] get(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, public byte[] get(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt,
byte[] key) throws RocksDBException { byte[] key) throws RocksDBException {
@ -725,7 +769,8 @@ public class RocksDB extends RocksObject {
* @return Map where key of map is the key passed by user and value for map * @return Map where key of map is the key passed by user and value for map
* entry is the corresponding value in DB. * entry is the corresponding value in DB.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public Map<byte[], byte[]> multiGet(List<byte[]> keys) public Map<byte[], byte[]> multiGet(List<byte[]> keys)
throws RocksDBException { throws RocksDBException {
@ -734,7 +779,7 @@ public class RocksDB extends RocksObject {
List<byte[]> values = multiGet( List<byte[]> values = multiGet(
nativeHandle_, keys, keys.size()); nativeHandle_, keys, keys.size());
Map<byte[], byte[]> keyValueMap = new HashMap<byte[], byte[]>(); Map<byte[], byte[]> keyValueMap = new HashMap<>();
for(int i = 0; i < values.size(); i++) { for(int i = 0; i < values.size(); i++) {
if(values.get(i) == null) { if(values.get(i) == null) {
continue; continue;
@ -759,8 +804,10 @@ public class RocksDB extends RocksObject {
* @return Map where key of map is the key passed by user and value for map * @return Map where key of map is the key passed by user and value for map
* entry is the corresponding value in DB. * entry is the corresponding value in DB.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* @throws IllegalArgumentException * native library.
* @throws IllegalArgumentException thrown if the size of passed keys is not
* equal to the amount of passed column family handles.
*/ */
public Map<byte[], byte[]> multiGet(List<ColumnFamilyHandle> columnFamilyHandleList, public Map<byte[], byte[]> multiGet(List<ColumnFamilyHandle> columnFamilyHandleList,
List<byte[]> keys) throws RocksDBException, IllegalArgumentException { List<byte[]> keys) throws RocksDBException, IllegalArgumentException {
@ -774,7 +821,7 @@ public class RocksDB extends RocksObject {
List<byte[]> values = multiGet(nativeHandle_, keys, keys.size(), List<byte[]> values = multiGet(nativeHandle_, keys, keys.size(),
columnFamilyHandleList); columnFamilyHandleList);
Map<byte[], byte[]> keyValueMap = new HashMap<byte[], byte[]>(); Map<byte[], byte[]> keyValueMap = new HashMap<>();
for(int i = 0; i < values.size(); i++) { for(int i = 0; i < values.size(); i++) {
if (values.get(i) == null) { if (values.get(i) == null) {
continue; continue;
@ -792,7 +839,8 @@ public class RocksDB extends RocksObject {
* @return Map where key of map is the key passed by user and value for map * @return Map where key of map is the key passed by user and value for map
* entry is the corresponding value in DB. * entry is the corresponding value in DB.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public Map<byte[], byte[]> multiGet(ReadOptions opt, List<byte[]> keys) public Map<byte[], byte[]> multiGet(ReadOptions opt, List<byte[]> keys)
throws RocksDBException { throws RocksDBException {
@ -801,7 +849,7 @@ public class RocksDB extends RocksObject {
List<byte[]> values = multiGet( List<byte[]> values = multiGet(
nativeHandle_, opt.nativeHandle_, keys, keys.size()); nativeHandle_, opt.nativeHandle_, keys, keys.size());
Map<byte[], byte[]> keyValueMap = new HashMap<byte[], byte[]>(); Map<byte[], byte[]> keyValueMap = new HashMap<>();
for(int i = 0; i < values.size(); i++) { for(int i = 0; i < values.size(); i++) {
if(values.get(i) == null) { if(values.get(i) == null) {
continue; continue;
@ -827,8 +875,10 @@ public class RocksDB extends RocksObject {
* @return Map where key of map is the key passed by user and value for map * @return Map where key of map is the key passed by user and value for map
* entry is the corresponding value in DB. * entry is the corresponding value in DB.
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* @throws java.lang.IllegalArgumentException * native library.
* @throws IllegalArgumentException thrown if the size of passed keys is not
* equal to the amount of passed column family handles.
*/ */
public Map<byte[], byte[]> multiGet(ReadOptions opt, public Map<byte[], byte[]> multiGet(ReadOptions opt,
List<ColumnFamilyHandle> columnFamilyHandleList, List<byte[]> keys) List<ColumnFamilyHandle> columnFamilyHandleList, List<byte[]> keys)
@ -844,7 +894,7 @@ public class RocksDB extends RocksObject {
List<byte[]> values = multiGet(nativeHandle_, opt.nativeHandle_, List<byte[]> values = multiGet(nativeHandle_, opt.nativeHandle_,
keys, keys.size(), columnFamilyHandleList); keys, keys.size(), columnFamilyHandleList);
Map<byte[], byte[]> keyValueMap = new HashMap<byte[], byte[]>(); Map<byte[], byte[]> keyValueMap = new HashMap<>();
for(int i = 0; i < values.size(); i++) { for(int i = 0; i < values.size(); i++) {
if(values.get(i) == null) { if(values.get(i) == null) {
continue; continue;
@ -862,7 +912,8 @@ public class RocksDB extends RocksObject {
* *
* @param key Key to delete within database * @param key Key to delete within database
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void remove(byte[] key) throws RocksDBException { public void remove(byte[] key) throws RocksDBException {
remove(nativeHandle_, key, key.length); remove(nativeHandle_, key, key.length);
@ -877,7 +928,8 @@ public class RocksDB extends RocksObject {
* instance * instance
* @param key Key to delete within database * @param key Key to delete within database
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key) public void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key)
throws RocksDBException { throws RocksDBException {
@ -892,7 +944,8 @@ public class RocksDB extends RocksObject {
* @param writeOpt WriteOptions to be used with delete operation * @param writeOpt WriteOptions to be used with delete operation
* @param key Key to delete within database * @param key Key to delete within database
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void remove(WriteOptions writeOpt, byte[] key) public void remove(WriteOptions writeOpt, byte[] key)
throws RocksDBException { throws RocksDBException {
@ -909,7 +962,8 @@ public class RocksDB extends RocksObject {
* @param writeOpt WriteOptions to be used with delete operation * @param writeOpt WriteOptions to be used with delete operation
* @param key Key to delete within database * @param key Key to delete within database
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void remove(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt, public void remove(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt,
byte[] key) throws RocksDBException { byte[] key) throws RocksDBException {
@ -940,7 +994,8 @@ public class RocksDB extends RocksObject {
* @param property to be fetched. See above for examples * @param property to be fetched. See above for examples
* @return property value * @return property value
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public String getProperty(ColumnFamilyHandle columnFamilyHandle, String property) public String getProperty(ColumnFamilyHandle columnFamilyHandle, String property)
throws RocksDBException { throws RocksDBException {
@ -967,7 +1022,8 @@ public class RocksDB extends RocksObject {
* @param property to be fetched. See above for examples * @param property to be fetched. See above for examples
* @return property value * @return property value
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public String getProperty(String property) throws RocksDBException { public String getProperty(String property) throws RocksDBException {
return getProperty0(nativeHandle_, property, property.length()); return getProperty0(nativeHandle_, property, property.length());
@ -997,7 +1053,7 @@ public class RocksDB extends RocksObject {
* <p>nullptr will be returned if the DB fails to take a snapshot or does * <p>nullptr will be returned if the DB fails to take a snapshot or does
* not support snapshot.</p> * not support snapshot.</p>
* *
* @return Snapshot * @return Snapshot {@link Snapshot} instance
*/ */
public Snapshot getSnapshot() { public Snapshot getSnapshot() {
long snapshotHandle = getSnapshot(nativeHandle_); long snapshotHandle = getSnapshot(nativeHandle_);
@ -1046,12 +1102,13 @@ public class RocksDB extends RocksObject {
* @return {@link java.util.List} containing {@link org.rocksdb.RocksIterator} * @return {@link java.util.List} containing {@link org.rocksdb.RocksIterator}
* instances * instances
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public List<RocksIterator> newIterators( public List<RocksIterator> newIterators(
List<ColumnFamilyHandle> columnFamilyHandleList) throws RocksDBException { List<ColumnFamilyHandle> columnFamilyHandleList) throws RocksDBException {
List<RocksIterator> iterators = List<RocksIterator> iterators =
new ArrayList<RocksIterator>(columnFamilyHandleList.size()); new ArrayList<>(columnFamilyHandleList.size());
long[] iteratorRefs = iterators(nativeHandle_, columnFamilyHandleList); long[] iteratorRefs = iterators(nativeHandle_, columnFamilyHandleList);
for (int i=0; i<columnFamilyHandleList.size(); i++){ for (int i=0; i<columnFamilyHandleList.size(); i++){
@ -1066,8 +1123,10 @@ public class RocksDB extends RocksObject {
* The ColumnFamilyHandle is automatically disposed with DB disposal. * The ColumnFamilyHandle is automatically disposed with DB disposal.
* *
* @param columnFamilyDescriptor column family to be created. * @param columnFamilyDescriptor column family to be created.
* @return {@link org.rocksdb.ColumnFamilyHandle} instance * @return {@link org.rocksdb.ColumnFamilyHandle} instance.
* @see RocksDBException *
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public ColumnFamilyHandle createColumnFamily( public ColumnFamilyHandle createColumnFamily(
ColumnFamilyDescriptor columnFamilyDescriptor) ColumnFamilyDescriptor columnFamilyDescriptor)
@ -1084,7 +1143,8 @@ public class RocksDB extends RocksObject {
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} * @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
* instance * instance
* *
* @throws RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void dropColumnFamily(ColumnFamilyHandle columnFamilyHandle) public void dropColumnFamily(ColumnFamilyHandle columnFamilyHandle)
throws RocksDBException, IllegalArgumentException { throws RocksDBException, IllegalArgumentException {

@ -5,8 +5,6 @@
package org.rocksdb; package org.rocksdb;
import java.util.*;
/** /**
* A RocksDBException encapsulates the error of an operation. This exception * A RocksDBException encapsulates the error of an operation. This exception
* type is used to describe an internal error from the c++ rocksdb library. * type is used to describe an internal error from the c++ rocksdb library.

@ -29,6 +29,8 @@ public class RocksEnv extends RocksObject {
* belongs to rocksdb c++. As a result, the returned RocksEnv will not * belongs to rocksdb c++. As a result, the returned RocksEnv will not
* have the ownership of its c++ resource, and calling its dispose() * have the ownership of its c++ resource, and calling its dispose()
* will be no-op.</p> * will be no-op.</p>
*
* @return the default {@link org.rocksdb.RocksEnv} instance.
*/ */
public static RocksEnv getDefault() { public static RocksEnv getDefault() {
return default_env_; return default_env_;
@ -38,6 +40,10 @@ public class RocksEnv extends RocksObject {
* <p>Sets the number of background worker threads of the flush pool * <p>Sets the number of background worker threads of the flush pool
* for this environment.</p> * for this environment.</p>
* <p>Default number: 1</p> * <p>Default number: 1</p>
*
* @param num the number of threads
*
* @return current {@link org.rocksdb.RocksEnv} instance.
*/ */
public RocksEnv setBackgroundThreads(int num) { public RocksEnv setBackgroundThreads(int num) {
return setBackgroundThreads(num, FLUSH_POOL); return setBackgroundThreads(num, FLUSH_POOL);
@ -52,6 +58,7 @@ public class RocksEnv extends RocksObject {
* FLUSH_POOL or COMPACTION_POOL. * FLUSH_POOL or COMPACTION_POOL.
* *
* <p>Default number: 1</p> * <p>Default number: 1</p>
* @return current {@link org.rocksdb.RocksEnv} instance.
*/ */
public RocksEnv setBackgroundThreads(int num, int poolID) { public RocksEnv setBackgroundThreads(int num, int poolID) {
setBackgroundThreads(nativeHandle_, num, poolID); setBackgroundThreads(nativeHandle_, num, poolID);
@ -66,6 +73,8 @@ public class RocksEnv extends RocksObject {
* *
* @param poolID the id to specified a thread pool. Should be either * @param poolID the id to specified a thread pool. Should be either
* FLUSH_POOL or COMPACTION_POOL. * FLUSH_POOL or COMPACTION_POOL.
*
* @return the thread pool queue length.
*/ */
public int getThreadPoolQueueLen(int poolID) { public int getThreadPoolQueueLen(int poolID) {
return getThreadPoolQueueLen(nativeHandle_, poolID); return getThreadPoolQueueLen(nativeHandle_, poolID);

@ -112,6 +112,9 @@ public class RocksIterator extends RocksObject {
* <p>Position at the first key in the source that at or past target * <p>Position at the first key in the source that at or past target
* The iterator is valid after this call iff the source contains * The iterator is valid after this call iff the source contains
* an entry that comes at or past target.</p> * an entry that comes at or past target.</p>
*
* @param target byte array describing a key or a
* key prefix to seek for.
*/ */
public void seek(byte[] target) { public void seek(byte[] target) {
assert(isInitialized()); assert(isInitialized());
@ -123,7 +126,8 @@ public class RocksIterator extends RocksObject {
* If non-blocking IO is requested and this operation cannot be * If non-blocking IO is requested and this operation cannot be
* satisfied without doing some IO, then this returns Status::Incomplete(). * satisfied without doing some IO, then this returns Status::Incomplete().
* *
* @throws org.rocksdb.RocksDBException * @throws RocksDBException thrown if error happens in underlying
* native library.
*/ */
public void status() throws RocksDBException { public void status() throws RocksDBException {
assert(isInitialized()); assert(isInitialized());

@ -37,7 +37,7 @@ public abstract class RocksObject {
* small in that they seems to only hold a long variable. As a result, * small in that they seems to only hold a long variable. As a result,
* they might have low priority in the GC process. To prevent this, * they might have low priority in the GC process. To prevent this,
* it is suggested to call {@code dispose()} manually. * it is suggested to call {@code dispose()} manually.
* <p> * </p>
* <p> * <p>
* Note that once an instance of {@code RocksObject} has been disposed, * Note that once an instance of {@code RocksObject} has been disposed,
* calling its function will lead undefined behavior. * calling its function will lead undefined behavior.
@ -107,8 +107,9 @@ public abstract class RocksObject {
* Simply calls {@code dispose()} and release its c++ resource if it has not * Simply calls {@code dispose()} and release its c++ resource if it has not
* yet released. * yet released.
*/ */
@Override protected void finalize() { @Override protected void finalize() throws Throwable {
dispose(); dispose();
super.finalize();
} }
/** /**

@ -6,26 +6,26 @@
package org.rocksdb; package org.rocksdb;
/** /**
* Base class for slices which will receive * <p>Base class for slices which will receive
* byte[] based access to the underlying data. * byte[] based access to the underlying data.</p>
* *
* byte[] backed slices typically perform better with * <p>byte[] backed slices typically perform better with
* small keys and values. When using larger keys and * small keys and values. When using larger keys and
* values consider using @see org.rocksdb.DirectSlice * values consider using {@link org.rocksdb.DirectSlice}</p>
*/ */
public class Slice extends AbstractSlice<byte[]> { public class Slice extends AbstractSlice<byte[]> {
/** /**
* Called from JNI to construct a new Java Slice * <p>Called from JNI to construct a new Java Slice
* without an underlying C++ object set * without an underlying C++ object set
* at creation time. * at creation time.</p>
* *
* Note: You should be aware that * <p>Note: You should be aware that
* {@see org.rocksdb.RocksObject#disOwnNativeHandle()} is intentionally * {@see org.rocksdb.RocksObject#disOwnNativeHandle()} is intentionally
* called from the default Slice constructor, and that it is marked as * called from the default Slice constructor, and that it is marked as
* private. This is so that developers cannot construct their own default * private. This is so that developers cannot construct their own default
* Slice objects (at present). As developers cannot construct their own * Slice objects (at present). As developers cannot construct their own
* Slice objects through this, they are not creating underlying C++ Slice * Slice objects through this, they are not creating underlying C++ Slice
* objects, and so there is nothing to free (dispose) from Java. * objects, and so there is nothing to free (dispose) from Java.</p>
*/ */
private Slice() { private Slice() {
super(); super();
@ -33,9 +33,10 @@ public class Slice extends AbstractSlice<byte[]> {
} }
/** /**
* Constructs a slice * <p>Constructs a slice where the data is taken from
* where the data is taken from * a String.</p>
* a String. *
* @param str String value.
*/ */
public Slice(final String str) { public Slice(final String str) {
super(); super();
@ -43,9 +44,11 @@ public class Slice extends AbstractSlice<byte[]> {
} }
/** /**
* Constructs a slice * <p>Constructs a slice where the data is a copy of
* where the data is a copy of * the byte array from a specific offset.</p>
* the byte array from a specific offset. *
* @param data byte array.
* @param offset offset within the byte array.
*/ */
public Slice(final byte[] data, final int offset) { public Slice(final byte[] data, final int offset) {
super(); super();
@ -53,9 +56,10 @@ public class Slice extends AbstractSlice<byte[]> {
} }
/** /**
* Constructs a slice * <p>Constructs a slice where the data is a copy of
* where the data is a copy of * the byte array.</p>
* the byte array. *
* @param data byte array.
*/ */
public Slice(final byte[] data) { public Slice(final byte[] data) {
super(); super();
@ -63,8 +67,8 @@ public class Slice extends AbstractSlice<byte[]> {
} }
/** /**
* Deletes underlying C++ slice pointer * <p>Deletes underlying C++ slice pointer
* and any buffered data. * and any buffered data.</p>
* *
* <p> * <p>
* Note that this function should be called only after all * Note that this function should be called only after all

@ -24,9 +24,8 @@ public class Statistics {
public HistogramData geHistogramData(HistogramType histogramType) { public HistogramData geHistogramData(HistogramType histogramType) {
assert(isInitialized()); assert(isInitialized());
HistogramData hist = geHistogramData0( return geHistogramData0(
histogramType.getValue(), statsHandle_); histogramType.getValue(), statsHandle_);
return hist;
} }
private boolean isInitialized() { private boolean isInitialized() {

@ -6,11 +6,9 @@
package org.rocksdb; package org.rocksdb;
import java.util.List; import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
/** /**
* <p>Helper class to collect DB statistics periodically at a period specified in * <p>Helper class to collect DB statistics periodically at a period specified in
@ -51,6 +49,7 @@ public class StatisticsCollector {
* *
* @param shutdownTimeout Time in milli-seconds to wait for shutdown before * @param shutdownTimeout Time in milli-seconds to wait for shutdown before
* killing the collection process. * killing the collection process.
* @throws java.lang.InterruptedException thrown if Threads are interrupted.
*/ */
public void shutDown(int shutdownTimeout) throws InterruptedException { public void shutDown(int shutdownTimeout) throws InterruptedException {
_isRunning = false; _isRunning = false;

@ -12,9 +12,11 @@ package org.rocksdb;
*/ */
public abstract class TableFormatConfig { public abstract class TableFormatConfig {
/** /**
* This function should only be called by Options.setTableFormatConfig(), * <p>This function should only be called by Options.setTableFormatConfig(),
* which will create a c++ shared-pointer to the c++ TableFactory * which will create a c++ shared-pointer to the c++ TableFactory
* that associated with the Java TableFormatConfig. * that associated with the Java TableFormatConfig.</p>
*
* @return native handle address to native table instance.
*/ */
abstract protected long newTableFactoryHandle(); abstract protected long newTableFactoryHandle();
} }

@ -23,11 +23,19 @@ package org.rocksdb;
* external synchronization. * external synchronization.
*/ */
public class WriteBatch extends RocksObject { public class WriteBatch extends RocksObject {
/**
* Constructs a WriteBatch instance.
*/
public WriteBatch() { public WriteBatch() {
super(); super();
newWriteBatch(0); newWriteBatch(0);
} }
/**
* Constructs a WriteBatch instance with a given size.
*
* @param reserved_bytes reserved size for WriteBatch
*/
public WriteBatch(int reserved_bytes) { public WriteBatch(int reserved_bytes) {
nativeHandle_ = 0; nativeHandle_ = 0;
newWriteBatch(reserved_bytes); newWriteBatch(reserved_bytes);
@ -35,19 +43,29 @@ public class WriteBatch extends RocksObject {
/** /**
* Returns the number of updates in the batch. * Returns the number of updates in the batch.
*
* @return number of items in WriteBatch
*/ */
public native int count(); public native int count();
/** /**
* Store the mapping "key-&gt;value" in the database. * <p>Store the mapping "key-&gt;value" in the database.</p>
*
* @param key the specified key to be inserted.
* @param value the value associated with the specified key.
*/ */
public void put(byte[] key, byte[] value) { public void put(byte[] key, byte[] value) {
put(key, key.length, value, value.length); put(key, key.length, value, value.length);
} }
/** /**
* Store the mapping "key-&gt;value" within given column * <p>Store the mapping "key-&gt;value" within given column
* family. * family.</p>
*
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
* instance
* @param key the specified key to be inserted.
* @param value the value associated with the specified key.
*/ */
public void put(ColumnFamilyHandle columnFamilyHandle, public void put(ColumnFamilyHandle columnFamilyHandle,
byte[] key, byte[] value) { byte[] key, byte[] value) {
@ -56,16 +74,25 @@ public class WriteBatch extends RocksObject {
} }
/** /**
* Merge "value" with the existing value of "key" in the database. * <p>Merge "value" with the existing value of "key" in the database.
* "key-&gt;merge(existing, value)" * "key-&gt;merge(existing, value)"</p>
*
* @param key the specified key to be merged.
* @param value the value to be merged with the current value for
* the specified key.
*/ */
public void merge(byte[] key, byte[] value) { public void merge(byte[] key, byte[] value) {
merge(key, key.length, value, value.length); merge(key, key.length, value, value.length);
} }
/** /**
* Merge "value" with the existing value of "key" in given column family. * <p>Merge "value" with the existing value of "key" in given column family.
* "key-&gt;merge(existing, value)" * "key-&gt;merge(existing, value)"</p>
*
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
* @param key the specified key to be merged.
* @param value the value to be merged with the current value for
* the specified key.
*/ */
public void merge(ColumnFamilyHandle columnFamilyHandle, public void merge(ColumnFamilyHandle columnFamilyHandle,
byte[] key, byte[] value) { byte[] key, byte[] value) {
@ -74,14 +101,19 @@ public class WriteBatch extends RocksObject {
} }
/** /**
* If the database contains a mapping for "key", erase it. Else do nothing. * <p>If the database contains a mapping for "key", erase it. Else do nothing.</p>
*
* @param key Key to delete within database
*/ */
public void remove(byte[] key) { public void remove(byte[] key) {
remove(key, key.length); remove(key, key.length);
} }
/** /**
* If column family contains a mapping for "key", erase it. Else do nothing. * <p>If column family contains a mapping for "key", erase it. Else do nothing.</p>
*
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
* @param key Key to delete within database
*/ */
public void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key) { public void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key) {
remove(key, key.length, columnFamilyHandle.nativeHandle_); remove(key, key.length, columnFamilyHandle.nativeHandle_);
@ -98,6 +130,8 @@ public class WriteBatch extends RocksObject {
* *
* Example application: add timestamps to the transaction log for use in * Example application: add timestamps to the transaction log for use in
* replication. * replication.
*
* @param blob binary object to be inserted
*/ */
public void putLogData(byte[] blob) { public void putLogData(byte[] blob) {
putLogData(blob, blob.length); putLogData(blob, blob.length);
@ -166,6 +200,9 @@ public class WriteBatch extends RocksObject {
* iteration is halted. Otherwise, it continues * iteration is halted. Otherwise, it continues
* iterating. The default implementation always * iterating. The default implementation always
* returns true. * returns true.
*
* @return boolean value indicating if the
* iteration is halted.
*/ */
public boolean shouldContinue() { public boolean shouldContinue() {
return true; return true;

@ -12,6 +12,9 @@ package org.rocksdb;
* c++ side memory before a WriteOptions instance runs out of scope. * c++ side memory before a WriteOptions instance runs out of scope.
*/ */
public class WriteOptions extends RocksObject { public class WriteOptions extends RocksObject {
/**
* Construct WriteOptions instance.
*/
public WriteOptions() { public WriteOptions() {
super(); super();
newWriteOptions(); newWriteOptions();
@ -64,6 +67,8 @@ public class WriteOptions extends RocksObject {
* crash semantics as the "write()" system call. A DB write * crash semantics as the "write()" system call. A DB write
* with sync==true has similar crash semantics to a "write()" * with sync==true has similar crash semantics to a "write()"
* system call followed by "fdatasync()". * system call followed by "fdatasync()".
*
* @return boolean value indicating if sync is active.
*/ */
public boolean sync() { public boolean sync() {
return sync(nativeHandle_); return sync(nativeHandle_);
@ -85,6 +90,8 @@ public class WriteOptions extends RocksObject {
/** /**
* If true, writes will not first go to the write ahead log, * If true, writes will not first go to the write ahead log,
* and the write may got lost after a crash. * and the write may got lost after a crash.
*
* @return boolean value indicating if WAL is disabled.
*/ */
public boolean disableWAL() { public boolean disableWAL() {
return disableWAL(nativeHandle_); return disableWAL(nativeHandle_);

@ -36,6 +36,8 @@ public abstract class AbstractComparatorTest {
* *
* @param db_path A path where we can store database * @param db_path A path where we can store database
* files temporarily * files temporarily
*
* @throws java.io.IOException if IO error happens.
*/ */
public void testRoundtrip(final Path db_path) throws IOException { public void testRoundtrip(final Path db_path) throws IOException {

@ -14,6 +14,8 @@ import java.util.Random;
public class PlatformRandomHelper { public class PlatformRandomHelper {
/** /**
* Determine if OS is 32-Bit/64-Bit * Determine if OS is 32-Bit/64-Bit
*
* @return boolean value indicating if operating system is 64 Bit.
*/ */
public static boolean isOs64Bit(){ public static boolean isOs64Bit(){
boolean is64Bit = false; boolean is64Bit = false;
@ -27,6 +29,8 @@ public class PlatformRandomHelper {
/** /**
* Factory to get a platform specific Random instance * Factory to get a platform specific Random instance
*
* @return {@link java.util.Random} instance.
*/ */
public static Random getPlatformSpecificRandomFactory(){ public static Random getPlatformSpecificRandomFactory(){
if (isOs64Bit()) { if (isOs64Bit()) {

@ -5,17 +5,17 @@ public class Environment {
private static String ARCH = System.getProperty("os.arch").toLowerCase(); private static String ARCH = System.getProperty("os.arch").toLowerCase();
public static boolean isWindows() { public static boolean isWindows() {
return (OS.indexOf("win") >= 0); return (OS.contains("win"));
} }
public static boolean isMac() { public static boolean isMac() {
return (OS.indexOf("mac") >= 0); return (OS.contains("mac"));
} }
public static boolean isUnix() { public static boolean isUnix() {
return (OS.indexOf("nix") >= 0 || return (OS.contains("nix") ||
OS.indexOf("nux") >= 0 || OS.contains("nux") ||
OS.indexOf("aix") >= 0); OS.contains("aix"));
} }
public static boolean is64Bit() { public static boolean is64Bit() {

Loading…
Cancel
Save