2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
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 file implements the "bridge" between Java and C++ and enables
|
|
|
|
// calling c++ rocksdb::DB methods from Java side.
|
|
|
|
|
2015-01-30 21:05:45 +01:00
|
|
|
#include <jni.h>
|
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
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2016-12-16 20:17:26 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <functional>
|
2015-01-25 22:05:29 +01:00
|
|
|
#include <memory>
|
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
|
|
|
#include <string>
|
2016-02-01 21:00:40 +01:00
|
|
|
#include <tuple>
|
2014-04-25 22:57:20 +02:00
|
|
|
#include <vector>
|
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
|
|
|
|
|
|
|
#include "include/org_rocksdb_RocksDB.h"
|
2014-04-14 22:42:36 +02:00
|
|
|
#include "rocksdb/cache.h"
|
2016-10-21 02:05:32 +02:00
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/options.h"
|
2015-01-25 22:05:29 +01:00
|
|
|
#include "rocksdb/types.h"
|
2015-01-30 21:05:45 +01:00
|
|
|
#include "rocksjni/portal.h"
|
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
|
|
|
|
2016-01-28 15:44:31 +01:00
|
|
|
#ifdef min
|
|
|
|
#undef min
|
|
|
|
#endif
|
|
|
|
|
2014-04-02 22:14:55 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::Open
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong rocksdb_open_helper(
|
|
|
|
JNIEnv* env, jlong jopt_handle, jstring jdb_path,
|
|
|
|
std::function<rocksdb::Status(const rocksdb::Options&, const std::string&,
|
|
|
|
rocksdb::DB**)>
|
|
|
|
open_fn) {
|
2017-02-28 01:26:12 +01:00
|
|
|
const char* db_path = env->GetStringUTFChars(jdb_path, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (db_path == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-20 18:05:41 +01:00
|
|
|
auto* opt = reinterpret_cast<rocksdb::Options*>(jopt_handle);
|
2014-04-14 22:42:36 +02:00
|
|
|
rocksdb::DB* db = nullptr;
|
2016-01-20 18:05:41 +01:00
|
|
|
rocksdb::Status s = open_fn(*opt, db_path, &db);
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2014-04-02 01:59:05 +02:00
|
|
|
env->ReleaseStringUTFChars(jdb_path, db_path);
|
|
|
|
|
|
|
|
if (s.ok()) {
|
2016-01-20 18:05:41 +01:00
|
|
|
return reinterpret_cast<jlong>(db);
|
|
|
|
} else {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
return 0;
|
2014-04-02 01:59:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2016-01-20 18:05:41 +01:00
|
|
|
* Method: open
|
|
|
|
* Signature: (JLjava/lang/String;)J
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_open__JLjava_lang_String_2(JNIEnv* env,
|
|
|
|
jclass /*jcls*/,
|
|
|
|
jlong jopt_handle,
|
|
|
|
jstring jdb_path) {
|
|
|
|
return rocksdb_open_helper(
|
|
|
|
env, jopt_handle, jdb_path,
|
|
|
|
(rocksdb::Status(*)(const rocksdb::Options&, const std::string&,
|
|
|
|
rocksdb::DB**)) &
|
|
|
|
rocksdb::DB::Open);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: openROnly
|
2016-01-20 18:05:41 +01:00
|
|
|
* Signature: (JLjava/lang/String;)J
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2016-01-20 18:05:41 +01:00
|
|
|
jlong Java_org_rocksdb_RocksDB_openROnly__JLjava_lang_String_2(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jclass /*jcls*/, jlong jopt_handle, jstring jdb_path) {
|
|
|
|
return rocksdb_open_helper(env, jopt_handle, jdb_path,
|
|
|
|
[](const rocksdb::Options& options,
|
|
|
|
const std::string& db_path, rocksdb::DB** db) {
|
|
|
|
return rocksdb::DB::OpenForReadOnly(options,
|
|
|
|
db_path, db);
|
|
|
|
});
|
2016-01-20 18:05:41 +01:00
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
jlongArray rocksdb_open_helper(
|
|
|
|
JNIEnv* env, jlong jopt_handle, jstring jdb_path,
|
|
|
|
jobjectArray jcolumn_names, jlongArray jcolumn_options,
|
2016-01-20 18:05:41 +01:00
|
|
|
std::function<rocksdb::Status(
|
2018-04-13 02:55:14 +02:00
|
|
|
const rocksdb::DBOptions&, const std::string&,
|
|
|
|
const std::vector<rocksdb::ColumnFamilyDescriptor>&,
|
|
|
|
std::vector<rocksdb::ColumnFamilyHandle*>*, rocksdb::DB**)>
|
|
|
|
open_fn) {
|
2017-02-28 01:26:12 +01:00
|
|
|
const char* db_path = env->GetStringUTFChars(jdb_path, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (db_path == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
const jsize len_cols = env->GetArrayLength(jcolumn_names);
|
|
|
|
jlong* jco = env->GetLongArrayElements(jcolumn_options, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jco == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->ReleaseStringUTFChars(jdb_path, db_path);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-31 23:39:14 +01:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
std::vector<rocksdb::ColumnFamilyDescriptor> column_families;
|
|
|
|
jboolean has_exception = JNI_FALSE;
|
|
|
|
rocksdb::JniUtil::byteStrings<std::string>(
|
2018-04-13 02:55:14 +02:00
|
|
|
env, jcolumn_names,
|
|
|
|
[](const char* str_data, const size_t str_len) {
|
|
|
|
return std::string(str_data, str_len);
|
|
|
|
},
|
|
|
|
[&jco, &column_families](size_t idx, std::string cf_name) {
|
|
|
|
rocksdb::ColumnFamilyOptions* cf_options =
|
|
|
|
reinterpret_cast<rocksdb::ColumnFamilyOptions*>(jco[idx]);
|
|
|
|
column_families.push_back(
|
|
|
|
rocksdb::ColumnFamilyDescriptor(cf_name, *cf_options));
|
|
|
|
},
|
|
|
|
&has_exception);
|
2014-10-13 10:34:52 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
env->ReleaseLongArrayElements(jcolumn_options, jco, JNI_ABORT);
|
2014-10-13 10:34:52 +02:00
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
if (has_exception == JNI_TRUE) {
|
2017-06-05 20:23:31 +02:00
|
|
|
// exception occurred
|
2017-02-28 01:26:12 +01:00
|
|
|
env->ReleaseStringUTFChars(jdb_path, db_path);
|
|
|
|
return nullptr;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2016-01-20 18:05:41 +01:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* opt = reinterpret_cast<rocksdb::DBOptions*>(jopt_handle);
|
2016-01-20 18:05:41 +01:00
|
|
|
std::vector<rocksdb::ColumnFamilyHandle*> handles;
|
|
|
|
rocksdb::DB* db = nullptr;
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::Status s = open_fn(*opt, db_path, column_families, &handles, &db);
|
2014-10-13 10:34:52 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
// we have now finished with db_path
|
|
|
|
env->ReleaseStringUTFChars(jdb_path, db_path);
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
// check if open operation was successful
|
|
|
|
if (s.ok()) {
|
2018-04-13 02:55:14 +02:00
|
|
|
const jsize resultsLen = 1 + len_cols; // db handle + column family handles
|
2016-07-26 22:18:31 +02:00
|
|
|
std::unique_ptr<jlong[]> results =
|
|
|
|
std::unique_ptr<jlong[]>(new jlong[resultsLen]);
|
2016-01-20 18:05:41 +01:00
|
|
|
results[0] = reinterpret_cast<jlong>(db);
|
2018-04-13 02:55:14 +02:00
|
|
|
for (int i = 1; i <= len_cols; i++) {
|
2016-01-20 18:05:41 +01:00
|
|
|
results[i] = reinterpret_cast<jlong>(handles[i - 1]);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
2016-01-20 18:05:41 +01:00
|
|
|
jlongArray jresults = env->NewLongArray(resultsLen);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jresults == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-07-22 19:17:10 +02:00
|
|
|
env->SetLongArrayRegion(jresults, 0, resultsLen, results.get());
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->DeleteLocalRef(jresults);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-20 18:05:41 +01:00
|
|
|
return jresults;
|
|
|
|
} else {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
2017-02-28 01:26:12 +01:00
|
|
|
return nullptr;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2016-01-20 18:05:41 +01:00
|
|
|
* Method: openROnly
|
|
|
|
* Signature: (JLjava/lang/String;[[B[J)[J
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2016-01-20 18:05:41 +01:00
|
|
|
jlongArray Java_org_rocksdb_RocksDB_openROnly__JLjava_lang_String_2_3_3B_3J(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jclass /*jcls*/, jlong jopt_handle, jstring jdb_path,
|
2016-01-20 18:05:41 +01:00
|
|
|
jobjectArray jcolumn_names, jlongArray jcolumn_options) {
|
2018-04-13 02:55:14 +02:00
|
|
|
return rocksdb_open_helper(
|
|
|
|
env, jopt_handle, jdb_path, jcolumn_names, jcolumn_options,
|
|
|
|
[](const rocksdb::DBOptions& options, const std::string& db_path,
|
|
|
|
const std::vector<rocksdb::ColumnFamilyDescriptor>& column_families,
|
|
|
|
std::vector<rocksdb::ColumnFamilyHandle*>* handles, rocksdb::DB** db) {
|
|
|
|
return rocksdb::DB::OpenForReadOnly(options, db_path, column_families,
|
|
|
|
handles, db);
|
|
|
|
});
|
2016-01-20 18:05:41 +01:00
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
|
2016-01-20 18:05:41 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: open
|
|
|
|
* Signature: (JLjava/lang/String;[[B[J)[J
|
|
|
|
*/
|
|
|
|
jlongArray Java_org_rocksdb_RocksDB_open__JLjava_lang_String_2_3_3B_3J(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jclass /*jcls*/, jlong jopt_handle, jstring jdb_path,
|
2016-01-20 18:05:41 +01:00
|
|
|
jobjectArray jcolumn_names, jlongArray jcolumn_options) {
|
2018-04-13 02:55:14 +02:00
|
|
|
return rocksdb_open_helper(
|
|
|
|
env, jopt_handle, jdb_path, jcolumn_names, jcolumn_options,
|
|
|
|
(rocksdb::Status(*)(const rocksdb::DBOptions&, const std::string&,
|
|
|
|
const std::vector<rocksdb::ColumnFamilyDescriptor>&,
|
|
|
|
std::vector<rocksdb::ColumnFamilyHandle*>*,
|
|
|
|
rocksdb::DB**)) &
|
|
|
|
rocksdb::DB::Open);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::ListColumnFamilies
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: listColumnFamilies
|
2016-02-03 18:47:38 +01:00
|
|
|
* Signature: (JLjava/lang/String;)[[B
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jobjectArray Java_org_rocksdb_RocksDB_listColumnFamilies(JNIEnv* env,
|
|
|
|
jclass /*jclazz*/,
|
|
|
|
jlong jopt_handle,
|
|
|
|
jstring jdb_path) {
|
2014-10-13 10:34:52 +02:00
|
|
|
std::vector<std::string> column_family_names;
|
2017-02-28 01:26:12 +01:00
|
|
|
const char* db_path = env->GetStringUTFChars(jdb_path, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (db_path == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-03 18:47:38 +01:00
|
|
|
auto* opt = reinterpret_cast<rocksdb::Options*>(jopt_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::Status s =
|
|
|
|
rocksdb::DB::ListColumnFamilies(*opt, db_path, &column_family_names);
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
env->ReleaseStringUTFChars(jdb_path, db_path);
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
jobjectArray jcolumn_family_names =
|
|
|
|
rocksdb::JniUtil::stringsBytes(env, column_family_names);
|
|
|
|
|
|
|
|
return jcolumn_family_names;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
2014-04-02 22:14:55 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::Put
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
/**
|
|
|
|
* @return true if the put succeeded, false if a Java Exception was thrown
|
|
|
|
*/
|
|
|
|
bool rocksdb_put_helper(JNIEnv* env, rocksdb::DB* db,
|
2016-09-14 22:12:55 +02:00
|
|
|
const rocksdb::WriteOptions& write_options,
|
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle, jbyteArray jkey,
|
|
|
|
jint jkey_off, jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len) {
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyte* key = new jbyte[jkey_len];
|
|
|
|
env->GetByteArrayRegion(jkey, jkey_off, jkey_len, key);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-12 20:51:08 +02:00
|
|
|
|
2016-09-14 22:12:55 +02:00
|
|
|
jbyte* value = new jbyte[jval_len];
|
|
|
|
env->GetByteArrayRegion(jval, jval_off, jval_len, value);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] value;
|
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
return false;
|
|
|
|
}
|
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-04-02 22:14:55 +02:00
|
|
|
rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len);
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb::Slice value_slice(reinterpret_cast<char*>(value), jval_len);
|
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
|
|
|
rocksdb::Status s;
|
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
s = db->Put(write_options, cf_handle, key_slice, value_slice);
|
|
|
|
} else {
|
|
|
|
// backwards compatibility
|
|
|
|
s = db->Put(write_options, key_slice, value_slice);
|
|
|
|
}
|
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
|
|
|
|
2016-09-12 20:51:08 +02:00
|
|
|
// cleanup
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] value;
|
|
|
|
delete[] key;
|
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
|
|
|
|
|
|
|
if (s.ok()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
return false;
|
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-04-02 22:14:55 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: put
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BII[BII)V
|
2014-04-02 22:14:55 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_put__J_3BII_3BII(JNIEnv* env, jobject /*jdb*/,
|
2016-09-14 22:12:55 +02:00
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-04-02 22:14:55 +02:00
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
|
|
|
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb_put_helper(env, db, default_write_options, nullptr, jkey, jkey_off,
|
|
|
|
jkey_len, jval, jval_off, jval_len);
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
2016-09-12 20:51:08 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: put
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BII[BIIJ)V
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_put__J_3BII_3BIIJ(JNIEnv* env, jobject /*jdb*/,
|
2016-09-14 22:12:55 +02:00
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len,
|
|
|
|
jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb_put_helper(env, db, default_write_options, cf_handle, jkey,
|
|
|
|
jkey_off, jkey_len, jval, jval_off, jval_len);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
2014-04-02 22:14:55 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: put
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BII[BII)V
|
2014-04-02 22:14:55 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_put__JJ_3BII_3BII(JNIEnv* env, jobject /*jdb*/,
|
2016-09-14 22:12:55 +02:00
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jwrite_options_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options_handle);
|
2014-04-02 22:14:55 +02:00
|
|
|
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb_put_helper(env, db, *write_options, nullptr, jkey, jkey_off, jkey_len,
|
|
|
|
jval, jval_off, jval_len);
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: put
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BII[BIIJ)V
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_put__JJ_3BII_3BIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jwrite_options_handle,
|
2016-09-14 22:12:55 +02:00
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len, jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options_handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb_put_helper(env, db, *write_options, cf_handle, jkey, jkey_off,
|
|
|
|
jkey_len, jval, jval_off, jval_len);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-09 09:48:20 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::Write
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2015-01-03 21:19:03 +01:00
|
|
|
* Method: write0
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (JJJ)V
|
2014-04-09 09:48:20 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_write0(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jwrite_options_handle,
|
|
|
|
jlong jwb_handle) {
|
2016-02-01 21:00:40 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options_handle);
|
2015-01-03 21:19:03 +01:00
|
|
|
auto* wb = reinterpret_cast<rocksdb::WriteBatch*>(jwb_handle);
|
|
|
|
|
|
|
|
rocksdb::Status s = db->Write(*write_options, wb);
|
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: write1
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (JJJ)V
|
2015-01-03 21:19:03 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_write1(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jwrite_options_handle,
|
|
|
|
jlong jwbwi_handle) {
|
2016-02-01 21:00:40 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options_handle);
|
2015-01-03 21:19:03 +01:00
|
|
|
auto* wbwi = reinterpret_cast<rocksdb::WriteBatchWithIndex*>(jwbwi_handle);
|
|
|
|
auto* wb = wbwi->GetWriteBatch();
|
2014-04-09 09:48:20 +02:00
|
|
|
|
2015-01-03 21:19:03 +01:00
|
|
|
rocksdb::Status s = db->Write(*write_options, wb);
|
2014-04-09 09:48:20 +02:00
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::KeyMayExist
|
|
|
|
jboolean key_may_exist_helper(JNIEnv* env, rocksdb::DB* db,
|
2018-04-13 02:55:14 +02:00
|
|
|
const rocksdb::ReadOptions& read_opt,
|
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len,
|
|
|
|
jobject jstring_builder, bool* has_exception) {
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyte* key = new jbyte[jkey_len];
|
|
|
|
env->GetByteArrayRegion(jkey, jkey_off, jkey_len, key);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
*has_exception = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len);
|
2017-05-10 19:19:52 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
std::string value;
|
|
|
|
bool value_found = false;
|
2014-11-01 01:02:12 +01:00
|
|
|
bool keyMayExist;
|
|
|
|
if (cf_handle != nullptr) {
|
2018-04-13 02:55:14 +02:00
|
|
|
keyMayExist =
|
|
|
|
db->KeyMayExist(read_opt, cf_handle, key_slice, &value, &value_found);
|
2014-11-01 01:02:12 +01:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
keyMayExist = db->KeyMayExist(read_opt, key_slice, &value, &value_found);
|
2014-11-01 01:02:12 +01:00
|
|
|
}
|
|
|
|
|
2016-09-12 20:51:08 +02:00
|
|
|
// cleanup
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2016-09-12 20:51:08 +02:00
|
|
|
|
|
|
|
// extract the value
|
2014-10-13 10:34:52 +02:00
|
|
|
if (value_found && !value.empty()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
jobject jresult_string_builder =
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::StringBuilderJni::append(env, jstring_builder, value.c_str());
|
|
|
|
if (jresult_string_builder == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
*has_exception = true;
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
|
|
|
*has_exception = false;
|
2014-11-01 01:02:12 +01:00
|
|
|
return static_cast<jboolean>(keyMayExist);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: keyMayExist
|
2017-02-28 01:26:12 +01:00
|
|
|
* Signature: (J[BIILjava/lang/StringBuilder;)Z
|
2014-11-01 01:02:12 +01:00
|
|
|
*/
|
2017-02-28 01:26:12 +01:00
|
|
|
jboolean Java_org_rocksdb_RocksDB_keyMayExist__J_3BIILjava_lang_StringBuilder_2(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jbyteArray jkey,
|
|
|
|
jint jkey_off, jint jkey_len, jobject jstring_builder) {
|
2016-02-01 21:00:40 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
bool has_exception = false;
|
2018-04-13 02:55:14 +02:00
|
|
|
return key_may_exist_helper(env, db, rocksdb::ReadOptions(), nullptr, jkey,
|
|
|
|
jkey_off, jkey_len, jstring_builder,
|
|
|
|
&has_exception);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: keyMayExist
|
2017-02-28 01:26:12 +01:00
|
|
|
* Signature: (J[BIIJLjava/lang/StringBuilder;)Z
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jboolean
|
|
|
|
Java_org_rocksdb_RocksDB_keyMayExist__J_3BIIJLjava_lang_StringBuilder_2(
|
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jbyteArray jkey,
|
|
|
|
jint jkey_off, jint jkey_len, jlong jcf_handle, jobject jstring_builder) {
|
2016-02-01 21:00:40 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
bool has_exception = false;
|
2018-04-13 02:55:14 +02:00
|
|
|
return key_may_exist_helper(env, db, rocksdb::ReadOptions(), cf_handle,
|
|
|
|
jkey, jkey_off, jkey_len, jstring_builder,
|
|
|
|
&has_exception);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2016-02-01 21:00:40 +01:00
|
|
|
return true;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-01 01:02:12 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: keyMayExist
|
2017-02-28 01:26:12 +01:00
|
|
|
* Signature: (JJ[BIILjava/lang/StringBuilder;)Z
|
2014-11-01 01:02:12 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jboolean
|
|
|
|
Java_org_rocksdb_RocksDB_keyMayExist__JJ_3BIILjava_lang_StringBuilder_2(
|
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jread_options_handle,
|
2017-02-28 01:26:12 +01:00
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len, jobject jstring_builder) {
|
2016-02-01 21:00:40 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto& read_options =
|
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jread_options_handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
bool has_exception = false;
|
2018-04-13 02:55:14 +02:00
|
|
|
return key_may_exist_helper(env, db, read_options, nullptr, jkey, jkey_off,
|
|
|
|
jkey_len, jstring_builder, &has_exception);
|
2014-11-01 01:02:12 +01:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: keyMayExist
|
2017-02-28 01:26:12 +01:00
|
|
|
* Signature: (JJ[BIIJLjava/lang/StringBuilder;)Z
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jboolean
|
|
|
|
Java_org_rocksdb_RocksDB_keyMayExist__JJ_3BIIJLjava_lang_StringBuilder_2(
|
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jread_options_handle,
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len, jlong jcf_handle,
|
2017-02-28 01:26:12 +01:00
|
|
|
jobject jstring_builder) {
|
2016-02-01 21:00:40 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto& read_options =
|
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jread_options_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
bool has_exception = false;
|
2018-04-13 02:55:14 +02:00
|
|
|
return key_may_exist_helper(env, db, read_options, cf_handle, jkey,
|
|
|
|
jkey_off, jkey_len, jstring_builder,
|
|
|
|
&has_exception);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2016-02-01 21:00:40 +01:00
|
|
|
return true;
|
2016-02-10 15:21:23 +01:00
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
2014-04-02 22:14:55 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::Get
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
jbyteArray rocksdb_get_helper(JNIEnv* env, rocksdb::DB* db,
|
|
|
|
const rocksdb::ReadOptions& read_opt,
|
|
|
|
rocksdb::ColumnFamilyHandle* column_family_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len) {
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyte* key = new jbyte[jkey_len];
|
|
|
|
env->GetByteArrayRegion(jkey, jkey_off, jkey_len, key);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len);
|
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
|
|
|
|
|
|
|
std::string value;
|
2014-10-13 10:34:52 +02:00
|
|
|
rocksdb::Status s;
|
|
|
|
if (column_family_handle != nullptr) {
|
|
|
|
s = db->Get(read_opt, column_family_handle, key_slice, &value);
|
|
|
|
} else {
|
|
|
|
// backwards compatibility
|
|
|
|
s = db->Get(read_opt, key_slice, &value);
|
|
|
|
}
|
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
|
|
|
|
2016-09-12 20:51:08 +02:00
|
|
|
// cleanup
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
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
|
|
|
|
|
|
|
if (s.IsNotFound()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
jbyteArray jret_value = rocksdb::JniUtil::copyBytes(env, value);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jret_value == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-11-06 23:12:36 +01:00
|
|
|
return jret_value;
|
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
|
|
|
}
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
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
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: get
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BII)[B
|
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
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jbyteArray Java_org_rocksdb_RocksDB_get__J_3BII(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len) {
|
|
|
|
return rocksdb_get_helper(env, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
|
|
|
rocksdb::ReadOptions(), nullptr, jkey, jkey_off,
|
|
|
|
jkey_len);
|
2014-04-22 00:52:59 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: get
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BIIJ)[B
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jbyteArray Java_org_rocksdb_RocksDB_get__J_3BIIJ(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len,
|
|
|
|
jlong jcf_handle) {
|
2014-10-13 10:34:52 +02:00
|
|
|
auto db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
if (cf_handle != nullptr) {
|
2018-04-13 02:55:14 +02:00
|
|
|
return rocksdb_get_helper(env, db_handle, rocksdb::ReadOptions(), cf_handle,
|
|
|
|
jkey, jkey_off, jkey_len);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2017-02-28 01:26:12 +01:00
|
|
|
return nullptr;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-22 00:52:59 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: get
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BII)[B
|
2014-04-22 00:52:59 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jbyteArray Java_org_rocksdb_RocksDB_get__JJ_3BII(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jropt_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len) {
|
|
|
|
return rocksdb_get_helper(
|
|
|
|
env, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle), nullptr, jkey,
|
|
|
|
jkey_off, jkey_len);
|
2014-04-22 00:52:59 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: get
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BIIJ)[B
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyteArray Java_org_rocksdb_RocksDB_get__JJ_3BIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jropt_handle,
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len, jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
auto& ro_opt = *reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2018-04-13 02:55:14 +02:00
|
|
|
return rocksdb_get_helper(env, db_handle, ro_opt, cf_handle, jkey, jkey_off,
|
|
|
|
jkey_len);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2017-02-28 01:26:12 +01:00
|
|
|
return nullptr;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-14 22:12:55 +02:00
|
|
|
jint rocksdb_get_helper(JNIEnv* env, rocksdb::DB* db,
|
|
|
|
const rocksdb::ReadOptions& read_options,
|
|
|
|
rocksdb::ColumnFamilyHandle* column_family_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len,
|
2017-02-28 01:26:12 +01:00
|
|
|
jbyteArray jval, jint jval_off, jint jval_len,
|
|
|
|
bool* has_exception) {
|
2014-03-30 07:00:52 +02:00
|
|
|
static const int kNotFound = -1;
|
|
|
|
static const int kStatusError = -2;
|
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
|
|
|
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyte* key = new jbyte[jkey_len];
|
|
|
|
env->GetByteArrayRegion(jkey, jkey_off, jkey_len, key);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
*has_exception = true;
|
|
|
|
return kStatusError;
|
|
|
|
}
|
|
|
|
rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len);
|
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
|
|
|
|
|
|
|
// TODO(yhchiang): we might save one memory allocation here by adding
|
|
|
|
// a DB::Get() function which takes preallocated jbyte* as input.
|
|
|
|
std::string cvalue;
|
2014-10-13 10:34:52 +02:00
|
|
|
rocksdb::Status s;
|
|
|
|
if (column_family_handle != nullptr) {
|
|
|
|
s = db->Get(read_options, column_family_handle, key_slice, &cvalue);
|
|
|
|
} else {
|
|
|
|
// backwards compatibility
|
|
|
|
s = db->Get(read_options, key_slice, &cvalue);
|
|
|
|
}
|
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
|
|
|
|
2016-09-12 20:51:08 +02:00
|
|
|
// cleanup
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
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
|
|
|
|
|
|
|
if (s.IsNotFound()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
*has_exception = false;
|
2014-03-30 07:00:52 +02:00
|
|
|
return kNotFound;
|
|
|
|
} else if (!s.ok()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
*has_exception = true;
|
2014-03-30 07:00:52 +02:00
|
|
|
// Here since we are throwing a Java exception from c++ side.
|
|
|
|
// As a result, c++ does not know calling this function will in fact
|
|
|
|
// throwing an exception. As a result, the execution flow will
|
|
|
|
// not stop here, and codes after this throw will still be
|
|
|
|
// executed.
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
|
|
|
|
// Return a dummy const value to avoid compilation error, although
|
|
|
|
// java side might not have a chance to get the return value :)
|
|
|
|
return kStatusError;
|
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
|
|
|
}
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
const jint cvalue_len = static_cast<jint>(cvalue.size());
|
|
|
|
const jint length = std::min(jval_len, cvalue_len);
|
2014-03-30 07:00:52 +02:00
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
env->SetByteArrayRegion(
|
|
|
|
jval, jval_off, length,
|
|
|
|
const_cast<jbyte*>(reinterpret_cast<const jbyte*>(cvalue.c_str())));
|
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
*has_exception = true;
|
|
|
|
return kStatusError;
|
|
|
|
}
|
|
|
|
|
|
|
|
*has_exception = false;
|
2014-04-03 08:54:50 +02:00
|
|
|
return cvalue_len;
|
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
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
inline void multi_get_helper_release_keys(
|
|
|
|
JNIEnv* env, std::vector<std::pair<jbyte*, jobject>>& keys_to_free) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto end = keys_to_free.end();
|
|
|
|
for (auto it = keys_to_free.begin(); it != end; ++it) {
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] it->first;
|
2017-02-28 01:26:12 +01:00
|
|
|
env->DeleteLocalRef(it->second);
|
|
|
|
}
|
|
|
|
keys_to_free.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cf multi get
|
|
|
|
*
|
|
|
|
* @return byte[][] of values or nullptr if an exception occurs
|
2017-05-10 19:19:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jobjectArray multi_get_helper(JNIEnv* env, jobject /*jdb*/, rocksdb::DB* db,
|
|
|
|
const rocksdb::ReadOptions& rOpt,
|
|
|
|
jobjectArray jkeys, jintArray jkey_offs,
|
|
|
|
jintArray jkey_lens,
|
|
|
|
jlongArray jcolumn_family_handles) {
|
2014-10-13 10:34:52 +02:00
|
|
|
std::vector<rocksdb::ColumnFamilyHandle*> cf_handles;
|
2016-02-01 21:00:40 +01:00
|
|
|
if (jcolumn_family_handles != nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
const jsize len_cols = env->GetArrayLength(jcolumn_family_handles);
|
|
|
|
|
|
|
|
jlong* jcfh = env->GetLongArrayElements(jcolumn_family_handles, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jcfh == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (jsize i = 0; i < len_cols; i++) {
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcfh[i]);
|
2016-02-01 21:00:40 +01:00
|
|
|
cf_handles.push_back(cf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2016-02-01 21:00:40 +01:00
|
|
|
env->ReleaseLongArrayElements(jcolumn_family_handles, jcfh, JNI_ABORT);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
const jsize len_keys = env->GetArrayLength(jkeys);
|
2016-09-12 20:51:08 +02:00
|
|
|
if (env->EnsureLocalCapacity(len_keys) != 0) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
2016-02-01 21:00:40 +01:00
|
|
|
}
|
2016-09-12 20:51:08 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
jint* jkey_off = env->GetIntArrayElements(jkey_offs, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jkey_off == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jint* jkey_len = env->GetIntArrayElements(jkey_lens, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jkey_len == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->ReleaseIntArrayElements(jkey_offs, jkey_off, JNI_ABORT);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-12 20:51:08 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
std::vector<rocksdb::Slice> keys;
|
|
|
|
std::vector<std::pair<jbyte*, jobject>> keys_to_free;
|
|
|
|
for (jsize i = 0; i < len_keys; i++) {
|
2016-09-12 20:51:08 +02:00
|
|
|
jobject jkey = env->GetObjectArrayElement(jkeys, i);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->ReleaseIntArrayElements(jkey_lens, jkey_len, JNI_ABORT);
|
|
|
|
env->ReleaseIntArrayElements(jkey_offs, jkey_off, JNI_ABORT);
|
|
|
|
multi_get_helper_release_keys(env, keys_to_free);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-12 20:51:08 +02:00
|
|
|
|
|
|
|
jbyteArray jkey_ba = reinterpret_cast<jbyteArray>(jkey);
|
2016-02-01 21:00:40 +01:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
const jint len_key = jkey_len[i];
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyte* key = new jbyte[len_key];
|
|
|
|
env->GetByteArrayRegion(jkey_ba, jkey_off[i], len_key, key);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
env->ReleaseIntArrayElements(jkey_lens, jkey_len, JNI_ABORT);
|
|
|
|
env->ReleaseIntArrayElements(jkey_offs, jkey_off, JNI_ABORT);
|
|
|
|
multi_get_helper_release_keys(env, keys_to_free);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-09-12 20:51:08 +02:00
|
|
|
|
|
|
|
rocksdb::Slice key_slice(reinterpret_cast<char*>(key), len_key);
|
2014-04-25 22:57:20 +02:00
|
|
|
keys.push_back(key_slice);
|
2016-02-01 21:00:40 +01:00
|
|
|
|
2016-09-12 20:51:08 +02:00
|
|
|
keys_to_free.push_back(std::pair<jbyte*, jobject>(key, jkey));
|
2014-04-25 22:57:20 +02:00
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2016-09-12 20:51:08 +02:00
|
|
|
// cleanup jkey_off and jken_len
|
|
|
|
env->ReleaseIntArrayElements(jkey_lens, jkey_len, JNI_ABORT);
|
|
|
|
env->ReleaseIntArrayElements(jkey_offs, jkey_off, JNI_ABORT);
|
|
|
|
|
2014-04-25 22:57:20 +02:00
|
|
|
std::vector<std::string> values;
|
2014-10-13 10:34:52 +02:00
|
|
|
std::vector<rocksdb::Status> s;
|
|
|
|
if (cf_handles.size() == 0) {
|
|
|
|
s = db->MultiGet(rOpt, keys, &values);
|
|
|
|
} else {
|
|
|
|
s = db->MultiGet(rOpt, cf_handles, keys, &values);
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2016-02-01 21:00:40 +01:00
|
|
|
// free up allocated byte arrays
|
2017-02-28 01:26:12 +01:00
|
|
|
multi_get_helper_release_keys(env, keys_to_free);
|
2016-02-01 21:00:40 +01:00
|
|
|
|
|
|
|
// prepare the results
|
|
|
|
jobjectArray jresults =
|
2017-02-28 01:26:12 +01:00
|
|
|
rocksdb::ByteJni::new2dByteArray(env, static_cast<jsize>(s.size()));
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jresults == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-04-26 05:59:16 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
// TODO(AR) it is not clear to me why EnsureLocalCapacity is needed for the
|
|
|
|
// loop as we cleanup references with env->DeleteLocalRef(jentry_value);
|
|
|
|
if (env->EnsureLocalCapacity(static_cast<jint>(s.size())) != 0) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-02-01 21:00:40 +01:00
|
|
|
// add to the jresults
|
2014-10-09 23:16:41 +02:00
|
|
|
for (std::vector<rocksdb::Status>::size_type i = 0; i != s.size(); i++) {
|
|
|
|
if (s[i].ok()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
std::string* value = &values[i];
|
|
|
|
const jsize jvalue_len = static_cast<jsize>(value->size());
|
|
|
|
jbyteArray jentry_value = env->NewByteArray(jvalue_len);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jentry_value == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
env->SetByteArrayRegion(
|
|
|
|
jentry_value, 0, static_cast<jsize>(jvalue_len),
|
2017-03-23 02:05:39 +01:00
|
|
|
const_cast<jbyte*>(reinterpret_cast<const jbyte*>(value->c_str())));
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->DeleteLocalRef(jentry_value);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-01 21:00:40 +01:00
|
|
|
env->SetObjectArrayElement(jresults, static_cast<jsize>(i), jentry_value);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->DeleteLocalRef(jentry_value);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-01 21:00:40 +01:00
|
|
|
env->DeleteLocalRef(jentry_value);
|
2014-04-25 22:57:20 +02:00
|
|
|
}
|
|
|
|
}
|
2016-02-01 21:00:40 +01:00
|
|
|
|
|
|
|
return jresults;
|
2014-04-25 22:57:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: multiGet
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[[B[I[I)[[B
|
2014-04-25 22:57:20 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
jobjectArray Java_org_rocksdb_RocksDB_multiGet__J_3_3B_3I_3I(
|
|
|
|
JNIEnv* env, jobject jdb, jlong jdb_handle, jobjectArray jkeys,
|
|
|
|
jintArray jkey_offs, jintArray jkey_lens) {
|
2014-04-25 22:57:20 +02:00
|
|
|
return multi_get_helper(env, jdb, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::ReadOptions(), jkeys, jkey_offs, jkey_lens,
|
|
|
|
nullptr);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: multiGet
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[[B[I[I[J)[[B
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
jobjectArray Java_org_rocksdb_RocksDB_multiGet__J_3_3B_3I_3I_3J(
|
2016-02-01 21:00:40 +01:00
|
|
|
JNIEnv* env, jobject jdb, jlong jdb_handle, jobjectArray jkeys,
|
2016-09-12 20:51:08 +02:00
|
|
|
jintArray jkey_offs, jintArray jkey_lens,
|
2016-02-01 21:00:40 +01:00
|
|
|
jlongArray jcolumn_family_handles) {
|
2014-10-13 10:34:52 +02:00
|
|
|
return multi_get_helper(env, jdb, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::ReadOptions(), jkeys, jkey_offs, jkey_lens,
|
|
|
|
jcolumn_family_handles);
|
2014-04-25 22:57:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: multiGet
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[[B[I[I)[[B
|
2014-04-25 22:57:20 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
jobjectArray Java_org_rocksdb_RocksDB_multiGet__JJ_3_3B_3I_3I(
|
2016-02-01 21:00:40 +01:00
|
|
|
JNIEnv* env, jobject jdb, jlong jdb_handle, jlong jropt_handle,
|
2016-09-12 20:51:08 +02:00
|
|
|
jobjectArray jkeys, jintArray jkey_offs, jintArray jkey_lens) {
|
2018-04-13 02:55:14 +02:00
|
|
|
return multi_get_helper(
|
|
|
|
env, jdb, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
2016-09-12 20:51:08 +02:00
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle), jkeys, jkey_offs,
|
|
|
|
jkey_lens, nullptr);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: multiGet
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[[B[I[I[J)[[B
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
jobjectArray Java_org_rocksdb_RocksDB_multiGet__JJ_3_3B_3I_3I_3J(
|
2016-02-01 21:00:40 +01:00
|
|
|
JNIEnv* env, jobject jdb, jlong jdb_handle, jlong jropt_handle,
|
2016-09-12 20:51:08 +02:00
|
|
|
jobjectArray jkeys, jintArray jkey_offs, jintArray jkey_lens,
|
|
|
|
jlongArray jcolumn_family_handles) {
|
2018-04-13 02:55:14 +02:00
|
|
|
return multi_get_helper(
|
|
|
|
env, jdb, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
2016-09-12 20:51:08 +02:00
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle), jkeys, jkey_offs,
|
|
|
|
jkey_lens, jcolumn_family_handles);
|
2014-04-25 22:57:20 +02:00
|
|
|
}
|
|
|
|
|
2014-04-22 00:52:59 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: get
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BII[BII)I
|
2014-04-22 00:52:59 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jint Java_org_rocksdb_RocksDB_get__J_3BII_3BII(JNIEnv* env, jobject /*jdb*/,
|
2016-09-14 22:12:55 +02:00
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
bool has_exception = false;
|
2016-09-14 22:12:55 +02:00
|
|
|
return rocksdb_get_helper(env, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
|
|
|
rocksdb::ReadOptions(), nullptr, jkey, jkey_off,
|
2018-04-13 02:55:14 +02:00
|
|
|
jkey_len, jval, jval_off, jval_len, &has_exception);
|
2014-04-22 00:52:59 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: get
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BII[BIIJ)I
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jint Java_org_rocksdb_RocksDB_get__J_3BII_3BIIJ(JNIEnv* env, jobject /*jdb*/,
|
2016-09-14 22:12:55 +02:00
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len,
|
|
|
|
jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
bool has_exception = false;
|
2014-10-13 10:34:52 +02:00
|
|
|
return rocksdb_get_helper(env, db_handle, rocksdb::ReadOptions(), cf_handle,
|
2016-09-14 22:12:55 +02:00
|
|
|
jkey, jkey_off, jkey_len, jval, jval_off,
|
2017-02-28 01:26:12 +01:00
|
|
|
jval_len, &has_exception);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2014-10-13 10:34:52 +02:00
|
|
|
// will never be evaluated
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-22 00:52:59 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: get
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BII[BII)I
|
2014-04-22 00:52:59 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jint Java_org_rocksdb_RocksDB_get__JJ_3BII_3BII(JNIEnv* env, jobject /*jdb*/,
|
2016-09-14 22:12:55 +02:00
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jropt_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
bool has_exception = false;
|
2016-09-14 22:12:55 +02:00
|
|
|
return rocksdb_get_helper(
|
|
|
|
env, reinterpret_cast<rocksdb::DB*>(jdb_handle),
|
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle), nullptr, jkey,
|
2017-02-28 01:26:12 +01:00
|
|
|
jkey_off, jkey_len, jval, jval_off, jval_len, &has_exception);
|
2014-04-22 00:52:59 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: get
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BII[BIIJ)I
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
jint Java_org_rocksdb_RocksDB_get__JJ_3BII_3BIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jropt_handle,
|
2016-09-14 22:12:55 +02:00
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len, jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
auto& ro_opt = *reinterpret_cast<rocksdb::ReadOptions*>(jropt_handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
bool has_exception = false;
|
2016-09-14 22:12:55 +02:00
|
|
|
return rocksdb_get_helper(env, db_handle, ro_opt, cf_handle, jkey, jkey_off,
|
2017-02-28 01:26:12 +01:00
|
|
|
jkey_len, jval, jval_off, jval_len,
|
|
|
|
&has_exception);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2014-10-13 10:34:52 +02:00
|
|
|
// will never be evaluated
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2014-04-02 22:14:55 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::Delete()
|
2017-02-28 01:26:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return true if the delete succeeded, false if a Java Exception was thrown
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
bool rocksdb_delete_helper(JNIEnv* env, rocksdb::DB* db,
|
|
|
|
const rocksdb::WriteOptions& write_options,
|
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len) {
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyte* key = new jbyte[jkey_len];
|
|
|
|
env->GetByteArrayRegion(jkey, jkey_off, jkey_len, key);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-04-02 22:14:55 +02:00
|
|
|
rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len);
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
rocksdb::Status s;
|
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
s = db->Delete(write_options, cf_handle, key_slice);
|
|
|
|
} else {
|
|
|
|
// backwards compatibility
|
|
|
|
s = db->Delete(write_options, key_slice);
|
|
|
|
}
|
2016-09-12 20:51:08 +02:00
|
|
|
|
|
|
|
// cleanup
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2014-04-02 22:14:55 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
if (s.ok()) {
|
|
|
|
return true;
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
return false;
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2016-08-22 20:02:31 +02:00
|
|
|
* Method: delete
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BII)V
|
2014-04-02 22:14:55 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_delete__J_3BII(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle, jbyteArray jkey,
|
|
|
|
jint jkey_off, jint jkey_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-04-02 22:14:55 +02:00
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb_delete_helper(env, db, default_write_options, nullptr, jkey, jkey_off,
|
|
|
|
jkey_len);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2014-04-02 22:14:55 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2016-08-22 20:02:31 +02:00
|
|
|
* Method: delete
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BIIJ)V
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_delete__J_3BIIJ(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle, jbyteArray jkey,
|
|
|
|
jint jkey_off, jint jkey_len,
|
|
|
|
jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb_delete_helper(env, db, default_write_options, cf_handle, jkey,
|
|
|
|
jkey_off, jkey_len);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2016-08-22 20:02:31 +02:00
|
|
|
* Method: delete
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BII)V
|
2014-04-02 22:14:55 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_delete__JJ_3BII(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jwrite_options,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options);
|
2016-09-12 20:51:08 +02:00
|
|
|
rocksdb_delete_helper(env, db, *write_options, nullptr, jkey, jkey_off,
|
2018-04-13 02:55:14 +02:00
|
|
|
jkey_len);
|
2014-04-02 22:14:55 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2016-08-22 20:02:31 +02:00
|
|
|
* Method: delete
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BIIJ)V
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_delete__JJ_3BIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jwrite_options,
|
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len, jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (cf_handle != nullptr) {
|
2016-09-12 20:51:08 +02:00
|
|
|
rocksdb_delete_helper(env, db, *write_options, cf_handle, jkey, jkey_off,
|
2018-04-13 02:55:14 +02:00
|
|
|
jkey_len);
|
2014-10-13 10:34:52 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
2016-08-22 20:02:31 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::SingleDelete()
|
2017-02-28 01:26:12 +01:00
|
|
|
/**
|
|
|
|
* @return true if the single delete succeeded, false if a Java Exception
|
|
|
|
* was thrown
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
bool rocksdb_single_delete_helper(JNIEnv* env, rocksdb::DB* db,
|
|
|
|
const rocksdb::WriteOptions& write_options,
|
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle,
|
|
|
|
jbyteArray jkey, jint jkey_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
jbyte* key = env->GetByteArrayElements(jkey, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (key == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-22 20:02:31 +02:00
|
|
|
rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len);
|
|
|
|
|
|
|
|
rocksdb::Status s;
|
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
s = db->SingleDelete(write_options, cf_handle, key_slice);
|
|
|
|
} else {
|
|
|
|
// backwards compatibility
|
|
|
|
s = db->SingleDelete(write_options, key_slice);
|
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2016-08-22 20:02:31 +02:00
|
|
|
// trigger java unref on key and value.
|
|
|
|
// by passing JNI_ABORT, it will simply release the reference without
|
|
|
|
// copying the result back to the java byte array.
|
|
|
|
env->ReleaseByteArrayElements(jkey, key, JNI_ABORT);
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
if (s.ok()) {
|
|
|
|
return true;
|
2016-08-22 20:02:31 +02:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
return false;
|
2016-08-22 20:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: singleDelete
|
|
|
|
* Signature: (J[BI)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_singleDelete__J_3BI(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey,
|
|
|
|
jint jkey_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2016-08-22 20:02:31 +02:00
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb_single_delete_helper(env, db, default_write_options, nullptr, jkey,
|
|
|
|
jkey_len);
|
2016-08-22 20:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: singleDelete
|
|
|
|
* Signature: (J[BIJ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_singleDelete__J_3BIJ(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey,
|
|
|
|
jint jkey_len,
|
|
|
|
jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2016-08-22 20:02:31 +02:00
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2016-08-22 20:02:31 +02:00
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
rocksdb_single_delete_helper(env, db, default_write_options, cf_handle,
|
2018-04-13 02:55:14 +02:00
|
|
|
jkey, jkey_len);
|
2016-08-22 20:02:31 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2016-08-22 20:02:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: singleDelete
|
|
|
|
* Signature: (JJ[BIJ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_singleDelete__JJ_3BI(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jwrite_options,
|
|
|
|
jbyteArray jkey,
|
|
|
|
jint jkey_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options);
|
2016-08-22 20:02:31 +02:00
|
|
|
rocksdb_single_delete_helper(env, db, *write_options, nullptr, jkey,
|
2018-04-13 02:55:14 +02:00
|
|
|
jkey_len);
|
2016-08-22 20:02:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: singleDelete
|
|
|
|
* Signature: (JJ[BIJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RocksDB_singleDelete__JJ_3BIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jwrite_options,
|
|
|
|
jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2016-08-22 20:02:31 +02:00
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
rocksdb_single_delete_helper(env, db, *write_options, cf_handle, jkey,
|
2018-04-13 02:55:14 +02:00
|
|
|
jkey_len);
|
2016-08-22 20:02:31 +02:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2016-08-22 20:02:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-07 07:13:53 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::DeleteRange()
|
|
|
|
/**
|
|
|
|
* @return true if the delete range succeeded, false if a Java Exception
|
|
|
|
* was thrown
|
|
|
|
*/
|
|
|
|
bool rocksdb_delete_range_helper(JNIEnv* env, rocksdb::DB* db,
|
|
|
|
const rocksdb::WriteOptions& write_options,
|
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle,
|
|
|
|
jbyteArray jbegin_key, jint jbegin_key_off,
|
|
|
|
jint jbegin_key_len, jbyteArray jend_key,
|
|
|
|
jint jend_key_off, jint jend_key_len) {
|
|
|
|
jbyte* begin_key = new jbyte[jbegin_key_len];
|
|
|
|
env->GetByteArrayRegion(jbegin_key, jbegin_key_off, jbegin_key_len,
|
|
|
|
begin_key);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
delete[] begin_key;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rocksdb::Slice begin_key_slice(reinterpret_cast<char*>(begin_key),
|
|
|
|
jbegin_key_len);
|
|
|
|
|
|
|
|
jbyte* end_key = new jbyte[jend_key_len];
|
|
|
|
env->GetByteArrayRegion(jend_key, jend_key_off, jend_key_len, end_key);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
delete[] begin_key;
|
|
|
|
delete[] end_key;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rocksdb::Slice end_key_slice(reinterpret_cast<char*>(end_key), jend_key_len);
|
|
|
|
|
|
|
|
rocksdb::Status s =
|
|
|
|
db->DeleteRange(write_options, cf_handle, begin_key_slice, end_key_slice);
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
delete[] begin_key;
|
|
|
|
delete[] end_key;
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: deleteRange
|
|
|
|
* Signature: (J[BII[BII)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RocksDB_deleteRange__J_3BII_3BII(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jbyteArray jbegin_key,
|
2017-03-07 07:13:53 +01:00
|
|
|
jint jbegin_key_off, jint jbegin_key_len, jbyteArray jend_key,
|
|
|
|
jint jend_key_off, jint jend_key_len) {
|
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
|
|
|
rocksdb_delete_range_helper(env, db, default_write_options, nullptr,
|
|
|
|
jbegin_key, jbegin_key_off, jbegin_key_len,
|
|
|
|
jend_key, jend_key_off, jend_key_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: deleteRange
|
|
|
|
* Signature: (J[BII[BIIJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RocksDB_deleteRange__J_3BII_3BIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jbyteArray jbegin_key,
|
2017-03-07 07:13:53 +01:00
|
|
|
jint jbegin_key_off, jint jbegin_key_len, jbyteArray jend_key,
|
|
|
|
jint jend_key_off, jint jend_key_len, jlong jcf_handle) {
|
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
rocksdb_delete_range_helper(env, db, default_write_options, cf_handle,
|
|
|
|
jbegin_key, jbegin_key_off, jbegin_key_len,
|
|
|
|
jend_key, jend_key_off, jend_key_len);
|
|
|
|
} else {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: deleteRange
|
|
|
|
* Signature: (JJ[BII[BII)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RocksDB_deleteRange__JJ_3BII_3BII(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jwrite_options,
|
2017-03-07 07:13:53 +01:00
|
|
|
jbyteArray jbegin_key, jint jbegin_key_off, jint jbegin_key_len,
|
|
|
|
jbyteArray jend_key, jint jend_key_off, jint jend_key_len) {
|
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options);
|
|
|
|
rocksdb_delete_range_helper(env, db, *write_options, nullptr, jbegin_key,
|
|
|
|
jbegin_key_off, jbegin_key_len, jend_key,
|
|
|
|
jend_key_off, jend_key_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: deleteRange
|
|
|
|
* Signature: (JJ[BII[BIIJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RocksDB_deleteRange__JJ_3BII_3BIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jwrite_options,
|
2017-03-07 07:13:53 +01:00
|
|
|
jbyteArray jbegin_key, jint jbegin_key_off, jint jbegin_key_len,
|
|
|
|
jbyteArray jend_key, jint jend_key_off, jint jend_key_len,
|
|
|
|
jlong jcf_handle) {
|
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
rocksdb_delete_range_helper(env, db, *write_options, cf_handle, jbegin_key,
|
|
|
|
jbegin_key_off, jbegin_key_len, jend_key,
|
|
|
|
jend_key_off, jend_key_len);
|
|
|
|
} else {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 22:58:49 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::Merge
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
/**
|
|
|
|
* @return true if the merge succeeded, false if a Java Exception was thrown
|
|
|
|
*/
|
|
|
|
bool rocksdb_merge_helper(JNIEnv* env, rocksdb::DB* db,
|
2016-09-14 22:12:55 +02:00
|
|
|
const rocksdb::WriteOptions& write_options,
|
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len,
|
|
|
|
jbyteArray jval, jint jval_off, jint jval_len) {
|
2016-09-12 20:51:08 +02:00
|
|
|
jbyte* key = new jbyte[jkey_len];
|
|
|
|
env->GetByteArrayRegion(jkey, jkey_off, jkey_len, key);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
rocksdb::Slice key_slice(reinterpret_cast<char*>(key), jkey_len);
|
|
|
|
|
2017-05-10 19:19:52 +02:00
|
|
|
jbyte* value = new jbyte[jval_len];
|
2016-09-14 22:12:55 +02:00
|
|
|
env->GetByteArrayRegion(jval, jval_off, jval_len, value);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] value;
|
|
|
|
delete[] key;
|
2017-02-28 01:26:12 +01:00
|
|
|
return false;
|
|
|
|
}
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb::Slice value_slice(reinterpret_cast<char*>(value), jval_len);
|
2014-09-16 22:58:49 +02:00
|
|
|
|
2014-10-29 18:40:44 +01:00
|
|
|
rocksdb::Status s;
|
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
s = db->Merge(write_options, cf_handle, key_slice, value_slice);
|
|
|
|
} else {
|
|
|
|
s = db->Merge(write_options, key_slice, value_slice);
|
|
|
|
}
|
2014-09-16 22:58:49 +02:00
|
|
|
|
2016-09-12 20:51:08 +02:00
|
|
|
// cleanup
|
2018-04-13 02:55:14 +02:00
|
|
|
delete[] value;
|
|
|
|
delete[] key;
|
2014-09-16 22:58:49 +02:00
|
|
|
|
|
|
|
if (s.ok()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
return true;
|
2014-09-16 22:58:49 +02:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2014-09-16 22:58:49 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
2017-02-28 01:26:12 +01:00
|
|
|
return false;
|
2014-09-16 22:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: merge
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BII[BII)V
|
2014-09-16 22:58:49 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_merge__J_3BII_3BII(JNIEnv* env, jobject /*jdb*/,
|
2016-09-14 22:12:55 +02:00
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jkey, jint jkey_off,
|
|
|
|
jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-09-16 22:58:49 +02:00
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
|
|
|
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb_merge_helper(env, db, default_write_options, nullptr, jkey, jkey_off,
|
|
|
|
jkey_len, jval, jval_off, jval_len);
|
2014-10-29 18:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: merge
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (J[BII[BIIJ)V
|
2014-10-29 18:40:44 +01:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_merge__J_3BII_3BIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jbyteArray jkey,
|
|
|
|
jint jkey_off, jint jkey_len, jbyteArray jval, jint jval_off, jint jval_len,
|
2016-09-14 22:12:55 +02:00
|
|
|
jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-10-29 18:40:44 +01:00
|
|
|
static const rocksdb::WriteOptions default_write_options =
|
|
|
|
rocksdb::WriteOptions();
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-29 18:40:44 +01:00
|
|
|
if (cf_handle != nullptr) {
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb_merge_helper(env, db, default_write_options, cf_handle, jkey,
|
|
|
|
jkey_off, jkey_len, jval, jval_off, jval_len);
|
2014-10-29 18:40:44 +01:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2014-10-29 18:40:44 +01:00
|
|
|
}
|
2014-09-16 22:58:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: merge
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BII[BII)V
|
2014-09-16 22:58:49 +02:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_merge__JJ_3BII_3BII(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jwrite_options_handle,
|
2016-09-14 22:12:55 +02:00
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options_handle);
|
2014-09-16 22:58:49 +02:00
|
|
|
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb_merge_helper(env, db, *write_options, nullptr, jkey, jkey_off,
|
|
|
|
jkey_len, jval, jval_off, jval_len);
|
2014-10-29 18:40:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: merge
|
2016-09-12 20:51:08 +02:00
|
|
|
* Signature: (JJ[BII[BIIJ)V
|
2014-10-29 18:40:44 +01:00
|
|
|
*/
|
2016-09-12 20:51:08 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_merge__JJ_3BII_3BIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jwrite_options_handle,
|
2016-09-14 22:12:55 +02:00
|
|
|
jbyteArray jkey, jint jkey_off, jint jkey_len, jbyteArray jval,
|
|
|
|
jint jval_off, jint jval_len, jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* write_options =
|
|
|
|
reinterpret_cast<rocksdb::WriteOptions*>(jwrite_options_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-29 18:40:44 +01:00
|
|
|
if (cf_handle != nullptr) {
|
2016-09-14 22:12:55 +02:00
|
|
|
rocksdb_merge_helper(env, db, *write_options, cf_handle, jkey, jkey_off,
|
|
|
|
jkey_len, jval, jval_off, jval_len);
|
2014-10-29 18:40:44 +01:00
|
|
|
} else {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid ColumnFamilyHandle."));
|
2014-10-29 18:40:44 +01:00
|
|
|
}
|
2014-09-16 22:58:49 +02:00
|
|
|
}
|
|
|
|
|
2014-04-02 22:14:55 +02:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::~DB()
|
|
|
|
|
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
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
[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
|
|
|
* Method: disposeInternal
|
2014-05-01 10:44:46 +02:00
|
|
|
* Signature: (J)V
|
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
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_disposeInternal(JNIEnv* /*env*/,
|
|
|
|
jobject /*java_db*/,
|
|
|
|
jlong jhandle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jhandle);
|
|
|
|
assert(db != nullptr);
|
|
|
|
delete db;
|
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-04-19 12:26:22 +02:00
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong rocksdb_iterator_helper(rocksdb::DB* db,
|
|
|
|
rocksdb::ReadOptions read_options,
|
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle) {
|
2015-01-16 23:35:21 +01:00
|
|
|
rocksdb::Iterator* iterator = nullptr;
|
|
|
|
if (cf_handle != nullptr) {
|
|
|
|
iterator = db->NewIterator(read_options, cf_handle);
|
|
|
|
} else {
|
|
|
|
iterator = db->NewIterator(read_options);
|
|
|
|
}
|
|
|
|
return reinterpret_cast<jlong>(iterator);
|
|
|
|
}
|
|
|
|
|
2014-04-19 22:21:06 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2015-01-16 23:35:21 +01:00
|
|
|
* Method: iterator
|
2014-04-19 22:21:06 +02:00
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_iterator__J(JNIEnv* /*env*/, jobject /*jdb*/,
|
|
|
|
jlong db_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
return rocksdb_iterator_helper(db, rocksdb::ReadOptions(), nullptr);
|
2014-04-19 22:05:21 +02:00
|
|
|
}
|
2014-09-24 20:43:35 +02:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2015-01-16 23:35:21 +01:00
|
|
|
* Method: iterator
|
2014-10-13 10:34:52 +02:00
|
|
|
* Signature: (JJ)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_iterator__JJ(JNIEnv* /*env*/, jobject /*jdb*/,
|
|
|
|
jlong db_handle,
|
|
|
|
jlong jread_options_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto& read_options =
|
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jread_options_handle);
|
|
|
|
return rocksdb_iterator_helper(db, read_options, nullptr);
|
2015-01-16 23:35:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: iteratorCF
|
|
|
|
* Signature: (JJ)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_iteratorCF__JJ(JNIEnv* /*env*/, jobject /*jdb*/,
|
|
|
|
jlong db_handle,
|
|
|
|
jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
return rocksdb_iterator_helper(db, rocksdb::ReadOptions(), cf_handle);
|
2015-01-16 23:35:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: iteratorCF
|
|
|
|
* Signature: (JJJ)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_iteratorCF__JJJ(JNIEnv* /*env*/, jobject /*jdb*/,
|
|
|
|
jlong db_handle,
|
|
|
|
jlong jcf_handle,
|
|
|
|
jlong jread_options_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto& read_options =
|
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jread_options_handle);
|
|
|
|
return rocksdb_iterator_helper(db, read_options, cf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: iterators
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[JJ)[J
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlongArray Java_org_rocksdb_RocksDB_iterators(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong db_handle,
|
|
|
|
jlongArray jcolumn_family_handles,
|
|
|
|
jlong jread_options_handle) {
|
2016-02-01 21:00:40 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto& read_options =
|
|
|
|
*reinterpret_cast<rocksdb::ReadOptions*>(jread_options_handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
std::vector<rocksdb::ColumnFamilyHandle*> cf_handles;
|
2016-02-01 21:00:40 +01:00
|
|
|
if (jcolumn_family_handles != nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
const jsize len_cols = env->GetArrayLength(jcolumn_family_handles);
|
|
|
|
jlong* jcfh = env->GetLongArrayElements(jcolumn_family_handles, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jcfh == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (jsize i = 0; i < len_cols; i++) {
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcfh[i]);
|
2016-02-01 21:00:40 +01:00
|
|
|
cf_handles.push_back(cf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2016-02-01 21:00:40 +01:00
|
|
|
env->ReleaseLongArrayElements(jcolumn_family_handles, jcfh, JNI_ABORT);
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
2016-02-01 21:00:40 +01:00
|
|
|
std::vector<rocksdb::Iterator*> iterators;
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::Status s = db->NewIterators(read_options, cf_handles, &iterators);
|
2014-10-13 10:34:52 +02:00
|
|
|
if (s.ok()) {
|
2014-11-11 22:47:22 +01:00
|
|
|
jlongArray jLongArray =
|
|
|
|
env->NewLongArray(static_cast<jsize>(iterators.size()));
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jLongArray == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
for (std::vector<rocksdb::Iterator*>::size_type i = 0; i < iterators.size();
|
|
|
|
i++) {
|
|
|
|
env->SetLongArrayRegion(
|
|
|
|
jLongArray, static_cast<jsize>(i), 1,
|
|
|
|
const_cast<jlong*>(reinterpret_cast<const jlong*>(&iterators[i])));
|
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->DeleteLocalRef(jLongArray);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
return jLongArray;
|
2016-02-01 21:00:40 +01:00
|
|
|
} else {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
2017-02-28 01:26:12 +01:00
|
|
|
return nullptr;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-28 17:37:57 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: getDefaultColumnFamily
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_getDefaultColumnFamily(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jdb_handle) {
|
2014-12-28 17:37:57 +01:00
|
|
|
auto* db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* cf_handle = db_handle->DefaultColumnFamily();
|
|
|
|
return reinterpret_cast<jlong>(cf_handle);
|
|
|
|
}
|
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: createColumnFamily
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[BJ)J
|
2014-10-13 10:34:52 +02:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_createColumnFamily(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jbyteArray jcolumn_name,
|
|
|
|
jlong jcolumn_options) {
|
2014-10-13 10:34:52 +02:00
|
|
|
rocksdb::ColumnFamilyHandle* handle;
|
2017-02-28 01:26:12 +01:00
|
|
|
jboolean has_exception = JNI_FALSE;
|
2018-04-13 02:55:14 +02:00
|
|
|
std::string column_name = rocksdb::JniUtil::byteString<std::string>(
|
|
|
|
env, jcolumn_name,
|
|
|
|
[](const char* str, const size_t len) { return std::string(str, len); },
|
|
|
|
&has_exception);
|
|
|
|
if (has_exception == JNI_TRUE) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception occurred
|
|
|
|
return 0;
|
|
|
|
}
|
2016-02-01 21:00:40 +01:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2016-02-01 21:00:40 +01:00
|
|
|
auto* cfOptions =
|
|
|
|
reinterpret_cast<rocksdb::ColumnFamilyOptions*>(jcolumn_options);
|
2015-01-15 00:26:32 +01:00
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::Status s =
|
|
|
|
db_handle->CreateColumnFamily(*cfOptions, column_name, &handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
return reinterpret_cast<jlong>(handle);
|
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2014-10-13 10:34:52 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: dropColumnFamily
|
|
|
|
* Signature: (JJ)V;
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_dropColumnFamily(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
auto* db_handle = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
rocksdb::Status s = db_handle->DropColumnFamily(cf_handle);
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-13 20:48:44 +02:00
|
|
|
/*
|
|
|
|
* Method: getSnapshot
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_getSnapshot(JNIEnv* /*env*/, jobject /*jdb*/,
|
|
|
|
jlong db_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
2014-10-13 20:48:44 +02:00
|
|
|
const rocksdb::Snapshot* snapshot = db->GetSnapshot();
|
|
|
|
return reinterpret_cast<jlong>(snapshot);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Method: releaseSnapshot
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_releaseSnapshot(JNIEnv* /*env*/, jobject /*jdb*/,
|
|
|
|
jlong db_handle,
|
|
|
|
jlong snapshot_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
|
|
|
auto* snapshot = reinterpret_cast<rocksdb::Snapshot*>(snapshot_handle);
|
2014-10-13 20:48:44 +02:00
|
|
|
db->ReleaseSnapshot(snapshot);
|
|
|
|
}
|
|
|
|
|
2014-09-24 20:43:35 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: getProperty0
|
|
|
|
* Signature: (JLjava/lang/String;I)Ljava/lang/String;
|
|
|
|
*/
|
2014-10-13 10:34:52 +02:00
|
|
|
jstring Java_org_rocksdb_RocksDB_getProperty0__JLjava_lang_String_2I(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong db_handle, jstring jproperty,
|
2014-09-24 20:43:35 +02:00
|
|
|
jint jproperty_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
const char* property = env->GetStringUTFChars(jproperty, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (property == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-09-24 20:43:35 +02:00
|
|
|
rocksdb::Slice property_slice(property, jproperty_len);
|
2014-10-09 23:16:41 +02:00
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
2014-09-24 20:43:35 +02:00
|
|
|
std::string property_value;
|
|
|
|
bool retCode = db->GetProperty(property_slice, &property_value);
|
|
|
|
env->ReleaseStringUTFChars(jproperty, property);
|
2014-10-09 23:16:41 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
if (retCode) {
|
|
|
|
return env->NewStringUTF(property_value.c_str());
|
2014-09-24 20:43:35 +02:00
|
|
|
}
|
2014-10-09 23:16:41 +02:00
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, rocksdb::Status::NotFound());
|
|
|
|
return nullptr;
|
2014-09-24 20:43:35 +02:00
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: getProperty0
|
|
|
|
* Signature: (JJLjava/lang/String;I)Ljava/lang/String;
|
|
|
|
*/
|
|
|
|
jstring Java_org_rocksdb_RocksDB_getProperty0__JJLjava_lang_String_2I(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong db_handle, jlong jcf_handle,
|
2014-10-13 10:34:52 +02:00
|
|
|
jstring jproperty, jint jproperty_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
const char* property = env->GetStringUTFChars(jproperty, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (property == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-13 10:34:52 +02:00
|
|
|
rocksdb::Slice property_slice(property, jproperty_len);
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-10-13 10:34:52 +02:00
|
|
|
std::string property_value;
|
|
|
|
bool retCode = db->GetProperty(cf_handle, property_slice, &property_value);
|
|
|
|
env->ReleaseStringUTFChars(jproperty, property);
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
if (retCode) {
|
|
|
|
return env->NewStringUTF(property_value.c_str());
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, rocksdb::Status::NotFound());
|
|
|
|
return nullptr;
|
2014-10-13 10:34:52 +02:00
|
|
|
}
|
2014-11-09 20:09:39 +01:00
|
|
|
|
2014-11-10 12:55:58 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: getLongProperty
|
|
|
|
* Signature: (JLjava/lang/String;I)L;
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RocksDB_getLongProperty__JLjava_lang_String_2I(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong db_handle, jstring jproperty,
|
2014-11-10 12:55:58 +01:00
|
|
|
jint jproperty_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
const char* property = env->GetStringUTFChars(jproperty, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (property == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return 0;
|
|
|
|
}
|
2014-11-10 12:55:58 +01:00
|
|
|
rocksdb::Slice property_slice(property, jproperty_len);
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
2014-11-10 12:55:58 +01:00
|
|
|
uint64_t property_value = 0;
|
|
|
|
bool retCode = db->GetIntProperty(property_slice, &property_value);
|
|
|
|
env->ReleaseStringUTFChars(jproperty, property);
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
if (retCode) {
|
|
|
|
return property_value;
|
2014-11-10 12:55:58 +01:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, rocksdb::Status::NotFound());
|
|
|
|
return 0;
|
2014-11-10 12:55:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: getLongProperty
|
|
|
|
* Signature: (JJLjava/lang/String;I)L;
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_RocksDB_getLongProperty__JJLjava_lang_String_2I(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong db_handle, jlong jcf_handle,
|
2014-11-10 12:55:58 +01:00
|
|
|
jstring jproperty, jint jproperty_len) {
|
2017-02-28 01:26:12 +01:00
|
|
|
const char* property = env->GetStringUTFChars(jproperty, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (property == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return 0;
|
|
|
|
}
|
2014-11-10 12:55:58 +01:00
|
|
|
rocksdb::Slice property_slice(property, jproperty_len);
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(db_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-11-10 12:55:58 +01:00
|
|
|
uint64_t property_value;
|
|
|
|
bool retCode = db->GetIntProperty(cf_handle, property_slice, &property_value);
|
|
|
|
env->ReleaseStringUTFChars(jproperty, property);
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
if (retCode) {
|
|
|
|
return property_value;
|
2014-11-10 12:55:58 +01:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, rocksdb::Status::NotFound());
|
|
|
|
return 0;
|
2014-11-10 12:55:58 +01:00
|
|
|
}
|
|
|
|
|
2014-11-09 20:09:39 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::Flush
|
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
void rocksdb_flush_helper(JNIEnv* env, rocksdb::DB* db,
|
|
|
|
const rocksdb::FlushOptions& flush_options,
|
|
|
|
rocksdb::ColumnFamilyHandle* column_family_handle) {
|
2014-11-09 20:09:39 +01:00
|
|
|
rocksdb::Status s;
|
|
|
|
if (column_family_handle != nullptr) {
|
|
|
|
s = db->Flush(flush_options, column_family_handle);
|
|
|
|
} else {
|
|
|
|
s = db->Flush(flush_options);
|
|
|
|
}
|
|
|
|
if (!s.ok()) {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
2014-11-09 20:09:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: flush
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_flush__JJ(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jflush_options) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* flush_options =
|
|
|
|
reinterpret_cast<rocksdb::FlushOptions*>(jflush_options);
|
2014-11-09 20:09:39 +01:00
|
|
|
rocksdb_flush_helper(env, db, *flush_options, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: flush
|
|
|
|
* Signature: (JJJ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_flush__JJJ(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle, jlong jflush_options,
|
|
|
|
jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* flush_options =
|
|
|
|
reinterpret_cast<rocksdb::FlushOptions*>(jflush_options);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2014-11-09 20:09:39 +01:00
|
|
|
rocksdb_flush_helper(env, db, *flush_options, cf_handle);
|
|
|
|
}
|
2014-11-17 23:29:52 +01:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::CompactRange - Full
|
|
|
|
|
|
|
|
void rocksdb_compactrange_helper(JNIEnv* env, rocksdb::DB* db,
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle,
|
|
|
|
jboolean jreduce_level, jint jtarget_level,
|
|
|
|
jint jtarget_path_id) {
|
2014-11-17 23:29:52 +01:00
|
|
|
rocksdb::Status s;
|
2015-06-17 23:36:14 +02:00
|
|
|
rocksdb::CompactRangeOptions compact_options;
|
|
|
|
compact_options.change_level = jreduce_level;
|
|
|
|
compact_options.target_level = jtarget_level;
|
|
|
|
compact_options.target_path_id = static_cast<uint32_t>(jtarget_path_id);
|
2014-11-17 23:29:52 +01:00
|
|
|
if (cf_handle != nullptr) {
|
2015-06-17 23:36:14 +02:00
|
|
|
s = db->CompactRange(compact_options, cf_handle, nullptr, nullptr);
|
2014-11-17 23:29:52 +01:00
|
|
|
} else {
|
|
|
|
// backwards compatibility
|
2015-06-17 23:36:14 +02:00
|
|
|
s = db->CompactRange(compact_options, nullptr, nullptr);
|
2014-11-17 23:29:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: compactRange0
|
|
|
|
* Signature: (JZII)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_compactRange0__JZII(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jboolean jreduce_level,
|
|
|
|
jint jtarget_level,
|
|
|
|
jint jtarget_path_id) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb_compactrange_helper(env, db, nullptr, jreduce_level, jtarget_level,
|
|
|
|
jtarget_path_id);
|
2014-11-17 23:29:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: compactRange
|
|
|
|
* Signature: (JZIIJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RocksDB_compactRange__JZIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jboolean jreduce_level,
|
|
|
|
jint jtarget_level, jint jtarget_path_id, jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb_compactrange_helper(env, db, cf_handle, jreduce_level, jtarget_level,
|
|
|
|
jtarget_path_id);
|
2014-11-17 23:29:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::CompactRange - Range
|
|
|
|
|
2017-02-28 01:26:12 +01:00
|
|
|
/**
|
|
|
|
* @return true if the compact range succeeded, false if a Java Exception
|
|
|
|
* was thrown
|
|
|
|
*/
|
|
|
|
bool rocksdb_compactrange_helper(JNIEnv* env, rocksdb::DB* db,
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle,
|
|
|
|
jbyteArray jbegin, jint jbegin_len,
|
|
|
|
jbyteArray jend, jint jend_len,
|
2018-08-17 19:52:58 +02:00
|
|
|
const rocksdb::CompactRangeOptions& compact_options) {
|
2017-02-28 01:26:12 +01:00
|
|
|
jbyte* begin = env->GetByteArrayElements(jbegin, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (begin == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
jbyte* end = env->GetByteArrayElements(jend, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (end == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->ReleaseByteArrayElements(jbegin, begin, JNI_ABORT);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-17 23:29:52 +01:00
|
|
|
const rocksdb::Slice begin_slice(reinterpret_cast<char*>(begin), jbegin_len);
|
|
|
|
const rocksdb::Slice end_slice(reinterpret_cast<char*>(end), jend_len);
|
|
|
|
|
|
|
|
rocksdb::Status s;
|
|
|
|
if (cf_handle != nullptr) {
|
2015-06-17 23:36:14 +02:00
|
|
|
s = db->CompactRange(compact_options, cf_handle, &begin_slice, &end_slice);
|
2014-11-17 23:29:52 +01:00
|
|
|
} else {
|
|
|
|
// backwards compatibility
|
2015-06-17 23:36:14 +02:00
|
|
|
s = db->CompactRange(compact_options, &begin_slice, &end_slice);
|
2014-11-17 23:29:52 +01:00
|
|
|
}
|
|
|
|
|
2017-04-06 22:59:24 +02:00
|
|
|
env->ReleaseByteArrayElements(jend, end, JNI_ABORT);
|
|
|
|
env->ReleaseByteArrayElements(jbegin, begin, JNI_ABORT);
|
2014-11-17 23:29:52 +01:00
|
|
|
|
|
|
|
if (s.ok()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
return true;
|
2014-11-17 23:29:52 +01:00
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2014-11-17 23:29:52 +01:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
2017-02-28 01:26:12 +01:00
|
|
|
return false;
|
2014-11-17 23:29:52 +01:00
|
|
|
}
|
|
|
|
|
2018-08-17 19:52:58 +02:00
|
|
|
/**
|
|
|
|
* @return true if the compact range succeeded, false if a Java Exception
|
|
|
|
* was thrown
|
|
|
|
*/
|
|
|
|
bool rocksdb_compactrange_helper(JNIEnv* env, rocksdb::DB* db,
|
|
|
|
rocksdb::ColumnFamilyHandle* cf_handle,
|
|
|
|
jbyteArray jbegin, jint jbegin_len,
|
|
|
|
jbyteArray jend, jint jend_len,
|
|
|
|
jboolean jreduce_level, jint jtarget_level,
|
|
|
|
jint jtarget_path_id) {
|
|
|
|
rocksdb::CompactRangeOptions compact_options;
|
|
|
|
compact_options.change_level = jreduce_level;
|
|
|
|
compact_options.target_level = jtarget_level;
|
|
|
|
compact_options.target_path_id = static_cast<uint32_t>(jtarget_path_id);
|
|
|
|
|
|
|
|
return rocksdb_compactrange_helper(env, db, cf_handle, jbegin, jbegin_len,
|
|
|
|
jend, jend_len, compact_options);
|
|
|
|
}
|
|
|
|
|
2014-11-17 23:29:52 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: compactRange0
|
|
|
|
* Signature: (J[BI[BIZII)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_compactRange0__J_3BI_3BIZII(
|
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jbyteArray jbegin,
|
|
|
|
jint jbegin_len, jbyteArray jend, jint jend_len, jboolean jreduce_level,
|
2014-11-17 23:29:52 +01:00
|
|
|
jint jtarget_level, jint jtarget_path_id) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb_compactrange_helper(env, db, nullptr, jbegin, jbegin_len, jend,
|
|
|
|
jend_len, jreduce_level, jtarget_level,
|
|
|
|
jtarget_path_id);
|
2014-11-17 23:29:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: compactRange
|
|
|
|
* Signature: (JJ[BI[BIZII)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RocksDB_compactRange__J_3BI_3BIZIIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jbyteArray jbegin,
|
|
|
|
jint jbegin_len, jbyteArray jend, jint jend_len, jboolean jreduce_level,
|
|
|
|
jint jtarget_level, jint jtarget_path_id, jlong jcf_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb_compactrange_helper(env, db, cf_handle, jbegin, jbegin_len, jend,
|
|
|
|
jend_len, jreduce_level, jtarget_level,
|
|
|
|
jtarget_path_id);
|
2014-11-17 23:29:52 +01:00
|
|
|
}
|
2015-01-25 22:05:29 +01:00
|
|
|
|
2018-08-17 19:52:58 +02:00
|
|
|
|
|
|
|
void Java_org_rocksdb_RocksDB_compactRange__J_3BI_3BIJJ(
|
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jbyteArray jbegin,
|
|
|
|
jint jbegin_len, jbyteArray jend, jint jend_len,
|
|
|
|
jlong jcompact_options_handle, jlong jcf_handle) {
|
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
auto* compact_options = reinterpret_cast<rocksdb::CompactRangeOptions*>(jcompact_options_handle);
|
|
|
|
|
|
|
|
rocksdb_compactrange_helper(env, db, cf_handle, jbegin, jbegin_len, jend,
|
|
|
|
jend_len, *compact_options);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-25 22:46:11 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2016-05-07 00:04:13 +02:00
|
|
|
// rocksdb::DB::PauseBackgroundWork
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: pauseBackgroundWork
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_pauseBackgroundWork(JNIEnv* env, jobject /*jobj*/,
|
|
|
|
jlong jdb_handle) {
|
2016-05-07 00:04:13 +02:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto s = db->PauseBackgroundWork();
|
2017-02-28 01:26:12 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
2016-05-07 00:04:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::ContinueBackgroundWork
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: continueBackgroundWork
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_continueBackgroundWork(JNIEnv* env,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jdb_handle) {
|
2016-05-07 00:04:13 +02:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto s = db->ContinueBackgroundWork();
|
2017-02-28 01:26:12 +01:00
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
2016-05-07 00:04:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2015-01-25 22:46:11 +01:00
|
|
|
// rocksdb::DB::GetLatestSequenceNumber
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: getLatestSequenceNumber
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_getLatestSequenceNumber(JNIEnv* /*env*/,
|
|
|
|
jobject /*jdb*/,
|
|
|
|
jlong jdb_handle) {
|
2015-01-25 22:47:29 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2015-01-25 22:46:11 +01:00
|
|
|
return db->GetLatestSequenceNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB enable/disable file deletions
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: enableFileDeletions
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_disableFileDeletions(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle) {
|
2015-01-25 22:47:29 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2015-01-25 22:46:11 +01:00
|
|
|
rocksdb::Status s = db->DisableFileDeletions();
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: enableFileDeletions
|
|
|
|
* Signature: (JZ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_enableFileDeletions(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jboolean jforce) {
|
2015-01-25 22:47:29 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2015-01-25 22:46:11 +01:00
|
|
|
rocksdb::Status s = db->EnableFileDeletions(jforce);
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-25 22:05:29 +01:00
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
// rocksdb::DB::GetUpdatesSince
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: getUpdatesSince
|
|
|
|
* Signature: (JJ)J
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_RocksDB_getUpdatesSince(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle,
|
|
|
|
jlong jsequence_number) {
|
2015-01-25 22:47:29 +01:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
2015-01-25 22:05:29 +01:00
|
|
|
rocksdb::SequenceNumber sequence_number =
|
|
|
|
static_cast<rocksdb::SequenceNumber>(jsequence_number);
|
|
|
|
std::unique_ptr<rocksdb::TransactionLogIterator> iter;
|
|
|
|
rocksdb::Status s = db->GetUpdatesSince(sequence_number, &iter);
|
|
|
|
if (s.ok()) {
|
|
|
|
return reinterpret_cast<jlong>(iter.release());
|
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
|
2015-01-25 22:05:29 +01:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-08-06 21:03:47 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: setOptions
|
|
|
|
* Signature: (JJ[Ljava/lang/String;[Ljava/lang/String;)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_setOptions(JNIEnv* env, jobject /*jdb*/,
|
|
|
|
jlong jdb_handle, jlong jcf_handle,
|
|
|
|
jobjectArray jkeys,
|
|
|
|
jobjectArray jvalues) {
|
2016-08-06 21:03:47 +02:00
|
|
|
const jsize len = env->GetArrayLength(jkeys);
|
|
|
|
assert(len == env->GetArrayLength(jvalues));
|
2017-02-28 01:26:12 +01:00
|
|
|
|
|
|
|
std::unordered_map<std::string, std::string> options_map;
|
|
|
|
for (jsize i = 0; i < len; i++) {
|
2016-08-06 21:03:47 +02:00
|
|
|
jobject jobj_key = env->GetObjectArrayElement(jkeys, i);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-06 21:03:47 +02:00
|
|
|
jobject jobj_value = env->GetObjectArrayElement(jvalues, i);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->DeleteLocalRef(jobj_key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-06 21:03:47 +02:00
|
|
|
jstring jkey = reinterpret_cast<jstring>(jobj_key);
|
2016-08-15 23:03:33 +02:00
|
|
|
jstring jval = reinterpret_cast<jstring>(jobj_value);
|
2017-02-28 01:26:12 +01:00
|
|
|
|
|
|
|
const char* key = env->GetStringUTFChars(jkey, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (key == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jobj_value);
|
|
|
|
env->DeleteLocalRef(jobj_key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* value = env->GetStringUTFChars(jval, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (value == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->ReleaseStringUTFChars(jkey, key);
|
|
|
|
env->DeleteLocalRef(jobj_value);
|
|
|
|
env->DeleteLocalRef(jobj_key);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-08-06 21:03:47 +02:00
|
|
|
std::string s_key(key);
|
|
|
|
std::string s_value(value);
|
2017-02-28 01:26:12 +01:00
|
|
|
options_map[s_key] = s_value;
|
|
|
|
|
2016-08-06 21:03:47 +02:00
|
|
|
env->ReleaseStringUTFChars(jkey, key);
|
2016-08-15 23:03:33 +02:00
|
|
|
env->ReleaseStringUTFChars(jval, value);
|
2016-08-06 21:03:47 +02:00
|
|
|
env->DeleteLocalRef(jobj_key);
|
|
|
|
env->DeleteLocalRef(jobj_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* cf_handle = reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
db->SetOptions(cf_handle, options_map);
|
|
|
|
}
|
2016-09-29 23:04:41 +02:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
2017-05-22 19:22:49 +02:00
|
|
|
// rocksdb::DB::IngestExternalFile
|
2016-09-29 23:04:41 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
2017-05-22 19:22:49 +02:00
|
|
|
* Method: ingestExternalFile
|
|
|
|
* Signature: (JJ[Ljava/lang/String;IJ)V
|
2016-09-29 23:04:41 +02:00
|
|
|
*/
|
2017-05-22 19:22:49 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_ingestExternalFile(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jdb*/, jlong jdb_handle, jlong jcf_handle,
|
2016-09-29 23:04:41 +02:00
|
|
|
jobjectArray jfile_path_list, jint jfile_path_list_len,
|
2017-05-22 19:22:49 +02:00
|
|
|
jlong jingest_external_file_options_handle) {
|
2017-02-28 01:26:12 +01:00
|
|
|
jboolean has_exception = JNI_FALSE;
|
2018-04-13 02:55:14 +02:00
|
|
|
std::vector<std::string> file_path_list = rocksdb::JniUtil::copyStrings(
|
|
|
|
env, jfile_path_list, jfile_path_list_len, &has_exception);
|
|
|
|
if (has_exception == JNI_TRUE) {
|
2017-06-05 20:23:31 +02:00
|
|
|
// exception occurred
|
2017-02-28 01:26:12 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-29 23:04:41 +02:00
|
|
|
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto* column_family =
|
|
|
|
reinterpret_cast<rocksdb::ColumnFamilyHandle*>(jcf_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
auto* ifo = reinterpret_cast<rocksdb::IngestExternalFileOptions*>(
|
|
|
|
jingest_external_file_options_handle);
|
2016-09-29 23:04:41 +02:00
|
|
|
rocksdb::Status s =
|
2017-05-22 19:22:49 +02:00
|
|
|
db->IngestExternalFile(column_family, file_path_list, *ifo);
|
2016-09-29 23:04:41 +02:00
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
2017-09-27 01:27:28 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RocksDB
|
|
|
|
* Method: destroyDB
|
|
|
|
* Signature: (Ljava/lang/String;J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_RocksDB_destroyDB(JNIEnv* env, jclass /*jcls*/,
|
|
|
|
jstring jdb_path,
|
|
|
|
jlong joptions_handle) {
|
2017-09-27 01:27:28 +02:00
|
|
|
const char* db_path = env->GetStringUTFChars(jdb_path, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (db_path == nullptr) {
|
2017-09-27 01:27:28 +02:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* options = reinterpret_cast<rocksdb::Options*>(joptions_handle);
|
|
|
|
if (options == nullptr) {
|
2018-04-13 02:55:14 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, rocksdb::Status::InvalidArgument("Invalid Options."));
|
2017-09-27 01:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status s = rocksdb::DestroyDB(db_path, *options);
|
|
|
|
env->ReleaseStringUTFChars(jdb_path, db_path);
|
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|