2014-04-02 22:14:55 +02:00
|
|
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
|
|
package org.rocksdb;
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
import java.util.*;
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
import java.io.IOException;
|
2014-04-30 20:54:02 +02:00
|
|
|
import org.rocksdb.util.Environment;
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A RocksDB is a persistent ordered map from keys to values. It is safe for
|
|
|
|
* concurrent access from multiple threads without any external synchronization.
|
|
|
|
* All methods of this class could potentially throw RocksDBException, which
|
2014-10-03 11:50:40 +02:00
|
|
|
* indicates sth wrong at the RocksDB library side and the call failed.
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
*/
|
2014-05-01 10:44:46 +02:00
|
|
|
public class RocksDB extends RocksObject {
|
2014-11-12 19:49:13 +01:00
|
|
|
public static final String DEFAULT_COLUMN_FAMILY = "default";
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
public static final int NOT_FOUND = -1;
|
2014-04-30 20:54:02 +02:00
|
|
|
|
2014-08-18 23:03:46 +02:00
|
|
|
static {
|
2014-09-23 03:20:02 +02:00
|
|
|
RocksDB.loadLibrary();
|
2014-08-18 23:03:46 +02:00
|
|
|
}
|
|
|
|
|
2014-04-30 20:54:02 +02:00
|
|
|
/**
|
|
|
|
* Loads the necessary library files.
|
|
|
|
* Calling this method twice will have no effect.
|
2014-09-23 19:31:55 +02:00
|
|
|
* By default the method extracts the shared library for loading at
|
|
|
|
* java.io.tmpdir, however, you can override this temporary location by
|
|
|
|
* setting the environment variable ROCKSDB_SHAREDLIB_DIR.
|
2014-04-30 20:54:02 +02:00
|
|
|
*/
|
|
|
|
public static synchronized void loadLibrary() {
|
2014-09-23 03:20:02 +02:00
|
|
|
String tmpDir = System.getenv("ROCKSDB_SHAREDLIB_DIR");
|
2014-04-30 20:54:02 +02:00
|
|
|
// loading possibly necessary libraries.
|
2014-12-02 14:29:00 +01:00
|
|
|
for (CompressionType compressionType : CompressionType.values()) {
|
2014-04-30 20:54:02 +02:00
|
|
|
try {
|
2014-12-02 14:29:00 +01:00
|
|
|
if (compressionType.getLibraryName() != null) {
|
|
|
|
System.loadLibrary(compressionType.getLibraryName());
|
|
|
|
}
|
2014-04-30 20:54:02 +02:00
|
|
|
} catch (UnsatisfiedLinkError e) {
|
|
|
|
// since it may be optional, we ignore its loading failure here.
|
|
|
|
}
|
|
|
|
}
|
2014-08-18 23:03:46 +02:00
|
|
|
try
|
|
|
|
{
|
2014-11-16 00:41:01 +01:00
|
|
|
NativeLibraryLoader.getInstance().loadLibraryFromJar(tmpDir);
|
2014-08-18 23:03:46 +02:00
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
2014-09-09 02:44:52 +02:00
|
|
|
throw new RuntimeException("Unable to load the RocksDB shared library" + e);
|
2014-08-18 23:03:46 +02:00
|
|
|
}
|
2014-04-30 20:54:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to load the necessary library files from the given list of
|
|
|
|
* directories.
|
|
|
|
*
|
|
|
|
* @param paths a list of strings where each describes a directory
|
|
|
|
* of a library.
|
|
|
|
*/
|
|
|
|
public static synchronized void loadLibrary(List<String> paths) {
|
2014-12-02 14:29:00 +01:00
|
|
|
for (CompressionType compressionType : CompressionType.values()) {
|
|
|
|
if (compressionType.equals(CompressionType.NO_COMPRESSION)) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-04-30 20:54:02 +02:00
|
|
|
for (String path : paths) {
|
|
|
|
try {
|
2014-12-02 14:29:00 +01:00
|
|
|
System.load(path + "/" + Environment.getSharedLibraryName(
|
|
|
|
compressionType.getLibraryName()));
|
2014-04-30 20:54:02 +02:00
|
|
|
break;
|
|
|
|
} catch (UnsatisfiedLinkError e) {
|
|
|
|
// since they are optional, we ignore loading fails.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
boolean success = false;
|
|
|
|
UnsatisfiedLinkError err = null;
|
|
|
|
for (String path : paths) {
|
|
|
|
try {
|
|
|
|
System.load(path + "/" + Environment.getJniLibraryName("rocksdbjni"));
|
|
|
|
success = true;
|
|
|
|
break;
|
|
|
|
} catch (UnsatisfiedLinkError e) {
|
|
|
|
err = e;
|
|
|
|
}
|
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
if (!success) {
|
2014-04-30 20:54:02 +02:00
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
/**
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance given
|
2014-04-02 01:59:05 +02:00
|
|
|
* the path to the database using the default options w/ createIfMissing
|
|
|
|
* set to true.
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
*
|
|
|
|
* @param path the path to the rocksdb.
|
2014-10-13 10:34:52 +02:00
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified
|
|
|
|
* {@link RocksDB} can not be opened.
|
2014-04-02 01:59:05 +02:00
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-03 11:50:40 +02:00
|
|
|
* @see Options#setCreateIfMissing(boolean)
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
*/
|
|
|
|
public static RocksDB open(String path) throws RocksDBException {
|
2014-04-14 22:42:36 +02:00
|
|
|
// This allows to use the rocksjni default Options instead of
|
|
|
|
// the c++ one.
|
|
|
|
Options options = new Options();
|
2014-11-07 23:31:38 +01:00
|
|
|
options.setCreateIfMissing(true);
|
2014-06-22 22:27:22 +02:00
|
|
|
return open(options, path);
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance given
|
|
|
|
* the path to the database using the specified options and db path and a list
|
|
|
|
* of column family names.
|
|
|
|
* <p>
|
|
|
|
* If opened in read write mode every existing column family name must be passed
|
|
|
|
* within the list to this method.</p>
|
|
|
|
* <p>
|
|
|
|
* If opened in read-only mode only a subset of existing column families must
|
|
|
|
* be passed to this method.</p>
|
|
|
|
* <p>
|
|
|
|
* Options instance *should* not be disposed before all DBs using this options
|
|
|
|
* instance have been closed. If user doesn't call options dispose explicitly,
|
|
|
|
* then this options instance will be GC'd automatically</p>
|
|
|
|
* <p>
|
|
|
|
* ColumnFamily handles are disposed when the RocksDB instance is disposed.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param path the path to the rocksdb.
|
2014-10-31 23:39:14 +01:00
|
|
|
* @param columnFamilyDescriptors list of column family descriptors
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
|
|
|
|
* on open.
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified
|
|
|
|
* {@link RocksDB} can not be opened.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-11-05 12:50:26 +01:00
|
|
|
* @see DBOptions#setCreateIfMissing(boolean)
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2014-10-31 23:39:14 +01:00
|
|
|
public static RocksDB open(String path,
|
|
|
|
List<ColumnFamilyDescriptor> columnFamilyDescriptors,
|
2014-10-13 10:34:52 +02:00
|
|
|
List<ColumnFamilyHandle> columnFamilyHandles) throws RocksDBException {
|
|
|
|
// This allows to use the rocksjni default Options instead of
|
|
|
|
// the c++ one.
|
2014-11-05 12:50:26 +01:00
|
|
|
DBOptions options = new DBOptions();
|
2014-10-31 23:39:14 +01:00
|
|
|
return open(options, path, columnFamilyDescriptors, columnFamilyHandles);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
2014-04-02 01:59:05 +02:00
|
|
|
/**
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance given
|
|
|
|
* the path to the database using the specified options and db path.
|
2014-08-25 23:22:55 +02:00
|
|
|
*
|
2014-10-13 10:34:52 +02:00
|
|
|
* <p>
|
2014-07-10 08:13:28 +02:00
|
|
|
* Options instance *should* not be disposed before all DBs using this options
|
|
|
|
* instance have been closed. If user doesn't call options dispose explicitly,
|
2014-10-13 10:34:52 +02:00
|
|
|
* then this options instance will be GC'd automatically.</p>
|
|
|
|
* <p>
|
2014-07-10 08:13:28 +02:00
|
|
|
* Options instance can be re-used to open multiple DBs if DB statistics is
|
|
|
|
* not used. If DB statistics are required, then its recommended to open DB
|
|
|
|
* with new Options instance as underlying native statistics instance does not
|
2014-10-13 10:34:52 +02:00
|
|
|
* use any locks to prevent concurrent updates.</p>
|
|
|
|
*
|
|
|
|
* @param options {@link org.rocksdb.Options} instance.
|
|
|
|
* @param path the path to the rocksdb.
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified
|
|
|
|
* {@link RocksDB} can not be opened.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
|
|
|
*
|
2014-10-13 10:34:52 +02:00
|
|
|
* @see Options#setCreateIfMissing(boolean)
|
2014-04-02 01:59:05 +02:00
|
|
|
*/
|
|
|
|
public static RocksDB open(Options options, String path)
|
|
|
|
throws RocksDBException {
|
[Java] Enable filluniquerandom, readseq, BloomFilter, and 70+ command-line options to DbBenchmark.java
Summary:
* Add filluniquerandom
* Add readseq, implemented using iterator.
* Realize most command-line-arguments from db_bench.cc (70+).
* Some code are commented out as some of the options in Options
not yet have Java bindings.
* Add default option to DbBenchmark.
* RocksDB will now take the ownership of all c++ raw-pointers from Options, which includes a c++ raw-pointer for Filter.
Test Plan: ./jdb_bench.sh --db=/tmp/rocksjava-bench/db --num_levels=6 --key_size=20 --prefix_size=20 --keys_per_prefix=0 --value_size=100 --block_size=4096 --cache_size=17179869184 --cache_numshardbits=6 --compression_ratio=1 --min_level_to_compress=-1 --disable_seek_compaction=1 --hard_rate_limit=2 --write_buffer_size=134217728 --max_write_buffer_number=2 --level0_file_num_compaction_trigger=8 --target_file_size_base=134217728 --max_bytes_for_level_base=1073741824 --disable_wal=0 --wal_dir=/tmp/rocksjava-bench/wal --sync=0 --disable_data_sync=1 --verify_checksum=1 --delete_obsolete_files_period_micros=314572800 --max_grandparent_overlap_factor=10 --max_background_compactions=4 --max_background_flushes=0 --level0_slowdown_writes_trigger=16 --level0_stop_writes_trigger=24 --statistics=0 --stats_per_interval=0 --stats_interval=1048576 --histogram=0 --use_plain_table=1 --open_files=-1 --mmap_read=1 --mmap_write=0 --memtablerep=prefix_hash --bloom_bits=10 --bloom_locality=1 --perf_level=0 --benchmarks=filluniquerandom,readseq,readrandom --use_existing_db=0 --threads=4
Reviewers: haobo, dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett
Reviewed By: haobo
CC: leveldb
Differential Revision: https://reviews.facebook.net/D18267
2014-04-24 22:43:57 +02:00
|
|
|
// when non-default Options is used, keeping an Options reference
|
|
|
|
// in RocksDB can prevent Java to GC during the life-time of
|
|
|
|
// the currently-created RocksDB.
|
2014-04-02 01:59:05 +02:00
|
|
|
RocksDB db = new RocksDB();
|
2014-08-25 23:22:55 +02:00
|
|
|
db.open(options.nativeHandle_, path);
|
|
|
|
|
2014-07-10 08:13:28 +02:00
|
|
|
db.storeOptionsInstance(options);
|
2014-04-02 01:59:05 +02:00
|
|
|
return db;
|
|
|
|
}
|
2014-08-25 23:22:55 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance given
|
|
|
|
* the path to the database using the specified options and db path and a list
|
|
|
|
* of column family names.
|
|
|
|
* <p>
|
|
|
|
* If opened in read write mode every existing column family name must be passed
|
|
|
|
* within the list to this method.</p>
|
|
|
|
* <p>
|
|
|
|
* If opened in read-only mode only a subset of existing column families must
|
|
|
|
* be passed to this method.</p>
|
|
|
|
* <p>
|
|
|
|
* Options instance *should* not be disposed before all DBs using this options
|
|
|
|
* instance have been closed. If user doesn't call options dispose explicitly,
|
|
|
|
* then this options instance will be GC'd automatically.</p>
|
|
|
|
* <p>
|
|
|
|
* Options instance can be re-used to open multiple DBs if DB statistics is
|
|
|
|
* not used. If DB statistics are required, then its recommended to open DB
|
|
|
|
* with new Options instance as underlying native statistics instance does not
|
|
|
|
* use any locks to prevent concurrent updates.</p>
|
|
|
|
* <p>
|
|
|
|
* ColumnFamily handles are disposed when the RocksDB instance is disposed.</p>
|
|
|
|
*
|
2014-11-05 12:50:26 +01:00
|
|
|
* @param options {@link org.rocksdb.DBOptions} instance.
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param path the path to the rocksdb.
|
2014-10-31 23:39:14 +01:00
|
|
|
* @param columnFamilyDescriptors list of column family descriptors
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
|
|
|
|
* on open.
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified
|
|
|
|
* {@link RocksDB} can not be opened.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
|
|
|
*
|
2014-11-05 12:50:26 +01:00
|
|
|
* @see DBOptions#setCreateIfMissing(boolean)
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2014-11-05 12:50:26 +01:00
|
|
|
public static RocksDB open(DBOptions options, String path,
|
2014-10-31 23:39:14 +01:00
|
|
|
List<ColumnFamilyDescriptor> columnFamilyDescriptors,
|
2014-10-13 10:34:52 +02:00
|
|
|
List<ColumnFamilyHandle> columnFamilyHandles)
|
|
|
|
throws RocksDBException {
|
|
|
|
RocksDB db = new RocksDB();
|
|
|
|
List<Long> cfReferences = db.open(options.nativeHandle_, path,
|
2014-10-31 23:39:14 +01:00
|
|
|
columnFamilyDescriptors, columnFamilyDescriptors.size());
|
2014-11-05 12:50:26 +01:00
|
|
|
for (int i = 0; i < columnFamilyDescriptors.size(); i++) {
|
2014-10-29 18:40:44 +01:00
|
|
|
columnFamilyHandles.add(new ColumnFamilyHandle(db, cfReferences.get(i)));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
db.storeOptionsInstance(options);
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance in
|
|
|
|
* Read-Only mode given the path to the database using the default
|
|
|
|
* options.
|
|
|
|
*
|
|
|
|
* @param path the path to the RocksDB.
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified
|
|
|
|
* {@link RocksDB} can not be opened.
|
2014-11-08 20:35:35 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public static RocksDB openReadOnly(String path)
|
|
|
|
throws RocksDBException {
|
|
|
|
// This allows to use the rocksjni default Options instead of
|
|
|
|
// the c++ one.
|
|
|
|
Options options = new Options();
|
|
|
|
return openReadOnly(options, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance in
|
|
|
|
* Read-Only mode given the path to the database using the default
|
|
|
|
* options.
|
|
|
|
*
|
|
|
|
* @param path the path to the RocksDB.
|
2014-10-31 23:39:14 +01:00
|
|
|
* @param columnFamilyDescriptors list of column family descriptors
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
|
|
|
|
* on open.
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified
|
|
|
|
* {@link RocksDB} can not be opened.
|
2014-11-08 20:35:35 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2014-10-31 23:39:14 +01:00
|
|
|
public static RocksDB openReadOnly(String path,
|
|
|
|
List<ColumnFamilyDescriptor> columnFamilyDescriptors,
|
2014-10-13 10:34:52 +02:00
|
|
|
List<ColumnFamilyHandle> columnFamilyHandles) throws RocksDBException {
|
|
|
|
// This allows to use the rocksjni default Options instead of
|
|
|
|
// the c++ one.
|
2014-11-05 12:50:26 +01:00
|
|
|
DBOptions options = new DBOptions();
|
2014-10-31 23:39:14 +01:00
|
|
|
return openReadOnly(options, path, columnFamilyDescriptors,
|
|
|
|
columnFamilyHandles);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance in
|
|
|
|
* Read-Only mode given the path to the database using the specified
|
|
|
|
* options and db path.
|
|
|
|
*
|
|
|
|
* Options instance *should* not be disposed before all DBs using this options
|
|
|
|
* instance have been closed. If user doesn't call options dispose explicitly,
|
|
|
|
* then this options instance will be GC'd automatically.
|
|
|
|
*
|
|
|
|
* @param options {@link Options} instance.
|
|
|
|
* @param path the path to the RocksDB.
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified
|
|
|
|
* {@link RocksDB} can not be opened.
|
2014-11-08 20:35:35 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public static RocksDB openReadOnly(Options options, String path)
|
|
|
|
throws RocksDBException {
|
|
|
|
// when non-default Options is used, keeping an Options reference
|
|
|
|
// in RocksDB can prevent Java to GC during the life-time of
|
|
|
|
// the currently-created RocksDB.
|
|
|
|
RocksDB db = new RocksDB();
|
|
|
|
db.openROnly(options.nativeHandle_, path);
|
|
|
|
|
|
|
|
db.storeOptionsInstance(options);
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The factory constructor of RocksDB that opens a RocksDB instance in
|
|
|
|
* Read-Only mode given the path to the database using the specified
|
|
|
|
* options and db path.
|
|
|
|
*
|
|
|
|
* <p>This open method allows to open RocksDB using a subset of available
|
|
|
|
* column families</p>
|
|
|
|
* <p>Options instance *should* not be disposed before all DBs using this
|
|
|
|
* options instance have been closed. If user doesn't call options dispose
|
|
|
|
* explicitly,then this options instance will be GC'd automatically.</p>
|
|
|
|
*
|
2014-11-05 12:50:26 +01:00
|
|
|
* @param options {@link DBOptions} instance.
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param path the path to the RocksDB.
|
2014-10-31 23:39:14 +01:00
|
|
|
* @param columnFamilyDescriptors list of column family descriptors
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param columnFamilyHandles will be filled with ColumnFamilyHandle instances
|
|
|
|
* on open.
|
|
|
|
* @return a {@link RocksDB} instance on success, null if the specified
|
|
|
|
* {@link RocksDB} can not be opened.
|
2014-11-08 20:35:35 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2014-11-05 12:50:26 +01:00
|
|
|
public static RocksDB openReadOnly(DBOptions options, String path,
|
2014-10-31 23:39:14 +01:00
|
|
|
List<ColumnFamilyDescriptor> columnFamilyDescriptors,
|
|
|
|
List<ColumnFamilyHandle> columnFamilyHandles)
|
2014-10-13 10:34:52 +02:00
|
|
|
throws RocksDBException {
|
|
|
|
// when non-default Options is used, keeping an Options reference
|
|
|
|
// in RocksDB can prevent Java to GC during the life-time of
|
|
|
|
// the currently-created RocksDB.
|
|
|
|
RocksDB db = new RocksDB();
|
|
|
|
List<Long> cfReferences = db.openROnly(options.nativeHandle_, path,
|
2014-10-31 23:39:14 +01:00
|
|
|
columnFamilyDescriptors, columnFamilyDescriptors.size());
|
|
|
|
for (int i=0; i<columnFamilyDescriptors.size(); i++) {
|
2014-10-29 18:40:44 +01:00
|
|
|
columnFamilyHandles.add(new ColumnFamilyHandle(db, cfReferences.get(i)));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
db.storeOptionsInstance(options);
|
|
|
|
return db;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Static method to determine all available column families for a
|
|
|
|
* rocksdb database identified by path
|
|
|
|
*
|
|
|
|
* @param options Options for opening the database
|
|
|
|
* @param path Absolute path to rocksdb database
|
2014-11-06 09:25:53 +01:00
|
|
|
* @return List<byte[]> List containing the column family names
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public static List<byte[]> listColumnFamilies(Options options, String path)
|
|
|
|
throws RocksDBException {
|
|
|
|
return RocksDB.listColumnFamilies(options.nativeHandle_, path);
|
|
|
|
}
|
|
|
|
|
2014-11-05 12:50:26 +01:00
|
|
|
private void storeOptionsInstance(DBOptionsInterface options) {
|
2014-07-10 08:13:28 +02:00
|
|
|
options_ = options;
|
|
|
|
}
|
2014-04-02 01:59:05 +02:00
|
|
|
|
[Java] Generalize dis-own native handle and refine dispose framework.
Summary:
1. Move disOwnNativeHandle() function from RocksDB to RocksObject
to allow other RocksObject to use disOwnNativeHandle() when its
ownership of native handle has been transferred.
2. RocksObject now has an abstract implementation of dispose(),
which does the following two things. First, it checks whether
both isOwningNativeHandle() and isInitialized() return true.
If so, it will call the protected abstract function dispose0(),
which all the subclasses of RocksObject should implement. Second,
it sets nativeHandle_ = 0. This redesign ensure all subclasses
of RocksObject have the same dispose behavior.
3. All subclasses of RocksObject now should implement dispose0()
instead of dispose(), and dispose0() will be called only when
isInitialized() returns true.
Test Plan:
make rocksdbjava
make jtest
Reviewers: dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett, haobo
Reviewed By: haobo
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D18801
2014-05-29 03:16:29 +02:00
|
|
|
@Override protected void disposeInternal() {
|
2014-11-02 01:08:41 +01:00
|
|
|
synchronized (this) {
|
|
|
|
assert (isInitialized());
|
|
|
|
disposeInternal(nativeHandle_);
|
|
|
|
}
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|
|
|
|
|
2014-05-01 10:44:46 +02:00
|
|
|
/**
|
|
|
|
* Close the RocksDB instance.
|
|
|
|
* This function is equivalent to dispose().
|
|
|
|
*/
|
|
|
|
public void close() {
|
|
|
|
dispose();
|
|
|
|
}
|
|
|
|
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
/**
|
|
|
|
* Set the database entry for "key" to "value".
|
|
|
|
*
|
|
|
|
* @param key the specified key to be inserted.
|
|
|
|
* @param value the value associated with the specified key.
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
*/
|
|
|
|
public void put(byte[] key, byte[] value) throws RocksDBException {
|
2014-04-03 07:23:04 +02:00
|
|
|
put(nativeHandle_, key, key.length, value, value.length);
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* Set the database entry for "key" to "value" in the specified
|
|
|
|
* column family.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @param key the specified key to be inserted.
|
|
|
|
* @param value the value associated with the specified key.
|
|
|
|
*
|
|
|
|
* throws IllegalArgumentException if column family is not present
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public void put(ColumnFamilyHandle columnFamilyHandle, byte[] key,
|
|
|
|
byte[] value) throws RocksDBException {
|
|
|
|
put(nativeHandle_, key, key.length, value, value.length,
|
|
|
|
columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
2014-04-02 22:14:55 +02:00
|
|
|
/**
|
|
|
|
* Set the database entry for "key" to "value".
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @param writeOpts {@link org.rocksdb.WriteOptions} instance.
|
2014-04-02 22:14:55 +02:00
|
|
|
* @param key the specified key to be inserted.
|
|
|
|
* @param value the value associated with the specified key.
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-04-02 22:14:55 +02:00
|
|
|
*/
|
|
|
|
public void put(WriteOptions writeOpts, byte[] key, byte[] value)
|
|
|
|
throws RocksDBException {
|
2014-04-22 00:52:59 +02:00
|
|
|
put(nativeHandle_, writeOpts.nativeHandle_,
|
|
|
|
key, key.length, value, value.length);
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* Set the database entry for "key" to "value" for the specified
|
|
|
|
* column family.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
2014-11-08 20:35:35 +01:00
|
|
|
* @param writeOpts {@link org.rocksdb.WriteOptions} instance.
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param key the specified key to be inserted.
|
|
|
|
* @param value the value associated with the specified key.
|
|
|
|
*
|
|
|
|
* throws IllegalArgumentException if column family is not present
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
* @see IllegalArgumentException
|
|
|
|
*/
|
|
|
|
public void put(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpts,
|
|
|
|
byte[] key, byte[] value) throws RocksDBException {
|
|
|
|
put(nativeHandle_, writeOpts.nativeHandle_, key, key.length, value, value.length,
|
|
|
|
columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
2014-11-01 01:02:12 +01:00
|
|
|
/**
|
|
|
|
* If the key definitely does not exist in the database, then this method
|
|
|
|
* returns false, else true.
|
|
|
|
*
|
|
|
|
* This check is potentially lighter-weight than invoking DB::Get(). One way
|
|
|
|
* to make this lighter weight is to avoid doing any IOs.
|
|
|
|
*
|
|
|
|
* @param key byte array of a key to search for
|
|
|
|
* @param value StringBuffer instance which is a out parameter if a value is
|
|
|
|
* found in block-cache.
|
|
|
|
* @return boolean value indicating if key does not exist or might exist.
|
|
|
|
*/
|
|
|
|
public boolean keyMayExist(byte[] key, StringBuffer value){
|
|
|
|
return keyMayExist(key, key.length, value);
|
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* If the key definitely does not exist in the database, then this method
|
|
|
|
* returns false, else true.
|
|
|
|
*
|
|
|
|
* This check is potentially lighter-weight than invoking DB::Get(). One way
|
|
|
|
* to make this lighter weight is to avoid doing any IOs.
|
|
|
|
*
|
2014-10-29 18:40:44 +01:00
|
|
|
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param key byte array of a key to search for
|
|
|
|
* @param value StringBuffer instance which is a out parameter if a value is
|
|
|
|
* found in block-cache.
|
|
|
|
* @return boolean value indicating if key does not exist or might exist.
|
|
|
|
*/
|
|
|
|
public boolean keyMayExist(ColumnFamilyHandle columnFamilyHandle,
|
|
|
|
byte[] key, StringBuffer value){
|
|
|
|
return keyMayExist(key, key.length, columnFamilyHandle.nativeHandle_,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2014-11-01 01:02:12 +01:00
|
|
|
/**
|
|
|
|
* If the key definitely does not exist in the database, then this method
|
|
|
|
* returns false, else true.
|
|
|
|
*
|
|
|
|
* This check is potentially lighter-weight than invoking DB::Get(). One way
|
|
|
|
* to make this lighter weight is to avoid doing any IOs.
|
|
|
|
*
|
|
|
|
* @param readOptions {@link ReadOptions} instance
|
|
|
|
* @param key byte array of a key to search for
|
|
|
|
* @param value StringBuffer instance which is a out parameter if a value is
|
|
|
|
* found in block-cache.
|
|
|
|
* @return boolean value indicating if key does not exist or might exist.
|
|
|
|
*/
|
|
|
|
public boolean keyMayExist(ReadOptions readOptions,
|
|
|
|
byte[] key, StringBuffer value){
|
|
|
|
return keyMayExist(readOptions.nativeHandle_,
|
|
|
|
key, key.length, value);
|
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* If the key definitely does not exist in the database, then this method
|
|
|
|
* returns false, else true.
|
|
|
|
*
|
|
|
|
* This check is potentially lighter-weight than invoking DB::Get(). One way
|
|
|
|
* to make this lighter weight is to avoid doing any IOs.
|
|
|
|
*
|
|
|
|
* @param readOptions {@link ReadOptions} instance
|
2014-10-29 18:40:44 +01:00
|
|
|
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param key byte array of a key to search for
|
|
|
|
* @param value StringBuffer instance which is a out parameter if a value is
|
|
|
|
* found in block-cache.
|
|
|
|
* @return boolean value indicating if key does not exist or might exist.
|
|
|
|
*/
|
|
|
|
public boolean keyMayExist(ReadOptions readOptions,
|
|
|
|
ColumnFamilyHandle columnFamilyHandle, byte[] key, StringBuffer value){
|
|
|
|
return keyMayExist(readOptions.nativeHandle_,
|
|
|
|
key, key.length, columnFamilyHandle.nativeHandle_,
|
|
|
|
value);
|
|
|
|
}
|
|
|
|
|
2014-04-09 09:48:20 +02:00
|
|
|
/**
|
|
|
|
* Apply the specified updates to the database.
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
|
|
|
* @param writeOpts WriteOptions instance
|
|
|
|
* @param updates WriteBatch instance
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-04-09 09:48:20 +02:00
|
|
|
*/
|
|
|
|
public void write(WriteOptions writeOpts, WriteBatch updates)
|
|
|
|
throws RocksDBException {
|
|
|
|
write(writeOpts.nativeHandle_, updates.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
/**
|
2014-10-07 01:58:24 +02:00
|
|
|
* Add merge operand for key/value pair.
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
*
|
2014-09-16 22:58:49 +02:00
|
|
|
* @param key the specified key to be merged.
|
2014-11-08 20:35:35 +01:00
|
|
|
* @param value the value to be merged with the current value for
|
2014-09-16 22:58:49 +02:00
|
|
|
* the specified key.
|
2014-11-08 20:35:35 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-09-16 22:58:49 +02:00
|
|
|
*/
|
|
|
|
public void merge(byte[] key, byte[] value) throws RocksDBException {
|
|
|
|
merge(nativeHandle_, key, key.length, value, value.length);
|
|
|
|
}
|
|
|
|
|
2014-10-29 18:40:44 +01:00
|
|
|
/**
|
|
|
|
* Add merge operand for key/value pair in a ColumnFamily.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
|
|
|
|
* @param key the specified key to be merged.
|
2014-11-08 20:35:35 +01:00
|
|
|
* @param value the value to be merged with the current value for
|
2014-10-29 18:40:44 +01:00
|
|
|
* the specified key.
|
2014-11-08 20:35:35 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-29 18:40:44 +01:00
|
|
|
*/
|
|
|
|
public void merge(ColumnFamilyHandle columnFamilyHandle, byte[] key,
|
|
|
|
byte[] value) throws RocksDBException {
|
|
|
|
merge(nativeHandle_, key, key.length, value, value.length,
|
|
|
|
columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
2014-09-16 22:58:49 +02:00
|
|
|
/**
|
2014-10-07 01:58:24 +02:00
|
|
|
* Add merge operand for key/value pair.
|
2014-09-16 22:58:49 +02:00
|
|
|
*
|
2014-10-07 01:58:24 +02:00
|
|
|
* @param writeOpts {@link WriteOptions} for this write.
|
2014-09-16 22:58:49 +02:00
|
|
|
* @param key the specified key to be merged.
|
|
|
|
* @param value the value to be merged with the current value for
|
|
|
|
* the specified key.
|
2014-11-08 20:35:35 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-09-16 22:58:49 +02:00
|
|
|
*/
|
|
|
|
public void merge(WriteOptions writeOpts, byte[] key, byte[] value)
|
|
|
|
throws RocksDBException {
|
|
|
|
merge(nativeHandle_, writeOpts.nativeHandle_,
|
|
|
|
key, key.length, value, value.length);
|
|
|
|
}
|
|
|
|
|
2014-10-29 18:40:44 +01:00
|
|
|
/**
|
|
|
|
* Add merge operand for key/value pair.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link ColumnFamilyHandle} instance
|
|
|
|
* @param writeOpts {@link WriteOptions} for this write.
|
|
|
|
* @param key the specified key to be merged.
|
|
|
|
* @param value the value to be merged with the current value for
|
|
|
|
* the specified key.
|
2014-11-08 20:35:35 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-29 18:40:44 +01:00
|
|
|
*/
|
|
|
|
public void merge(ColumnFamilyHandle columnFamilyHandle,
|
|
|
|
WriteOptions writeOpts, byte[] key, byte[] value)
|
|
|
|
throws RocksDBException {
|
|
|
|
merge(nativeHandle_, writeOpts.nativeHandle_,
|
|
|
|
key, key.length, value, value.length,
|
|
|
|
columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
2014-09-16 22:58:49 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value associated with the specified key within column family*
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
* @param key the key to retrieve the value.
|
|
|
|
* @param value the out-value to receive the retrieved value.
|
|
|
|
* @return The size of the actual value that matches the specified
|
|
|
|
* {@code key} in byte. If the return value is greater than the
|
|
|
|
* length of {@code value}, then it indicates that the size of the
|
|
|
|
* input buffer {@code value} is insufficient and partial result will
|
|
|
|
* be returned. RocksDB.NOT_FOUND will be returned if the value not
|
|
|
|
* found.
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
*/
|
|
|
|
public int get(byte[] key, byte[] value) throws RocksDBException {
|
2014-04-03 07:23:04 +02:00
|
|
|
return get(nativeHandle_, key, key.length, value, value.length);
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* Get the value associated with the specified key within column family.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @param key the key to retrieve the value.
|
|
|
|
* @param value the out-value to receive the retrieved value.
|
|
|
|
* @return The size of the actual value that matches the specified
|
|
|
|
* {@code key} in byte. If the return value is greater than the
|
|
|
|
* length of {@code value}, then it indicates that the size of the
|
|
|
|
* input buffer {@code value} is insufficient and partial result will
|
|
|
|
* be returned. RocksDB.NOT_FOUND will be returned if the value not
|
|
|
|
* found.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public int get(ColumnFamilyHandle columnFamilyHandle, byte[] key, byte[] value)
|
|
|
|
throws RocksDBException, IllegalArgumentException {
|
|
|
|
return get(nativeHandle_, key, key.length, value, value.length,
|
|
|
|
columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
2014-04-22 00:52:59 +02:00
|
|
|
/**
|
|
|
|
* Get the value associated with the specified key.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @param opt {@link org.rocksdb.ReadOptions} instance.
|
2014-04-22 00:52:59 +02:00
|
|
|
* @param key the key to retrieve the value.
|
|
|
|
* @param value the out-value to receive the retrieved value.
|
|
|
|
* @return The size of the actual value that matches the specified
|
|
|
|
* {@code key} in byte. If the return value is greater than the
|
|
|
|
* length of {@code value}, then it indicates that the size of the
|
|
|
|
* input buffer {@code value} is insufficient and partial result will
|
|
|
|
* be returned. RocksDB.NOT_FOUND will be returned if the value not
|
|
|
|
* found.
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-04-22 00:52:59 +02:00
|
|
|
*/
|
|
|
|
public int get(ReadOptions opt, byte[] key, byte[] value)
|
|
|
|
throws RocksDBException {
|
|
|
|
return get(nativeHandle_, opt.nativeHandle_,
|
|
|
|
key, key.length, value, value.length);
|
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* Get the value associated with the specified key within column family.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
2014-11-08 20:35:35 +01:00
|
|
|
* @param opt {@link org.rocksdb.ReadOptions} instance.
|
2014-10-13 10:34:52 +02:00
|
|
|
* @param key the key to retrieve the value.
|
|
|
|
* @param value the out-value to receive the retrieved value.
|
|
|
|
* @return The size of the actual value that matches the specified
|
|
|
|
* {@code key} in byte. If the return value is greater than the
|
|
|
|
* length of {@code value}, then it indicates that the size of the
|
|
|
|
* input buffer {@code value} is insufficient and partial result will
|
|
|
|
* be returned. RocksDB.NOT_FOUND will be returned if the value not
|
|
|
|
* found.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public int get(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt, byte[] key,
|
|
|
|
byte[] value) throws RocksDBException {
|
|
|
|
return get(nativeHandle_, opt.nativeHandle_, key, key.length, value,
|
|
|
|
value.length, columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
2014-04-22 00:52:59 +02:00
|
|
|
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
/**
|
|
|
|
* The simplified version of get which returns a new byte array storing
|
|
|
|
* the value associated with the specified input key if any. null will be
|
|
|
|
* returned if the specified key is not found.
|
|
|
|
*
|
|
|
|
* @param key the key retrieve the value.
|
|
|
|
* @return a byte array storing the value associated with the input key if
|
|
|
|
* any. null if it does not find the specified key.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
*/
|
|
|
|
public byte[] get(byte[] key) throws RocksDBException {
|
2014-04-03 07:23:04 +02:00
|
|
|
return get(nativeHandle_, key, key.length);
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* The simplified version of get which returns a new byte array storing
|
|
|
|
* the value associated with the specified input key if any. null will be
|
|
|
|
* returned if the specified key is not found.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @param key the key retrieve the value.
|
|
|
|
* @return a byte array storing the value associated with the input key if
|
|
|
|
* any. null if it does not find the specified key.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public byte[] get(ColumnFamilyHandle columnFamilyHandle, byte[] key)
|
|
|
|
throws RocksDBException {
|
|
|
|
return get(nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
2014-04-22 00:52:59 +02:00
|
|
|
/**
|
|
|
|
* The simplified version of get which returns a new byte array storing
|
|
|
|
* the value associated with the specified input key if any. null will be
|
|
|
|
* returned if the specified key is not found.
|
|
|
|
*
|
|
|
|
* @param key the key retrieve the value.
|
2014-04-25 22:57:20 +02:00
|
|
|
* @param opt Read options.
|
2014-04-22 00:52:59 +02:00
|
|
|
* @return a byte array storing the value associated with the input key if
|
|
|
|
* any. null if it does not find the specified key.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-04-22 00:52:59 +02:00
|
|
|
*/
|
|
|
|
public byte[] get(ReadOptions opt, byte[] key) throws RocksDBException {
|
|
|
|
return get(nativeHandle_, opt.nativeHandle_, key, key.length);
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* The simplified version of get which returns a new byte array storing
|
|
|
|
* the value associated with the specified input key if any. null will be
|
|
|
|
* returned if the specified key is not found.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @param key the key retrieve the value.
|
|
|
|
* @param opt Read options.
|
|
|
|
* @return a byte array storing the value associated with the input key if
|
|
|
|
* any. null if it does not find the specified key.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public byte[] get(ColumnFamilyHandle columnFamilyHandle, ReadOptions opt,
|
|
|
|
byte[] key) throws RocksDBException {
|
|
|
|
return get(nativeHandle_, opt.nativeHandle_, key, key.length,
|
|
|
|
columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
/**
|
|
|
|
* Returns a map of keys for which values were found in DB.
|
2014-04-26 05:59:16 +02:00
|
|
|
*
|
2014-04-25 22:57:20 +02:00
|
|
|
* @param keys List of keys for which values need to be retrieved.
|
2014-04-26 05:59:16 +02:00
|
|
|
* @return Map where key of map is the key passed by user and value for map
|
2014-04-25 22:57:20 +02:00
|
|
|
* entry is the corresponding value in DB.
|
2014-04-26 05:59:16 +02:00
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-04-25 22:57:20 +02:00
|
|
|
*/
|
|
|
|
public Map<byte[], byte[]> multiGet(List<byte[]> keys)
|
|
|
|
throws RocksDBException {
|
2014-04-29 17:02:52 +02:00
|
|
|
assert(keys.size() != 0);
|
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
List<byte[]> values = multiGet(
|
|
|
|
nativeHandle_, keys, keys.size());
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-11-08 19:19:29 +01:00
|
|
|
Map<byte[], byte[]> keyValueMap = new HashMap<>();
|
2014-04-25 22:57:20 +02:00
|
|
|
for(int i = 0; i < values.size(); i++) {
|
|
|
|
if(values.get(i) == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
keyValueMap.put(keys.get(i), values.get(i));
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
return keyValueMap;
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* Returns a map of keys for which values were found in DB.
|
|
|
|
* <p>
|
|
|
|
* Note: Every key needs to have a related column family name in
|
|
|
|
* {@code columnFamilyHandleList}.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandleList {@link java.util.List} containing
|
|
|
|
* {@link org.rocksdb.ColumnFamilyHandle} instances.
|
|
|
|
* @param keys List of keys for which values need to be retrieved.
|
|
|
|
* @return Map where key of map is the key passed by user and value for map
|
|
|
|
* entry is the corresponding value in DB.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
|
|
|
* @throws IllegalArgumentException thrown if the size of passed keys is not
|
|
|
|
* equal to the amount of passed column family handles.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public Map<byte[], byte[]> multiGet(List<ColumnFamilyHandle> columnFamilyHandleList,
|
|
|
|
List<byte[]> keys) throws RocksDBException, IllegalArgumentException {
|
|
|
|
assert(keys.size() != 0);
|
|
|
|
// Check if key size equals cfList size. If not a exception must be
|
|
|
|
// thrown. If not a Segmentation fault happens.
|
|
|
|
if (keys.size()!=columnFamilyHandleList.size()) {
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"For each key there must be a ColumnFamilyHandle.");
|
|
|
|
}
|
|
|
|
List<byte[]> values = multiGet(nativeHandle_, keys, keys.size(),
|
|
|
|
columnFamilyHandleList);
|
|
|
|
|
2014-11-08 19:19:29 +01:00
|
|
|
Map<byte[], byte[]> keyValueMap = new HashMap<>();
|
2014-10-13 10:34:52 +02:00
|
|
|
for(int i = 0; i < values.size(); i++) {
|
|
|
|
if (values.get(i) == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
keyValueMap.put(keys.get(i), values.get(i));
|
|
|
|
}
|
|
|
|
return keyValueMap;
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
/**
|
|
|
|
* Returns a map of keys for which values were found in DB.
|
2014-04-26 05:59:16 +02:00
|
|
|
*
|
2014-04-25 22:57:20 +02:00
|
|
|
* @param opt Read options.
|
2014-10-03 11:50:40 +02:00
|
|
|
* @param keys of keys for which values need to be retrieved.
|
2014-04-26 05:59:16 +02:00
|
|
|
* @return Map where key of map is the key passed by user and value for map
|
2014-04-25 22:57:20 +02:00
|
|
|
* entry is the corresponding value in DB.
|
2014-04-26 05:59:16 +02:00
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-04-25 22:57:20 +02:00
|
|
|
*/
|
|
|
|
public Map<byte[], byte[]> multiGet(ReadOptions opt, List<byte[]> keys)
|
|
|
|
throws RocksDBException {
|
2014-04-29 17:02:52 +02:00
|
|
|
assert(keys.size() != 0);
|
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
List<byte[]> values = multiGet(
|
|
|
|
nativeHandle_, opt.nativeHandle_, keys, keys.size());
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-11-08 19:19:29 +01:00
|
|
|
Map<byte[], byte[]> keyValueMap = new HashMap<>();
|
2014-04-25 22:57:20 +02:00
|
|
|
for(int i = 0; i < values.size(); i++) {
|
|
|
|
if(values.get(i) == null) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
keyValueMap.put(keys.get(i), values.get(i));
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
return keyValueMap;
|
|
|
|
}
|
2014-04-22 00:52:59 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* Returns a map of keys for which values were found in DB.
|
|
|
|
* <p>
|
|
|
|
* Note: Every key needs to have a related column family name in
|
|
|
|
* {@code columnFamilyHandleList}.
|
|
|
|
* </p>
|
|
|
|
*
|
|
|
|
* @param opt Read options.
|
|
|
|
* @param columnFamilyHandleList {@link java.util.List} containing
|
|
|
|
* {@link org.rocksdb.ColumnFamilyHandle} instances.
|
|
|
|
* @param keys of keys for which values need to be retrieved.
|
|
|
|
* @return Map where key of map is the key passed by user and value for map
|
|
|
|
* entry is the corresponding value in DB.
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
|
|
|
* @throws IllegalArgumentException thrown if the size of passed keys is not
|
|
|
|
* equal to the amount of passed column family handles.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public Map<byte[], byte[]> multiGet(ReadOptions opt,
|
|
|
|
List<ColumnFamilyHandle> columnFamilyHandleList, List<byte[]> keys)
|
|
|
|
throws RocksDBException {
|
|
|
|
assert(keys.size() != 0);
|
|
|
|
// Check if key size equals cfList size. If not a exception must be
|
|
|
|
// thrown. If not a Segmentation fault happens.
|
|
|
|
if (keys.size()!=columnFamilyHandleList.size()){
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
"For each key there must be a ColumnFamilyHandle.");
|
|
|
|
}
|
|
|
|
|
|
|
|
List<byte[]> values = multiGet(nativeHandle_, opt.nativeHandle_,
|
|
|
|
keys, keys.size(), columnFamilyHandleList);
|
|
|
|
|
2014-11-08 19:19:29 +01:00
|
|
|
Map<byte[], byte[]> keyValueMap = new HashMap<>();
|
2014-10-13 10:34:52 +02:00
|
|
|
for(int i = 0; i < values.size(); i++) {
|
|
|
|
if(values.get(i) == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
keyValueMap.put(keys.get(i), values.get(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
return keyValueMap;
|
|
|
|
}
|
|
|
|
|
2014-04-02 22:14:55 +02:00
|
|
|
/**
|
|
|
|
* Remove the database entry (if any) for "key". Returns OK on
|
|
|
|
* success, and a non-OK status on error. It is not an error if "key"
|
|
|
|
* did not exist in the database.
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
|
|
|
* @param key Key to delete within database
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-04-02 22:14:55 +02:00
|
|
|
*/
|
|
|
|
public void remove(byte[] key) throws RocksDBException {
|
2014-04-03 07:23:04 +02:00
|
|
|
remove(nativeHandle_, key, key.length);
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the database entry (if any) for "key". Returns OK on
|
|
|
|
* success, and a non-OK status on error. It is not an error if "key"
|
|
|
|
* did not exist in the database.
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @param key Key to delete within database
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public void remove(ColumnFamilyHandle columnFamilyHandle, byte[] key)
|
|
|
|
throws RocksDBException {
|
|
|
|
remove(nativeHandle_, key, key.length, columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the database entry (if any) for "key". Returns OK on
|
|
|
|
* success, and a non-OK status on error. It is not an error if "key"
|
|
|
|
* did not exist in the database.
|
|
|
|
*
|
|
|
|
* @param writeOpt WriteOptions to be used with delete operation
|
|
|
|
* @param key Key to delete within database
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-04-02 22:14:55 +02:00
|
|
|
*/
|
|
|
|
public void remove(WriteOptions writeOpt, byte[] key)
|
|
|
|
throws RocksDBException {
|
2014-04-03 07:23:04 +02:00
|
|
|
remove(nativeHandle_, writeOpt.nativeHandle_, key, key.length);
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
2014-10-03 21:43:47 +02:00
|
|
|
|
2014-09-24 20:43:35 +02:00
|
|
|
/**
|
2014-10-13 10:34:52 +02:00
|
|
|
* Remove the database entry (if any) for "key". Returns OK on
|
|
|
|
* success, and a non-OK status on error. It is not an error if "key"
|
|
|
|
* did not exist in the database.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @param writeOpt WriteOptions to be used with delete operation
|
|
|
|
* @param key Key to delete within database
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public void remove(ColumnFamilyHandle columnFamilyHandle, WriteOptions writeOpt,
|
|
|
|
byte[] key) throws RocksDBException {
|
|
|
|
remove(nativeHandle_, writeOpt.nativeHandle_, key, key.length,
|
|
|
|
columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
2014-10-03 21:43:47 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* DB implements can export properties about their state
|
|
|
|
* via this method on a per column family level.
|
|
|
|
*
|
|
|
|
* <p>If {@code property} is a valid property understood by this DB
|
|
|
|
* implementation, fills {@code value} with its current value and
|
|
|
|
* returns true. Otherwise returns false.</p>
|
|
|
|
*
|
|
|
|
* <p>Valid property names include:
|
|
|
|
* <ul>
|
2014-11-06 09:25:53 +01:00
|
|
|
* <li>"rocksdb.num-files-at-level<N>" - return the number of files at level <N>,
|
|
|
|
* where <N> is an ASCII representation of a level number (e.g. "0").</li>
|
2014-10-13 10:34:52 +02:00
|
|
|
* <li>"rocksdb.stats" - returns a multi-line string that describes statistics
|
|
|
|
* about the internal operation of the DB.</li>
|
|
|
|
* <li>"rocksdb.sstables" - returns a multi-line string that describes all
|
|
|
|
* of the sstables that make up the db contents.</li>
|
2014-11-06 09:25:53 +01:00
|
|
|
* </ul>
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @param property to be fetched. See above for examples
|
|
|
|
* @return property value
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public String getProperty(ColumnFamilyHandle columnFamilyHandle, String property)
|
|
|
|
throws RocksDBException {
|
|
|
|
return getProperty0(nativeHandle_, columnFamilyHandle.nativeHandle_, property,
|
|
|
|
property.length());
|
|
|
|
}
|
2014-10-03 21:43:47 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* DB implementations can export properties about their state
|
|
|
|
* via this method. If "property" is a valid property understood by this
|
|
|
|
* DB implementation, fills "*value" with its current value and returns
|
|
|
|
* true. Otherwise returns false.
|
|
|
|
*
|
|
|
|
* <p>Valid property names include:
|
|
|
|
* <ul>
|
2014-11-06 09:25:53 +01:00
|
|
|
* <li>"rocksdb.num-files-at-level<N>" - return the number of files at level <N>,
|
|
|
|
* where <N> is an ASCII representation of a level number (e.g. "0").</li>
|
2014-10-13 10:34:52 +02:00
|
|
|
* <li>"rocksdb.stats" - returns a multi-line string that describes statistics
|
|
|
|
* about the internal operation of the DB.</li>
|
|
|
|
* <li>"rocksdb.sstables" - returns a multi-line string that describes all
|
|
|
|
* of the sstables that make up the db contents.</li>
|
2014-11-06 09:25:53 +01:00
|
|
|
*</ul>
|
2014-10-13 10:34:52 +02:00
|
|
|
*
|
|
|
|
* @param property to be fetched. See above for examples
|
|
|
|
* @return property value
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-09-24 20:43:35 +02:00
|
|
|
*/
|
|
|
|
public String getProperty(String property) throws RocksDBException {
|
|
|
|
return getProperty0(nativeHandle_, property, property.length());
|
|
|
|
}
|
2014-04-19 22:05:21 +02:00
|
|
|
|
2014-11-10 12:55:58 +01:00
|
|
|
/**
|
|
|
|
* <p> Similar to GetProperty(), but only works for a subset of properties whose
|
|
|
|
* return value is a numerical value. Return the value as long.</p>
|
|
|
|
*
|
2014-11-17 21:29:05 +01:00
|
|
|
* <p><strong>Note</strong>: As the returned property is of type
|
|
|
|
* {@code uint64_t} on C++ side the returning value can be negative
|
|
|
|
* because Java supports in Java 7 only signed long values.</p>
|
|
|
|
*
|
|
|
|
* <p><strong>Java 7</strong>: To mitigate the problem of the non
|
|
|
|
* existent unsigned long tpye, values should be encapsulated using
|
|
|
|
* {@link java.math.BigInteger} to reflect the correct value. The correct
|
|
|
|
* behavior is guaranteed if {@code 2^64} is added to negative values.</p>
|
|
|
|
*
|
|
|
|
* <p><strong>Java 8</strong>: In Java 8 the value should be treated as
|
|
|
|
* unsigned long using provided methods of type {@link Long}.</p>
|
|
|
|
*
|
2014-11-10 12:55:58 +01:00
|
|
|
* @param property to be fetched.
|
|
|
|
*
|
2014-11-17 21:29:05 +01:00
|
|
|
* @return numerical property value.
|
2014-11-10 12:55:58 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException if an error happens in the underlying native code.
|
|
|
|
*/
|
|
|
|
public long getLongProperty(String property) throws RocksDBException {
|
|
|
|
return getLongProperty(nativeHandle_, property, property.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p> Similar to GetProperty(), but only works for a subset of properties whose
|
|
|
|
* return value is a numerical value. Return the value as long.</p>
|
|
|
|
*
|
2014-11-17 21:29:05 +01:00
|
|
|
* <p><strong>Note</strong>: As the returned property is of type
|
|
|
|
* {@code uint64_t} on C++ side the returning value can be negative
|
|
|
|
* because Java supports in Java 7 only signed long values.</p>
|
|
|
|
*
|
|
|
|
* <p><strong>Java 7</strong>: To mitigate the problem of the non
|
|
|
|
* existent unsigned long tpye, values should be encapsulated using
|
|
|
|
* {@link java.math.BigInteger} to reflect the correct value. The correct
|
|
|
|
* behavior is guaranteed if {@code 2^64} is added to negative values.</p>
|
|
|
|
*
|
|
|
|
* <p><strong>Java 8</strong>: In Java 8 the value should be treated as
|
|
|
|
* unsigned long using provided methods of type {@link Long}.</p>
|
|
|
|
*
|
2014-11-10 12:55:58 +01:00
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @param property to be fetched.
|
|
|
|
*
|
2014-11-17 21:29:05 +01:00
|
|
|
* @return numerical property value
|
2014-11-10 12:55:58 +01:00
|
|
|
*
|
|
|
|
* @throws RocksDBException if an error happens in the underlying native code.
|
|
|
|
*/
|
|
|
|
public long getLongProperty(ColumnFamilyHandle columnFamilyHandle, String property)
|
|
|
|
throws RocksDBException {
|
|
|
|
return getLongProperty(nativeHandle_, columnFamilyHandle.nativeHandle_, property,
|
|
|
|
property.length());
|
|
|
|
}
|
|
|
|
|
2014-04-19 22:13:01 +02:00
|
|
|
/**
|
|
|
|
* Return a heap-allocated iterator over the contents of the database.
|
|
|
|
* The result of newIterator() is initially invalid (caller must
|
|
|
|
* call one of the Seek methods on the iterator before using it).
|
2014-04-19 22:21:06 +02:00
|
|
|
*
|
2014-04-19 22:13:01 +02:00
|
|
|
* Caller should close the iterator when it is no longer needed.
|
|
|
|
* The returned iterator should be closed before this db is closed.
|
2014-04-19 22:21:06 +02:00
|
|
|
*
|
|
|
|
* @return instance of iterator object.
|
2014-04-19 22:13:01 +02:00
|
|
|
*/
|
2014-05-12 20:02:25 +02:00
|
|
|
public RocksIterator newIterator() {
|
2014-10-27 20:55:57 +01:00
|
|
|
return new RocksIterator(this, iterator0(nativeHandle_));
|
2014-04-19 12:26:22 +02:00
|
|
|
}
|
2014-04-02 22:14:55 +02:00
|
|
|
|
2014-10-13 20:48:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Return a handle to the current DB state. Iterators created with
|
|
|
|
* this handle will all observe a stable snapshot of the current DB
|
|
|
|
* state. The caller must call ReleaseSnapshot(result) when the
|
|
|
|
* snapshot is no longer needed.</p>
|
|
|
|
*
|
|
|
|
* <p>nullptr will be returned if the DB fails to take a snapshot or does
|
|
|
|
* not support snapshot.</p>
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @return Snapshot {@link Snapshot} instance
|
2014-10-13 20:48:44 +02:00
|
|
|
*/
|
|
|
|
public Snapshot getSnapshot() {
|
|
|
|
long snapshotHandle = getSnapshot(nativeHandle_);
|
|
|
|
if (snapshotHandle != 0) {
|
|
|
|
return new Snapshot(snapshotHandle);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release a previously acquired snapshot. The caller must not
|
|
|
|
* use "snapshot" after this call.
|
|
|
|
*
|
|
|
|
* @param snapshot {@link Snapshot} instance
|
|
|
|
*/
|
|
|
|
public void releaseSnapshot(final Snapshot snapshot) {
|
|
|
|
if (snapshot != null) {
|
|
|
|
releaseSnapshot(nativeHandle_, snapshot.nativeHandle_);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/**
|
|
|
|
* Return a heap-allocated iterator over the contents of the database.
|
|
|
|
* The result of newIterator() is initially invalid (caller must
|
|
|
|
* call one of the Seek methods on the iterator before using it).
|
|
|
|
*
|
|
|
|
* Caller should close the iterator when it is no longer needed.
|
|
|
|
* The returned iterator should be closed before this db is closed.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
* @return instance of iterator object.
|
|
|
|
*/
|
|
|
|
public RocksIterator newIterator(ColumnFamilyHandle columnFamilyHandle) {
|
2014-10-27 20:55:57 +01:00
|
|
|
return new RocksIterator(this, iterator0(nativeHandle_,
|
|
|
|
columnFamilyHandle.nativeHandle_));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns iterators from a consistent database state across multiple
|
|
|
|
* column families. Iterators are heap allocated and need to be deleted
|
|
|
|
* before the db is deleted
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandleList {@link java.util.List} containing
|
|
|
|
* {@link org.rocksdb.ColumnFamilyHandle} instances.
|
|
|
|
* @return {@link java.util.List} containing {@link org.rocksdb.RocksIterator}
|
|
|
|
* instances
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public List<RocksIterator> newIterators(
|
|
|
|
List<ColumnFamilyHandle> columnFamilyHandleList) throws RocksDBException {
|
|
|
|
List<RocksIterator> iterators =
|
2014-11-08 19:19:29 +01:00
|
|
|
new ArrayList<>(columnFamilyHandleList.size());
|
2014-10-13 10:34:52 +02:00
|
|
|
|
|
|
|
long[] iteratorRefs = iterators(nativeHandle_, columnFamilyHandleList);
|
|
|
|
for (int i=0; i<columnFamilyHandleList.size(); i++){
|
2014-10-27 20:55:57 +01:00
|
|
|
iterators.add(new RocksIterator(this, iteratorRefs[i]));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
return iterators;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new column family with the name columnFamilyName and
|
|
|
|
* allocates a ColumnFamilyHandle within an internal structure.
|
|
|
|
* The ColumnFamilyHandle is automatically disposed with DB disposal.
|
|
|
|
*
|
2014-10-31 23:39:14 +01:00
|
|
|
* @param columnFamilyDescriptor column family to be created.
|
2014-11-08 20:35:35 +01:00
|
|
|
* @return {@link org.rocksdb.ColumnFamilyHandle} instance.
|
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2014-10-31 23:39:14 +01:00
|
|
|
public ColumnFamilyHandle createColumnFamily(
|
|
|
|
ColumnFamilyDescriptor columnFamilyDescriptor)
|
2014-10-13 10:34:52 +02:00
|
|
|
throws RocksDBException {
|
2014-10-29 18:40:44 +01:00
|
|
|
return new ColumnFamilyHandle(this, createColumnFamily(nativeHandle_,
|
2014-10-31 23:39:14 +01:00
|
|
|
columnFamilyDescriptor));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Drops the column family identified by columnFamilyName. Internal
|
|
|
|
* handles to this column family will be disposed. If the column family
|
|
|
|
* is not known removal will fail.
|
|
|
|
*
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle}
|
|
|
|
* instance
|
|
|
|
*
|
2014-11-08 20:35:35 +01:00
|
|
|
* @throws RocksDBException thrown if error happens in underlying
|
|
|
|
* native library.
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
|
|
|
public void dropColumnFamily(ColumnFamilyHandle columnFamilyHandle)
|
|
|
|
throws RocksDBException, IllegalArgumentException {
|
|
|
|
// throws RocksDBException if something goes wrong
|
|
|
|
dropColumnFamily(nativeHandle_, columnFamilyHandle.nativeHandle_);
|
2014-11-02 01:08:41 +01:00
|
|
|
// After the drop the native handle is not valid anymore
|
|
|
|
columnFamilyHandle.nativeHandle_ = 0;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
2014-11-09 20:09:39 +01:00
|
|
|
/**
|
|
|
|
* <p>Flush all memory table data.</p>
|
|
|
|
*
|
|
|
|
* <p>Note: it must be ensured that the FlushOptions instance
|
|
|
|
* is not GC'ed before this method finishes. If the wait parameter is
|
|
|
|
* set to false, flush processing is asynchronous.</p>
|
|
|
|
*
|
|
|
|
* @param flushOptions {@link org.rocksdb.FlushOptions} instance.
|
|
|
|
* @throws RocksDBException thrown if an error occurs within the native
|
|
|
|
* part of the library.
|
|
|
|
*/
|
|
|
|
public void flush(FlushOptions flushOptions)
|
|
|
|
throws RocksDBException {
|
|
|
|
flush(nativeHandle_, flushOptions.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* <p>Flush all memory table data.</p>
|
|
|
|
*
|
|
|
|
* <p>Note: it must be ensured that the FlushOptions instance
|
|
|
|
* is not GC'ed before this method finishes. If the wait parameter is
|
|
|
|
* set to false, flush processing is asynchronous.</p>
|
|
|
|
*
|
|
|
|
* @param flushOptions {@link org.rocksdb.FlushOptions} instance.
|
|
|
|
* @param columnFamilyHandle {@link org.rocksdb.ColumnFamilyHandle} instance.
|
|
|
|
* @throws RocksDBException thrown if an error occurs within the native
|
|
|
|
* part of the library.
|
|
|
|
*/
|
|
|
|
public void flush(FlushOptions flushOptions,
|
|
|
|
ColumnFamilyHandle columnFamilyHandle) throws RocksDBException {
|
|
|
|
flush(nativeHandle_, flushOptions.nativeHandle_,
|
|
|
|
columnFamilyHandle.nativeHandle_);
|
|
|
|
}
|
|
|
|
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
/**
|
|
|
|
* Private constructor.
|
|
|
|
*/
|
2014-04-18 02:28:51 +02:00
|
|
|
protected RocksDB() {
|
2014-05-01 10:44:46 +02:00
|
|
|
super();
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// native methods
|
2014-04-18 02:28:51 +02:00
|
|
|
protected native void open(
|
2014-08-25 23:22:55 +02:00
|
|
|
long optionsHandle, String path) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native List<Long> open(long optionsHandle, String path,
|
2014-10-31 23:39:14 +01:00
|
|
|
List<ColumnFamilyDescriptor> columnFamilyDescriptors,
|
|
|
|
int columnFamilyDescriptorsLength)
|
2014-10-13 10:34:52 +02:00
|
|
|
throws RocksDBException;
|
|
|
|
protected native static List<byte[]> listColumnFamilies(
|
|
|
|
long optionsHandle, String path) throws RocksDBException;
|
|
|
|
protected native void openROnly(
|
|
|
|
long optionsHandle, String path) throws RocksDBException;
|
|
|
|
protected native List<Long> openROnly(
|
2014-10-31 23:39:14 +01:00
|
|
|
long optionsHandle, String path,
|
|
|
|
List<ColumnFamilyDescriptor> columnFamilyDescriptors,
|
|
|
|
int columnFamilyDescriptorsLength) throws RocksDBException;
|
2014-04-18 02:28:51 +02:00
|
|
|
protected native void put(
|
2014-04-03 07:23:04 +02:00
|
|
|
long handle, byte[] key, int keyLen,
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
byte[] value, int valueLen) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native void put(
|
|
|
|
long handle, byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen, long cfHandle) throws RocksDBException;
|
2014-04-18 02:28:51 +02:00
|
|
|
protected native void put(
|
2014-04-03 07:23:04 +02:00
|
|
|
long handle, long writeOptHandle,
|
|
|
|
byte[] key, int keyLen,
|
2014-04-02 22:14:55 +02:00
|
|
|
byte[] value, int valueLen) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native void put(
|
|
|
|
long handle, long writeOptHandle,
|
|
|
|
byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen, long cfHandle) throws RocksDBException;
|
2014-04-18 02:28:51 +02:00
|
|
|
protected native void write(
|
2014-04-09 09:48:20 +02:00
|
|
|
long writeOptHandle, long batchHandle) throws RocksDBException;
|
2014-11-01 01:02:12 +01:00
|
|
|
protected native boolean keyMayExist(byte[] key, int keyLen,
|
|
|
|
StringBuffer stringBuffer);
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native boolean keyMayExist(byte[] key, int keyLen,
|
|
|
|
long cfHandle, StringBuffer stringBuffer);
|
2014-11-01 01:02:12 +01:00
|
|
|
protected native boolean keyMayExist(long optionsHandle, byte[] key, int keyLen,
|
|
|
|
StringBuffer stringBuffer);
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native boolean keyMayExist(long optionsHandle, byte[] key, int keyLen,
|
|
|
|
long cfHandle, StringBuffer stringBuffer);
|
2014-09-16 22:58:49 +02:00
|
|
|
protected native void merge(
|
|
|
|
long handle, byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen) throws RocksDBException;
|
2014-10-29 18:40:44 +01:00
|
|
|
protected native void merge(
|
|
|
|
long handle, byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen, long cfHandle) throws RocksDBException;
|
2014-09-16 22:58:49 +02:00
|
|
|
protected native void merge(
|
|
|
|
long handle, long writeOptHandle,
|
|
|
|
byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen) throws RocksDBException;
|
2014-10-29 18:40:44 +01:00
|
|
|
protected native void merge(
|
|
|
|
long handle, long writeOptHandle,
|
|
|
|
byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen, long cfHandle) throws RocksDBException;
|
2014-04-18 02:28:51 +02:00
|
|
|
protected native int get(
|
2014-04-03 07:23:04 +02:00
|
|
|
long handle, byte[] key, int keyLen,
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
byte[] value, int valueLen) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native int get(
|
|
|
|
long handle, byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen, long cfHandle) throws RocksDBException;
|
2014-04-22 00:52:59 +02:00
|
|
|
protected native int get(
|
|
|
|
long handle, long readOptHandle, byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native int get(
|
|
|
|
long handle, long readOptHandle, byte[] key, int keyLen,
|
|
|
|
byte[] value, int valueLen, long cfHandle) throws RocksDBException;
|
2014-04-25 22:57:20 +02:00
|
|
|
protected native List<byte[]> multiGet(
|
|
|
|
long dbHandle, List<byte[]> keys, int keysCount);
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native List<byte[]> multiGet(
|
|
|
|
long dbHandle, List<byte[]> keys, int keysCount, List<ColumnFamilyHandle>
|
|
|
|
cfHandles);
|
2014-04-25 22:57:20 +02:00
|
|
|
protected native List<byte[]> multiGet(
|
|
|
|
long dbHandle, long rOptHandle, List<byte[]> keys, int keysCount);
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native List<byte[]> multiGet(
|
|
|
|
long dbHandle, long rOptHandle, List<byte[]> keys, int keysCount,
|
|
|
|
List<ColumnFamilyHandle> cfHandles);
|
2014-04-18 02:28:51 +02:00
|
|
|
protected native byte[] get(
|
2014-04-03 07:23:04 +02:00
|
|
|
long handle, byte[] key, int keyLen) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native byte[] get(
|
|
|
|
long handle, byte[] key, int keyLen, long cfHandle) throws RocksDBException;
|
2014-04-22 00:52:59 +02:00
|
|
|
protected native byte[] get(
|
|
|
|
long handle, long readOptHandle,
|
|
|
|
byte[] key, int keyLen) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native byte[] get(
|
|
|
|
long handle, long readOptHandle,
|
|
|
|
byte[] key, int keyLen, long cfHandle) throws RocksDBException;
|
2014-04-18 02:28:51 +02:00
|
|
|
protected native void remove(
|
2014-04-03 07:23:04 +02:00
|
|
|
long handle, byte[] key, int keyLen) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native void remove(
|
|
|
|
long handle, byte[] key, int keyLen, long cfHandle) throws RocksDBException;
|
2014-04-18 02:28:51 +02:00
|
|
|
protected native void remove(
|
2014-04-03 07:23:04 +02:00
|
|
|
long handle, long writeOptHandle,
|
|
|
|
byte[] key, int keyLen) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native void remove(
|
|
|
|
long handle, long writeOptHandle,
|
|
|
|
byte[] key, int keyLen, long cfHandle) throws RocksDBException;
|
2014-09-24 20:43:35 +02:00
|
|
|
protected native String getProperty0(long nativeHandle,
|
|
|
|
String property, int propertyLength) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native String getProperty0(long nativeHandle, long cfHandle,
|
|
|
|
String property, int propertyLength) throws RocksDBException;
|
2014-11-10 12:55:58 +01:00
|
|
|
protected native long getLongProperty(long nativeHandle,
|
|
|
|
String property, int propertyLength) throws RocksDBException;
|
|
|
|
protected native long getLongProperty(long nativeHandle, long cfHandle,
|
|
|
|
String property, int propertyLength) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
protected native long iterator0(long handle);
|
|
|
|
protected native long iterator0(long handle, long cfHandle);
|
|
|
|
protected native long[] iterators(long handle,
|
|
|
|
List<ColumnFamilyHandle> columnFamilyNames) throws RocksDBException;
|
2014-10-13 20:48:44 +02:00
|
|
|
protected native long getSnapshot(long nativeHandle);
|
|
|
|
protected native void releaseSnapshot(
|
|
|
|
long nativeHandle, long snapshotHandle);
|
[Java] Generalize dis-own native handle and refine dispose framework.
Summary:
1. Move disOwnNativeHandle() function from RocksDB to RocksObject
to allow other RocksObject to use disOwnNativeHandle() when its
ownership of native handle has been transferred.
2. RocksObject now has an abstract implementation of dispose(),
which does the following two things. First, it checks whether
both isOwningNativeHandle() and isInitialized() return true.
If so, it will call the protected abstract function dispose0(),
which all the subclasses of RocksObject should implement. Second,
it sets nativeHandle_ = 0. This redesign ensure all subclasses
of RocksObject have the same dispose behavior.
3. All subclasses of RocksObject now should implement dispose0()
instead of dispose(), and dispose0() will be called only when
isInitialized() returns true.
Test Plan:
make rocksdbjava
make jtest
Reviewers: dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett, haobo
Reviewed By: haobo
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D18801
2014-05-29 03:16:29 +02:00
|
|
|
private native void disposeInternal(long handle);
|
2014-10-31 23:39:14 +01:00
|
|
|
private native long createColumnFamily(long handle,
|
|
|
|
ColumnFamilyDescriptor columnFamilyDescriptor) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
private native void dropColumnFamily(long handle, long cfHandle) throws RocksDBException;
|
2014-11-09 20:09:39 +01:00
|
|
|
private native void flush(long handle, long flushOptHandle)
|
|
|
|
throws RocksDBException;
|
|
|
|
private native void flush(long handle, long flushOptHandle,
|
|
|
|
long cfHandle) throws RocksDBException;
|
2014-10-13 10:34:52 +02:00
|
|
|
|
2014-11-05 12:50:26 +01:00
|
|
|
protected DBOptionsInterface options_;
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 22:19:21 +01:00
|
|
|
}
|