2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00: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 21:19:21 +00:00
|
|
|
|
|
|
|
// This file is designed for caching those frequently used IDs and provide
|
|
|
|
// efficient portal (i.e, a set of static functions) to access java code
|
|
|
|
// from c++.
|
|
|
|
|
|
|
|
#ifndef JAVA_ROCKSJNI_PORTAL_H_
|
|
|
|
#define JAVA_ROCKSJNI_PORTAL_H_
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
#include <algorithm>
|
2017-10-12 18:06:51 +00:00
|
|
|
#include <cstring>
|
2016-12-16 19:17:26 +00:00
|
|
|
#include <functional>
|
2017-02-28 00:26:12 +00:00
|
|
|
#include <iostream>
|
2018-03-02 18:22:38 +00:00
|
|
|
#include <iterator>
|
2019-02-22 22:36:38 +00:00
|
|
|
#include <jni.h>
|
2014-09-17 19:30:06 +00:00
|
|
|
#include <limits>
|
2017-10-12 18:06:51 +00:00
|
|
|
#include <memory>
|
2014-08-21 20:55:51 +00:00
|
|
|
#include <string>
|
2018-03-02 18:22:38 +00:00
|
|
|
#include <type_traits>
|
2014-10-26 22:23:06 +00:00
|
|
|
#include <vector>
|
2014-08-21 20:55:51 +00:00
|
|
|
|
2020-04-22 00:35:28 +00:00
|
|
|
#include "rocksdb/convenience.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 21:19:21 +00:00
|
|
|
#include "rocksdb/db.h"
|
2014-04-22 06:56:19 +00:00
|
|
|
#include "rocksdb/filter_policy.h"
|
2018-01-08 20:20:48 +00:00
|
|
|
#include "rocksdb/rate_limiter.h"
|
2014-10-09 21:16:41 +00:00
|
|
|
#include "rocksdb/status.h"
|
2019-02-22 22:36:38 +00:00
|
|
|
#include "rocksdb/table.h"
|
2014-07-23 18:15:14 +00:00
|
|
|
#include "rocksdb/utilities/backupable_db.h"
|
2018-10-08 18:03:34 +00:00
|
|
|
#include "rocksdb/utilities/memory_util.h"
|
2018-03-02 18:22:38 +00:00
|
|
|
#include "rocksdb/utilities/transaction_db.h"
|
2015-01-03 14:52:07 +00:00
|
|
|
#include "rocksdb/utilities/write_batch_with_index.h"
|
2017-10-12 18:06:51 +00:00
|
|
|
#include "rocksjni/compaction_filter_factory_jnicallback.h"
|
2014-08-03 20:11:44 +00:00
|
|
|
#include "rocksjni/comparatorjnicallback.h"
|
2015-02-10 20:59:40 +00:00
|
|
|
#include "rocksjni/loggerjnicallback.h"
|
2019-02-22 22:36:38 +00:00
|
|
|
#include "rocksjni/table_filter_jnicallback.h"
|
|
|
|
#include "rocksjni/trace_writer_jnicallback.h"
|
2018-03-02 18:22:38 +00:00
|
|
|
#include "rocksjni/transaction_notifier_jnicallback.h"
|
2019-02-22 22:36:38 +00:00
|
|
|
#include "rocksjni/wal_filter_jnicallback.h"
|
2014-10-23 15:19:38 +00:00
|
|
|
#include "rocksjni/writebatchhandlerjnicallback.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 21:19:21 +00:00
|
|
|
|
2016-01-28 14:44:31 +00:00
|
|
|
// Remove macro on windows
|
|
|
|
#ifdef DELETE
|
|
|
|
#undef DELETE
|
|
|
|
#endif
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
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 21:19:21 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
class JavaClass {
|
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 21:19:21 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Gets and initializes a Java Class
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param jclazz_name The fully qualified JNI name of the Java Class
|
|
|
|
* e.g. "java/lang/String"
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2015-01-24 22:38:43 +00:00
|
|
|
static jclass getJClass(JNIEnv* env, const char* jclazz_name) {
|
|
|
|
jclass jclazz = env->FindClass(jclazz_name);
|
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 21:19:21 +00:00
|
|
|
assert(jclazz != nullptr);
|
|
|
|
return jclazz;
|
|
|
|
}
|
2016-01-20 17:05:41 +00:00
|
|
|
};
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 21:19:21 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// Native class template
|
|
|
|
template<class PTR, class DERIVED> class RocksDBNativeClass : public JavaClass {
|
|
|
|
};
|
|
|
|
|
2016-01-20 17:05:41 +00:00
|
|
|
// Native class template for sub-classes of RocksMutableObject
|
2016-02-10 14:21:23 +00:00
|
|
|
template<class PTR, class DERIVED> class NativeRocksMutableObject
|
|
|
|
: public RocksDBNativeClass<PTR, DERIVED> {
|
2016-01-20 17:05:41 +00:00
|
|
|
public:
|
2016-02-04 14:28:18 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Gets the Java Method ID for the
|
|
|
|
* RocksMutableObject#setNativeHandle(long, boolean) method
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @return The Java Method ID or nullptr the RocksMutableObject class cannot
|
|
|
|
* be accessed, or if one of the NoSuchMethodError,
|
|
|
|
* ExceptionInInitializerError or OutOfMemoryError exceptions is thrown
|
|
|
|
*/
|
2016-02-04 14:28:18 +00:00
|
|
|
static jmethodID getSetNativeHandleMethod(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
static jclass jclazz = DERIVED::getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-04 14:28:18 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(
|
2017-02-28 00:26:12 +00:00
|
|
|
jclazz, "setNativeHandle", "(JZ)V");
|
2016-02-04 14:28:18 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Sets the C++ object pointer handle in the Java object
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param jobj The Java object on which to set the pointer handle
|
|
|
|
* @param ptr The C++ object pointer
|
|
|
|
* @param java_owns_handle JNI_TRUE if ownership of the C++ object is
|
|
|
|
* managed by the Java object
|
|
|
|
*
|
|
|
|
* @return true if a Java exception is pending, false otherwise
|
|
|
|
*/
|
|
|
|
static bool setHandle(JNIEnv* env, jobject jobj, PTR ptr,
|
2016-02-10 14:21:23 +00:00
|
|
|
jboolean java_owns_handle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
assert(jobj != nullptr);
|
|
|
|
static jmethodID mid = getSetNativeHandleMethod(env);
|
|
|
|
if(mid == nullptr) {
|
|
|
|
return true; // signal exception
|
|
|
|
}
|
|
|
|
|
|
|
|
env->CallVoidMethod(jobj, mid, reinterpret_cast<jlong>(ptr), java_owns_handle);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
return true; // signal exception
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-01-24 22:38:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-03-12 21:25:57 +00:00
|
|
|
// Java Exception template
|
2017-02-28 00:26:12 +00:00
|
|
|
template<class DERIVED> class JavaException : public JavaClass {
|
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 21:19:21 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Create and throw a java exception with the provided message
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param msg The message for the exception
|
|
|
|
*
|
|
|
|
* @return true if an exception was thrown, false otherwise
|
|
|
|
*/
|
|
|
|
static bool ThrowNew(JNIEnv* env, const std::string& msg) {
|
|
|
|
jclass jclazz = DERIVED::getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
std::cerr << "JavaException::ThrowNew - Error: unexpected exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
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 21:19:21 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
const jint rs = env->ThrowNew(jclazz, msg.c_str());
|
|
|
|
if(rs != JNI_OK) {
|
|
|
|
// exception could not be thrown
|
|
|
|
std::cerr << "JavaException::ThrowNew - Fatal: could not throw exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
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 21:19:21 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
return true;
|
Add a jni library for rocksdb which supports Open, Get, Put, and Close.
Summary:
This diff contains a simple jni library for rocksdb which supports open, get,
put and closeusing default options (including Options, ReadOptions, and
WriteOptions.) In the usual case, Java developers can use the c++ rocksdb
library in the way similar to the following:
RocksDB db = RocksDB.open(path_to_db);
...
db.put("hello".getBytes(), "world".getBytes();
byte[] value = db.get("hello".getBytes());
...
db.close();
Specifically, this diff has the following major classes:
* RocksDB: a Java wrapper class which forwards the operations
from the java side to c++ rocksdb library.
* RocksDBException: ncapsulates the error of an operation.
This exception type is used to describe an internal error from
the c++ rocksdb library.
This diff also include a simple java sample code calling c++ rocksdb library.
To build the rocksdb jni library, simply run make jni, and make jtest will try to
build and run the sample code.
Note that if the rocksdb is not built with the default glibc that Java uses,
java will try to load the wrong glibc during the run time. As a result,
the sample code might not work properly during the run time.
Test Plan:
* make jni
* make jtest
Reviewers: haobo, dhruba, sdong, igor, ljin
Reviewed By: dhruba
CC: leveldb, xjin
Differential Revision: https://reviews.facebook.net/D17109
2014-03-28 21:19:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for java.lang.IllegalArgumentException
|
|
|
|
class IllegalArgumentExceptionJni :
|
|
|
|
public JavaException<IllegalArgumentExceptionJni> {
|
2015-03-12 21:25:57 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class java.lang.IllegalArgumentException
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2015-03-12 21:25:57 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return JavaException::getJClass(env, "java/lang/IllegalArgumentException");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and throw a Java IllegalArgumentException with the provided status
|
|
|
|
*
|
|
|
|
* If s.ok() == true, then this function will not throw any exception.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param s The status for the exception
|
|
|
|
*
|
|
|
|
* @return true if an exception was thrown, false otherwise
|
|
|
|
*/
|
|
|
|
static bool ThrowNew(JNIEnv* env, const Status& s) {
|
|
|
|
assert(!s.ok());
|
|
|
|
if (s.ok()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the IllegalArgumentException class
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
std::cerr << "IllegalArgumentExceptionJni::ThrowNew/class - Error: unexpected exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
return JavaException::ThrowNew(env, s.ToString());
|
2015-03-12 21:25:57 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
// The portal class for org.rocksdb.Status.Code
|
|
|
|
class CodeJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.Status.Code
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/Status$Code");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: Status.Code#getValue
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getValueMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "getValue", "()b");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.Status.SubCode
|
|
|
|
class SubCodeJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.Status.SubCode
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/Status$SubCode");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: Status.SubCode#getValue
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getValueMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "getValue", "()b");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
static ROCKSDB_NAMESPACE::Status::SubCode toCppSubCode(
|
|
|
|
const jbyte jsub_code) {
|
2018-03-02 23:33:08 +00:00
|
|
|
switch (jsub_code) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kNone;
|
2018-03-02 23:33:08 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kMutexTimeout;
|
2018-03-02 23:33:08 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kLockTimeout;
|
2018-03-02 23:33:08 +00:00
|
|
|
case 0x3:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kLockLimit;
|
2018-03-02 23:33:08 +00:00
|
|
|
case 0x4:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kNoSpace;
|
2018-03-02 23:33:08 +00:00
|
|
|
case 0x5:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kDeadlock;
|
2018-03-02 23:33:08 +00:00
|
|
|
case 0x6:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kStaleFile;
|
2018-03-02 23:33:08 +00:00
|
|
|
case 0x7:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kMemoryLimit;
|
2018-03-02 23:33:08 +00:00
|
|
|
|
|
|
|
case 0x7F:
|
|
|
|
default:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Status::SubCode::kNone;
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-22 18:01:42 +00:00
|
|
|
// The portal class for org.rocksdb.Status
|
2020-02-20 20:07:53 +00:00
|
|
|
class StatusJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::Status*, StatusJni> {
|
2016-08-22 18:01:42 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.Status
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2016-08-22 18:01:42 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/Status");
|
|
|
|
}
|
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Method: Status#getCode
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getCodeMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "getCode", "()Lorg/rocksdb/Status$Code;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: Status#getSubCode
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getSubCodeMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "getSubCode", "()Lorg/rocksdb/Status$SubCode;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: Status#getState
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getStateMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "getState", "()Ljava/lang/String;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.Status object with the same properties as
|
2020-02-20 20:07:53 +00:00
|
|
|
* the provided C++ ROCKSDB_NAMESPACE::Status object
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2020-02-20 20:07:53 +00:00
|
|
|
* @param status The ROCKSDB_NAMESPACE::Status object
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.Status object, or nullptr
|
|
|
|
* if an an exception occurs
|
|
|
|
*/
|
2016-08-22 18:01:42 +00:00
|
|
|
static jobject construct(JNIEnv* env, const Status& status) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "<init>", "(BBLjava/lang/String;)V");
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// convert the Status state for Java
|
2016-08-22 18:01:42 +00:00
|
|
|
jstring jstate = nullptr;
|
|
|
|
if (status.getState() != nullptr) {
|
2017-01-04 02:17:12 +00:00
|
|
|
const char* const state = status.getState();
|
|
|
|
jstate = env->NewStringUTF(state);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
if(jstate != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstate);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jstatus =
|
|
|
|
env->NewObject(jclazz, mid, toJavaStatusCode(status.code()),
|
|
|
|
toJavaStatusSubCode(status.subcode()), jstate);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
if(jstate != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstate);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(jstate != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstate);
|
2016-08-22 18:01:42 +00:00
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
|
|
|
return jstatus;
|
2016-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the equivalent org.rocksdb.Status.Code for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::Status::Code enum
|
|
|
|
static jbyte toJavaStatusCode(const ROCKSDB_NAMESPACE::Status::Code& code) {
|
2016-08-22 18:01:42 +00:00
|
|
|
switch (code) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kOk:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kNotFound:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kCorruption:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kNotSupported:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x3;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kInvalidArgument:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x4;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kIOError:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x5;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kMergeInProgress:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x6;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kIncomplete:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x7;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kShutdownInProgress:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x8;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kTimedOut:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x9;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kAborted:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0xA;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kBusy:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0xB;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kExpired:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0xC;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kTryAgain:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0xD;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::Code::kColumnFamilyDropped:
|
2019-05-20 17:37:37 +00:00
|
|
|
return 0xE;
|
2016-08-22 18:01:42 +00:00
|
|
|
default:
|
2016-12-14 18:17:52 +00:00
|
|
|
return 0x7F; // undefined
|
2016-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the equivalent org.rocksdb.Status.SubCode for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::Status::SubCode enum
|
|
|
|
static jbyte toJavaStatusSubCode(
|
|
|
|
const ROCKSDB_NAMESPACE::Status::SubCode& subCode) {
|
2016-08-22 18:01:42 +00:00
|
|
|
switch (subCode) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::SubCode::kNone:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::SubCode::kMutexTimeout:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::SubCode::kLockTimeout:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::SubCode::kLockLimit:
|
2016-08-22 18:01:42 +00:00
|
|
|
return 0x3;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::SubCode::kNoSpace:
|
2017-10-23 23:34:47 +00:00
|
|
|
return 0x4;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::SubCode::kDeadlock:
|
2017-10-23 23:34:47 +00:00
|
|
|
return 0x5;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::SubCode::kStaleFile:
|
2017-10-23 23:34:47 +00:00
|
|
|
return 0x6;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Status::SubCode::kMemoryLimit:
|
2017-10-23 23:34:47 +00:00
|
|
|
return 0x7;
|
2016-08-22 18:01:42 +00:00
|
|
|
default:
|
2016-12-14 18:17:52 +00:00
|
|
|
return 0x7F; // undefined
|
2016-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
static std::unique_ptr<ROCKSDB_NAMESPACE::Status> toCppStatus(
|
2019-02-22 22:36:38 +00:00
|
|
|
const jbyte jcode_value, const jbyte jsub_code_value) {
|
2020-02-20 20:07:53 +00:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status;
|
2019-02-22 22:36:38 +00:00
|
|
|
switch (jcode_value) {
|
|
|
|
case 0x0:
|
|
|
|
//Ok
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::OK()));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x1:
|
|
|
|
//NotFound
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::NotFound(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x2:
|
|
|
|
//Corruption
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::Corruption(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x3:
|
|
|
|
//NotSupported
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(
|
|
|
|
ROCKSDB_NAMESPACE::Status::NotSupported(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(
|
|
|
|
jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x4:
|
|
|
|
//InvalidArgument
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(
|
|
|
|
ROCKSDB_NAMESPACE::Status::InvalidArgument(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(
|
|
|
|
jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x5:
|
|
|
|
//IOError
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::IOError(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x6:
|
|
|
|
//MergeInProgress
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(
|
|
|
|
ROCKSDB_NAMESPACE::Status::MergeInProgress(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(
|
|
|
|
jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x7:
|
|
|
|
//Incomplete
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::Incomplete(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x8:
|
|
|
|
//ShutdownInProgress
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(
|
|
|
|
ROCKSDB_NAMESPACE::Status::ShutdownInProgress(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(
|
|
|
|
jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0x9:
|
|
|
|
//TimedOut
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::TimedOut(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0xA:
|
|
|
|
//Aborted
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::Aborted(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0xB:
|
|
|
|
//Busy
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::Busy(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0xC:
|
|
|
|
//Expired
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::Expired(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
|
|
|
case 0xD:
|
|
|
|
//TryAgain
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::TryAgain(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(jsub_code_value))));
|
2019-02-22 22:36:38 +00:00
|
|
|
break;
|
2019-05-20 17:37:37 +00:00
|
|
|
case 0xE:
|
|
|
|
// ColumnFamilyDropped
|
2020-02-20 20:07:53 +00:00
|
|
|
status = std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(
|
|
|
|
ROCKSDB_NAMESPACE::Status::ColumnFamilyDropped(
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::toCppSubCode(
|
|
|
|
jsub_code_value))));
|
2019-05-20 17:37:37 +00:00
|
|
|
break;
|
2019-02-22 22:36:38 +00:00
|
|
|
case 0x7F:
|
|
|
|
default:
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent ROCKSDB_NAMESPACE::Status for the Java
|
|
|
|
// org.rocksdb.Status
|
|
|
|
static std::unique_ptr<ROCKSDB_NAMESPACE::Status> toCppStatus(
|
|
|
|
JNIEnv* env, const jobject jstatus) {
|
2018-03-02 23:33:08 +00:00
|
|
|
jmethodID mid_code = getCodeMethod(env);
|
|
|
|
if (mid_code == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
jobject jcode = env->CallObjectMethod(jstatus, mid_code);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-04-13 00:55:14 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jmethodID mid_code_value = ROCKSDB_NAMESPACE::CodeJni::getValueMethod(env);
|
2018-03-02 23:33:08 +00:00
|
|
|
if (mid_code_value == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
jbyte jcode_value = env->CallByteMethod(jcode, mid_code_value);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
if (jcode != nullptr) {
|
|
|
|
env->DeleteLocalRef(jcode);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid_subCode = getSubCodeMethod(env);
|
|
|
|
if (mid_subCode == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
jobject jsubCode = env->CallObjectMethod(jstatus, mid_subCode);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
if (jcode != nullptr) {
|
|
|
|
env->DeleteLocalRef(jcode);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jbyte jsub_code_value = 0x0; // None
|
2018-03-02 23:33:08 +00:00
|
|
|
if (jsubCode != nullptr) {
|
2020-02-20 20:07:53 +00:00
|
|
|
jmethodID mid_subCode_value =
|
|
|
|
ROCKSDB_NAMESPACE::SubCodeJni::getValueMethod(env);
|
2018-03-02 23:33:08 +00:00
|
|
|
if (mid_subCode_value == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
jsub_code_value = env->CallByteMethod(jsubCode, mid_subCode_value);
|
2018-03-02 23:33:08 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
if (jcode != nullptr) {
|
|
|
|
env->DeleteLocalRef(jcode);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid_state = getStateMethod(env);
|
|
|
|
if (mid_state == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
jobject jstate = env->CallObjectMethod(jstatus, mid_state);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
if (jsubCode != nullptr) {
|
|
|
|
env->DeleteLocalRef(jsubCode);
|
|
|
|
}
|
|
|
|
if (jcode != nullptr) {
|
|
|
|
env->DeleteLocalRef(jcode);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
2019-02-22 22:36:38 +00:00
|
|
|
toCppStatus(jcode_value, jsub_code_value);
|
2018-03-02 23:33:08 +00:00
|
|
|
|
|
|
|
// delete all local refs
|
|
|
|
if (jstate != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstate);
|
|
|
|
}
|
|
|
|
if (jsubCode != nullptr) {
|
|
|
|
env->DeleteLocalRef(jsubCode);
|
|
|
|
}
|
|
|
|
if (jcode != nullptr) {
|
|
|
|
env->DeleteLocalRef(jcode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
};
|
|
|
|
|
2015-03-12 21:25:57 +00:00
|
|
|
// The portal class for org.rocksdb.RocksDBException
|
|
|
|
class RocksDBExceptionJni :
|
2017-02-28 00:26:12 +00:00
|
|
|
public JavaException<RocksDBExceptionJni> {
|
2015-03-12 21:25:57 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.RocksDBException
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2015-03-12 21:25:57 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
return JavaException::getJClass(env, "org/rocksdb/RocksDBException");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and throw a Java RocksDBException with the provided message
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param msg The message for the exception
|
|
|
|
*
|
|
|
|
* @return true if an exception was thrown, false otherwise
|
|
|
|
*/
|
|
|
|
static bool ThrowNew(JNIEnv* env, const std::string& msg) {
|
|
|
|
return JavaException::ThrowNew(env, msg);
|
|
|
|
}
|
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
|
|
|
* Create and throw a Java RocksDBException with the provided status
|
|
|
|
*
|
|
|
|
* If s->ok() == true, then this function will not throw any exception.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param s The status for the exception
|
|
|
|
*
|
|
|
|
* @return true if an exception was thrown, false otherwise
|
|
|
|
*/
|
|
|
|
static bool ThrowNew(JNIEnv* env, std::unique_ptr<Status>& s) {
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, *(s.get()));
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Create and throw a Java RocksDBException with the provided status
|
|
|
|
*
|
|
|
|
* If s.ok() == true, then this function will not throw any exception.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param s The status for the exception
|
|
|
|
*
|
|
|
|
* @return true if an exception was thrown, false otherwise
|
|
|
|
*/
|
|
|
|
static bool ThrowNew(JNIEnv* env, const Status& s) {
|
|
|
|
if (s.ok()) {
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// get the RocksDBException class
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/class - Error: unexpected exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// get the constructor of org.rocksdb.RocksDBException
|
|
|
|
jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "<init>", "(Lorg/rocksdb/Status;)V");
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/cstr - Error: unexpected exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
2016-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// get the Java status object
|
2016-08-22 18:01:42 +00:00
|
|
|
jobject jstatus = StatusJni::construct(env, s);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(jstatus == nullptr) {
|
|
|
|
// exception occcurred
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/StatusJni - Error: unexpected exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// construct the RocksDBException
|
|
|
|
jthrowable rocksdb_exception = reinterpret_cast<jthrowable>(env->NewObject(jclazz, mid, jstatus));
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
if(jstatus != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstatus);
|
|
|
|
}
|
|
|
|
if(rocksdb_exception != nullptr) {
|
|
|
|
env->DeleteLocalRef(rocksdb_exception);
|
|
|
|
}
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/NewObject - Error: unexpected exception!" << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// throw the RocksDBException
|
|
|
|
const jint rs = env->Throw(rocksdb_exception);
|
|
|
|
if(rs != JNI_OK) {
|
|
|
|
// exception could not be thrown
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew - Fatal: could not throw exception!" << std::endl;
|
|
|
|
if(jstatus != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstatus);
|
|
|
|
}
|
|
|
|
if(rocksdb_exception != nullptr) {
|
|
|
|
env->DeleteLocalRef(rocksdb_exception);
|
|
|
|
}
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
if(jstatus != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstatus);
|
|
|
|
}
|
|
|
|
if(rocksdb_exception != nullptr) {
|
|
|
|
env->DeleteLocalRef(rocksdb_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and throw a Java RocksDBException with the provided message
|
|
|
|
* and status
|
|
|
|
*
|
|
|
|
* If s.ok() == true, then this function will not throw any exception.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param msg The message for the exception
|
|
|
|
* @param s The status for the exception
|
|
|
|
*
|
|
|
|
* @return true if an exception was thrown, false otherwise
|
|
|
|
*/
|
|
|
|
static bool ThrowNew(JNIEnv* env, const std::string& msg, const Status& s) {
|
|
|
|
assert(!s.ok());
|
2016-08-22 18:01:42 +00:00
|
|
|
if (s.ok()) {
|
2017-02-28 00:26:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the RocksDBException class
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/class - Error: unexpected exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the constructor of org.rocksdb.RocksDBException
|
|
|
|
jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "<init>", "(Ljava/lang/String;Lorg/rocksdb/Status;)V");
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/cstr - Error: unexpected exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
2016-08-22 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
jstring jmsg = env->NewStringUTF(msg.c_str());
|
2017-02-28 00:26:12 +00:00
|
|
|
if(jmsg == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/msg - Error: unexpected exception!" << std::endl;
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the Java status object
|
2016-08-22 18:01:42 +00:00
|
|
|
jobject jstatus = StatusJni::construct(env, s);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(jstatus == nullptr) {
|
|
|
|
// exception occcurred
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/StatusJni - Error: unexpected exception!" << std::endl;
|
|
|
|
if(jmsg != nullptr) {
|
|
|
|
env->DeleteLocalRef(jmsg);
|
|
|
|
}
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// construct the RocksDBException
|
|
|
|
jthrowable rocksdb_exception = reinterpret_cast<jthrowable>(env->NewObject(jclazz, mid, jmsg, jstatus));
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
if(jstatus != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstatus);
|
|
|
|
}
|
|
|
|
if(jmsg != nullptr) {
|
|
|
|
env->DeleteLocalRef(jmsg);
|
|
|
|
}
|
|
|
|
if(rocksdb_exception != nullptr) {
|
|
|
|
env->DeleteLocalRef(rocksdb_exception);
|
|
|
|
}
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew/NewObject - Error: unexpected exception!" << std::endl;
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-22 18:01:42 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// throw the RocksDBException
|
|
|
|
const jint rs = env->Throw(rocksdb_exception);
|
|
|
|
if(rs != JNI_OK) {
|
|
|
|
// exception could not be thrown
|
|
|
|
std::cerr << "RocksDBExceptionJni::ThrowNew - Fatal: could not throw exception!" << std::endl;
|
|
|
|
if(jstatus != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstatus);
|
|
|
|
}
|
|
|
|
if(jmsg != nullptr) {
|
|
|
|
env->DeleteLocalRef(jmsg);
|
|
|
|
}
|
|
|
|
if(rocksdb_exception != nullptr) {
|
|
|
|
env->DeleteLocalRef(rocksdb_exception);
|
|
|
|
}
|
|
|
|
return env->ExceptionCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(jstatus != nullptr) {
|
|
|
|
env->DeleteLocalRef(jstatus);
|
|
|
|
}
|
|
|
|
if(jmsg != nullptr) {
|
|
|
|
env->DeleteLocalRef(jmsg);
|
|
|
|
}
|
|
|
|
if(rocksdb_exception != nullptr) {
|
|
|
|
env->DeleteLocalRef(rocksdb_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-08-22 18:01:42 +00:00
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: RocksDBException#getStatus
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getStatusMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "getStatus", "()Lorg/rocksdb/Status;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
static std::unique_ptr<ROCKSDB_NAMESPACE::Status> toCppStatus(
|
2018-03-02 23:33:08 +00:00
|
|
|
JNIEnv* env, jthrowable jrocksdb_exception) {
|
|
|
|
if(!env->IsInstanceOf(jrocksdb_exception, getJClass(env))) {
|
|
|
|
// not an instance of RocksDBException
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get the java status object
|
|
|
|
jmethodID mid = getStatusMethod(env);
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception occurred accessing class or method
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jstatus = env->CallObjectMethod(jrocksdb_exception, mid);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(jstatus == nullptr) {
|
|
|
|
return nullptr; // no status available
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::StatusJni::toCppStatus(env, jstatus);
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
2015-03-12 21:25:57 +00:00
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for java.util.List
|
|
|
|
class ListJni : public JavaClass {
|
2015-03-12 21:25:57 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class java.util.List
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getListClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "java/util/List");
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class java.util.ArrayList
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getArrayListClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "java/util/ArrayList");
|
2016-08-22 18:01:42 +00:00
|
|
|
}
|
2015-03-12 21:25:57 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class java.util.Iterator
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getIteratorClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "java/util/Iterator");
|
2014-04-01 23:59:05 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: List#iterator
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getIteratorMethod(JNIEnv* env) {
|
|
|
|
jclass jlist_clazz = getListClass(env);
|
|
|
|
if(jlist_clazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jlist_clazz, "iterator", "()Ljava/util/Iterator;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-10-28 21:38:08 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: Iterator#hasNext
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getHasNextMethod(JNIEnv* env) {
|
|
|
|
jclass jiterator_clazz = getIteratorClass(env);
|
|
|
|
if(jiterator_clazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jiterator_clazz, "hasNext", "()Z");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-10-31 22:39:14 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: Iterator#next
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getNextMethod(JNIEnv* env) {
|
|
|
|
jclass jiterator_clazz = getIteratorClass(env);
|
|
|
|
if(jiterator_clazz == nullptr) {
|
2017-02-28 00:26:12 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jiterator_clazz, "next", "()Ljava/lang/Object;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: ArrayList constructor
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getArrayListConstructorMethodId(JNIEnv* env) {
|
|
|
|
jclass jarray_list_clazz = getArrayListClass(env);
|
|
|
|
if(jarray_list_clazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
2017-02-28 00:26:12 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jarray_list_clazz, "<init>", "(I)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Method: List#add
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getListAddMethodId(JNIEnv* env) {
|
|
|
|
jclass jlist_clazz = getListClass(env);
|
|
|
|
if(jlist_clazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
2017-09-22 00:15:27 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-31 22:39:14 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jlist_clazz, "add", "(Ljava/lang/Object;)Z");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-10-28 21:38:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for java.lang.Byte
|
|
|
|
class ByteJni : public JavaClass {
|
2014-04-02 20:14:55 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class java.lang.Byte
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return JavaClass::getJClass(env, "java/lang/Byte");
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class byte[]
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getArrayJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "[B");
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Creates a new 2-dimensional Java Byte Array byte[][]
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2019-02-22 22:36:38 +00:00
|
|
|
* @param len The size of the first dimension
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return A reference to the Java byte[][] or nullptr if an exception occurs
|
2018-03-02 23:33:08 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jobjectArray new2dByteArray(JNIEnv* env, const jsize len) {
|
|
|
|
jclass clazz = getArrayJClass(env);
|
|
|
|
if(clazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return env->NewObjectArray(len, clazz, nullptr);
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: Byte#byteValue
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retrieved
|
2018-03-02 23:33:08 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getByteValueMethod(JNIEnv* env) {
|
|
|
|
jclass clazz = getJClass(env);
|
|
|
|
if(clazz == nullptr) {
|
2018-03-02 23:33:08 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(clazz, "byteValue", "()B");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls the Java Method: Byte#valueOf, returning a constructed Byte jobject
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A constructing Byte object or nullptr if the class or method id could not
|
|
|
|
* be retrieved, or an exception occurred
|
|
|
|
*/
|
|
|
|
static jobject valueOf(JNIEnv* env, jbyte jprimitive_byte) {
|
|
|
|
jclass clazz = getJClass(env);
|
|
|
|
if (clazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetStaticMethodID(clazz, "valueOf", "(B)Ljava/lang/Byte;");
|
2018-03-02 23:33:08 +00:00
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
const jobject jbyte_obj =
|
|
|
|
env->CallStaticObjectMethod(clazz, mid, jprimitive_byte);
|
2018-03-02 23:33:08 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
2019-02-22 22:36:38 +00:00
|
|
|
// exception occurred
|
2018-03-02 23:33:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jbyte_obj;
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
};
|
|
|
|
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
// The portal class for java.nio.ByteBuffer
|
|
|
|
class ByteBufferJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class java.nio.ByteBuffer
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "java/nio/ByteBuffer");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: ByteBuffer#allocate
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param jbytebuffer_clazz if you have a reference to a ByteBuffer class, or nullptr
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getAllocateMethodId(JNIEnv* env,
|
|
|
|
jclass jbytebuffer_clazz = nullptr) {
|
|
|
|
const jclass jclazz =
|
|
|
|
jbytebuffer_clazz == nullptr ? getJClass(env) : jbytebuffer_clazz;
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetStaticMethodID(
|
|
|
|
jclazz, "allocate", "(I)Ljava/nio/ByteBuffer;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: ByteBuffer#array
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getArrayMethodId(JNIEnv* env,
|
|
|
|
jclass jbytebuffer_clazz = nullptr) {
|
|
|
|
const jclass jclazz =
|
|
|
|
jbytebuffer_clazz == nullptr ? getJClass(env) : jbytebuffer_clazz;
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "array", "()[B");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jobject construct(
|
|
|
|
JNIEnv* env, const bool direct, const size_t capacity,
|
|
|
|
jclass jbytebuffer_clazz = nullptr) {
|
|
|
|
return constructWith(env, direct, nullptr, capacity, jbytebuffer_clazz);
|
|
|
|
}
|
|
|
|
|
2020-06-05 16:41:03 +00:00
|
|
|
static jobject constructWith(JNIEnv* env, const bool direct, const char* buf,
|
|
|
|
const size_t capacity,
|
|
|
|
jclass jbytebuffer_clazz = nullptr) {
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
if (direct) {
|
|
|
|
bool allocated = false;
|
|
|
|
if (buf == nullptr) {
|
|
|
|
buf = new char[capacity];
|
|
|
|
allocated = true;
|
|
|
|
}
|
|
|
|
jobject jbuf = env->NewDirectByteBuffer(const_cast<char*>(buf), static_cast<jlong>(capacity));
|
|
|
|
if (jbuf == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
if (allocated) {
|
|
|
|
delete[] static_cast<const char*>(buf);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return jbuf;
|
|
|
|
} else {
|
|
|
|
const jclass jclazz =
|
|
|
|
jbytebuffer_clazz == nullptr ? getJClass(env) : jbytebuffer_clazz;
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const jmethodID jmid_allocate = getAllocateMethodId(env, jbytebuffer_clazz);
|
|
|
|
if (jmid_allocate == nullptr) {
|
|
|
|
// exception occurred accessing class, or NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const jobject jbuf = env->CallStaticObjectMethod(
|
|
|
|
jclazz, jmid_allocate, static_cast<jint>(capacity));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// set buffer data?
|
|
|
|
if (buf != nullptr) {
|
|
|
|
jbyteArray jarray = array(env, jbuf, jbytebuffer_clazz);
|
|
|
|
if (jarray == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
env->DeleteLocalRef(jbuf);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jboolean is_copy = JNI_FALSE;
|
|
|
|
jbyte* ja = reinterpret_cast<jbyte*>(
|
|
|
|
env->GetPrimitiveArrayCritical(jarray, &is_copy));
|
|
|
|
if (ja == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
env->DeleteLocalRef(jarray);
|
|
|
|
env->DeleteLocalRef(jbuf);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(ja, const_cast<char*>(buf), capacity);
|
|
|
|
|
|
|
|
env->ReleasePrimitiveArrayCritical(jarray, ja, 0);
|
|
|
|
|
|
|
|
env->DeleteLocalRef(jarray);
|
|
|
|
}
|
|
|
|
|
|
|
|
return jbuf;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static jbyteArray array(JNIEnv* env, const jobject& jbyte_buffer,
|
|
|
|
jclass jbytebuffer_clazz = nullptr) {
|
|
|
|
const jmethodID mid = getArrayMethodId(env, jbytebuffer_clazz);
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception occurred accessing class, or NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
const jobject jarray = env->CallObjectMethod(jbyte_buffer, mid);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return static_cast<jbyteArray>(jarray);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for java.lang.Integer
|
|
|
|
class IntegerJni : public JavaClass {
|
2018-03-02 23:33:08 +00:00
|
|
|
public:
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class java.lang.Integer
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return JavaClass::getJClass(env, "java/lang/Integer");
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jobject valueOf(JNIEnv* env, jint jprimitive_int) {
|
2018-03-02 23:33:08 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (jclazz == nullptr) {
|
2018-03-02 23:33:08 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jmethodID mid =
|
|
|
|
env->GetStaticMethodID(jclazz, "valueOf", "(I)Ljava/lang/Integer;");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
const jobject jinteger_obj =
|
|
|
|
env->CallStaticObjectMethod(jclazz, mid, jprimitive_int);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
2018-03-02 23:33:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jinteger_obj;
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for java.lang.Long
|
|
|
|
class LongJni : public JavaClass {
|
|
|
|
public:
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class java.lang.Long
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
2018-03-02 23:33:08 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "java/lang/Long");
|
|
|
|
}
|
|
|
|
|
|
|
|
static jobject valueOf(JNIEnv* env, jlong jprimitive_long) {
|
2018-03-02 23:33:08 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (jclazz == nullptr) {
|
2018-03-02 23:33:08 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jmethodID mid =
|
|
|
|
env->GetStaticMethodID(jclazz, "valueOf", "(J)Ljava/lang/Long;");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
const jobject jlong_obj =
|
|
|
|
env->CallStaticObjectMethod(jclazz, mid, jprimitive_long);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
2018-03-02 23:33:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jlong_obj;
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for java.lang.StringBuilder
|
|
|
|
class StringBuilderJni : public JavaClass {
|
|
|
|
public:
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class java.lang.StringBuilder
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
2018-03-02 23:33:08 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "java/lang/StringBuilder");
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: StringBuilder#append
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getListAddMethodId(JNIEnv* env) {
|
2018-03-02 23:33:08 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "append",
|
|
|
|
"(Ljava/lang/String;)Ljava/lang/StringBuilder;");
|
2018-03-02 23:33:08 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Appends a C-style string to a StringBuilder
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2019-02-22 22:36:38 +00:00
|
|
|
* @param jstring_builder Reference to a java.lang.StringBuilder
|
|
|
|
* @param c_str A C-style string to append to the StringBuilder
|
2018-03-02 23:33:08 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return A reference to the updated StringBuilder, or a nullptr if
|
|
|
|
* an exception occurs
|
2018-03-02 23:33:08 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jobject append(JNIEnv* env, jobject jstring_builder,
|
|
|
|
const char* c_str) {
|
|
|
|
jmethodID mid = getListAddMethodId(env);
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception occurred accessing class or method
|
2018-03-02 23:33:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jstring new_value_str = env->NewStringUTF(c_str);
|
|
|
|
if(new_value_str == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
2018-03-02 23:33:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jobject jresult_string_builder =
|
|
|
|
env->CallObjectMethod(jstring_builder, mid, new_value_str);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
env->DeleteLocalRef(new_value_str);
|
2018-03-02 23:33:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jresult_string_builder;
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// various utility functions for working with RocksDB and JNI
|
|
|
|
class JniUtil {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Detect if jlong overflows size_t
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @param jvalue the jlong value
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
inline static Status check_if_jlong_fits_size_t(const jlong& jvalue) {
|
|
|
|
Status s = Status::OK();
|
|
|
|
if (static_cast<uint64_t>(jvalue) > std::numeric_limits<size_t>::max()) {
|
|
|
|
s = Status::InvalidArgument(Slice("jlong overflows 32 bit value."));
|
|
|
|
}
|
|
|
|
return s;
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Obtains a reference to the JNIEnv from
|
|
|
|
* the JVM
|
|
|
|
*
|
|
|
|
* If the current thread is not attached to the JavaVM
|
|
|
|
* then it will be attached so as to retrieve the JNIEnv
|
|
|
|
*
|
|
|
|
* If a thread is attached, it must later be manually
|
|
|
|
* released by calling JavaVM::DetachCurrentThread.
|
|
|
|
* This can be handled by always matching calls to this
|
|
|
|
* function with calls to {@link JniUtil::releaseJniEnv(JavaVM*, jboolean)}
|
|
|
|
*
|
|
|
|
* @param jvm (IN) A pointer to the JavaVM instance
|
|
|
|
* @param attached (OUT) A pointer to a boolean which
|
|
|
|
* will be set to JNI_TRUE if we had to attach the thread
|
|
|
|
*
|
|
|
|
* @return A pointer to the JNIEnv or nullptr if a fatal error
|
|
|
|
* occurs and the JNIEnv cannot be retrieved
|
|
|
|
*/
|
|
|
|
static JNIEnv* getJniEnv(JavaVM* jvm, jboolean* attached) {
|
|
|
|
assert(jvm != nullptr);
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
JNIEnv *env;
|
|
|
|
const jint env_rs = jvm->GetEnv(reinterpret_cast<void**>(&env),
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
JNI_VERSION_1_6);
|
2014-04-21 22:52:59 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
if(env_rs == JNI_OK) {
|
|
|
|
// current thread is already attached, return the JNIEnv
|
|
|
|
*attached = JNI_FALSE;
|
|
|
|
return env;
|
|
|
|
} else if(env_rs == JNI_EDETACHED) {
|
|
|
|
// current thread is not attached, attempt to attach
|
|
|
|
const jint rs_attach = jvm->AttachCurrentThread(reinterpret_cast<void**>(&env), NULL);
|
|
|
|
if(rs_attach == JNI_OK) {
|
|
|
|
*attached = JNI_TRUE;
|
|
|
|
return env;
|
|
|
|
} else {
|
|
|
|
// error, could not attach the thread
|
|
|
|
std::cerr << "JniUtil::getJniEnv - Fatal: could not attach current thread to JVM!" << std::endl;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
} else if(env_rs == JNI_EVERSION) {
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
// error, JDK does not support JNI_VERSION_1_6+
|
|
|
|
std::cerr << "JniUtil::getJniEnv - Fatal: JDK does not support JNI_VERSION_1_6" << std::endl;
|
2019-02-22 22:36:38 +00:00
|
|
|
return nullptr;
|
|
|
|
} else {
|
|
|
|
std::cerr << "JniUtil::getJniEnv - Fatal: Unknown error: env_rs=" << env_rs << std::endl;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Counterpart to {@link JniUtil::getJniEnv(JavaVM*, jboolean*)}
|
|
|
|
*
|
|
|
|
* Detachess the current thread from the JVM if it was previously
|
|
|
|
* attached
|
|
|
|
*
|
|
|
|
* @param jvm (IN) A pointer to the JavaVM instance
|
|
|
|
* @param attached (IN) JNI_TRUE if we previously had to attach the thread
|
|
|
|
* to the JavaVM to get the JNIEnv
|
|
|
|
*/
|
|
|
|
static void releaseJniEnv(JavaVM* jvm, jboolean& attached) {
|
|
|
|
assert(jvm != nullptr);
|
|
|
|
if(attached == JNI_TRUE) {
|
|
|
|
const jint rs_detach = jvm->DetachCurrentThread();
|
|
|
|
assert(rs_detach == JNI_OK);
|
|
|
|
if(rs_detach != JNI_OK) {
|
|
|
|
std::cerr << "JniUtil::getJniEnv - Warn: Unable to detach current thread from JVM!" << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Copies a Java String[] to a C++ std::vector<std::string>
|
|
|
|
*
|
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param jss (IN) The Java String array to copy
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an OutOfMemoryError or ArrayIndexOutOfBoundsException
|
|
|
|
* exception occurs
|
|
|
|
*
|
|
|
|
* @return A std::vector<std:string> containing copies of the Java strings
|
|
|
|
*/
|
|
|
|
static std::vector<std::string> copyStrings(JNIEnv* env,
|
|
|
|
jobjectArray jss, jboolean* has_exception) {
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::JniUtil::copyStrings(
|
|
|
|
env, jss, env->GetArrayLength(jss), has_exception);
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Copies a Java String[] to a C++ std::vector<std::string>
|
|
|
|
*
|
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param jss (IN) The Java String array to copy
|
|
|
|
* @param jss_len (IN) The length of the Java String array to copy
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an OutOfMemoryError or ArrayIndexOutOfBoundsException
|
|
|
|
* exception occurs
|
|
|
|
*
|
|
|
|
* @return A std::vector<std:string> containing copies of the Java strings
|
|
|
|
*/
|
|
|
|
static std::vector<std::string> copyStrings(JNIEnv* env,
|
|
|
|
jobjectArray jss, const jsize jss_len, jboolean* has_exception) {
|
|
|
|
std::vector<std::string> strs;
|
|
|
|
strs.reserve(jss_len);
|
|
|
|
for (jsize i = 0; i < jss_len; i++) {
|
|
|
|
jobject js = env->GetObjectArrayElement(jss, i);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return strs;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jstring jstr = static_cast<jstring>(js);
|
|
|
|
const char* str = env->GetStringUTFChars(jstr, nullptr);
|
|
|
|
if(str == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(js);
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return strs;
|
|
|
|
}
|
2014-10-23 15:19:38 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
strs.push_back(std::string(str));
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
env->ReleaseStringUTFChars(jstr, str);
|
|
|
|
env->DeleteLocalRef(js);
|
|
|
|
}
|
2017-03-07 06:13:53 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
*has_exception = JNI_FALSE;
|
|
|
|
return strs;
|
2017-03-07 06:13:53 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Copies a jstring to a C-style null-terminated byte string
|
|
|
|
* and releases the original jstring
|
|
|
|
*
|
|
|
|
* The jstring is copied as UTF-8
|
|
|
|
*
|
|
|
|
* If an exception occurs, then JNIEnv::ExceptionCheck()
|
|
|
|
* will have been called
|
|
|
|
*
|
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param js (IN) The java string to copy
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an OutOfMemoryError exception occurs
|
|
|
|
*
|
|
|
|
* @return A pointer to the copied string, or a
|
|
|
|
* nullptr if has_exception == JNI_TRUE
|
|
|
|
*/
|
|
|
|
static std::unique_ptr<char[]> copyString(JNIEnv* env, jstring js,
|
|
|
|
jboolean* has_exception) {
|
|
|
|
const char *utf = env->GetStringUTFChars(js, nullptr);
|
|
|
|
if(utf == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->ExceptionCheck();
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return nullptr;
|
|
|
|
} else if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown
|
|
|
|
env->ReleaseStringUTFChars(js, utf);
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
const jsize utf_len = env->GetStringUTFLength(js);
|
|
|
|
std::unique_ptr<char[]> str(new char[utf_len + 1]); // Note: + 1 is needed for the c_str null terminator
|
|
|
|
std::strcpy(str.get(), utf);
|
|
|
|
env->ReleaseStringUTFChars(js, utf);
|
|
|
|
*has_exception = JNI_FALSE;
|
|
|
|
return str;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Copies a jstring to a std::string
|
|
|
|
* and releases the original jstring
|
|
|
|
*
|
|
|
|
* If an exception occurs, then JNIEnv::ExceptionCheck()
|
|
|
|
* will have been called
|
|
|
|
*
|
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param js (IN) The java string to copy
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an OutOfMemoryError exception occurs
|
|
|
|
*
|
|
|
|
* @return A std:string copy of the jstring, or an
|
|
|
|
* empty std::string if has_exception == JNI_TRUE
|
|
|
|
*/
|
|
|
|
static std::string copyStdString(JNIEnv* env, jstring js,
|
|
|
|
jboolean* has_exception) {
|
|
|
|
const char *utf = env->GetStringUTFChars(js, nullptr);
|
|
|
|
if(utf == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->ExceptionCheck();
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return std::string();
|
|
|
|
} else if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown
|
|
|
|
env->ReleaseStringUTFChars(js, utf);
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return std::string();
|
|
|
|
}
|
2014-10-23 15:19:38 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
std::string name(utf);
|
|
|
|
env->ReleaseStringUTFChars(js, utf);
|
|
|
|
*has_exception = JNI_FALSE;
|
|
|
|
return name;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Copies bytes from a std::string to a jByteArray
|
|
|
|
*
|
|
|
|
* @param env A pointer to the java environment
|
|
|
|
* @param bytes The bytes to copy
|
|
|
|
*
|
|
|
|
* @return the Java byte[], or nullptr if an exception occurs
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown
|
2019-02-22 22:36:38 +00:00
|
|
|
* if memory size to copy exceeds general java specific array size limitation.
|
|
|
|
*/
|
|
|
|
static jbyteArray copyBytes(JNIEnv* env, std::string bytes) {
|
|
|
|
return createJavaByteArrayWithSizeCheck(env, bytes.c_str(), bytes.size());
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Given a Java byte[][] which is an array of java.lang.Strings
|
|
|
|
* where each String is a byte[], the passed function `string_fn`
|
|
|
|
* will be called on each String, the result is the collected by
|
|
|
|
* calling the passed function `collector_fn`
|
|
|
|
*
|
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param jbyte_strings (IN) A Java array of Strings expressed as bytes
|
|
|
|
* @param string_fn (IN) A transform function to call for each String
|
|
|
|
* @param collector_fn (IN) A collector which is called for the result
|
|
|
|
* of each `string_fn`
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an ArrayIndexOutOfBoundsException or OutOfMemoryError
|
|
|
|
* exception occurs
|
|
|
|
*/
|
|
|
|
template <typename T> static void byteStrings(JNIEnv* env,
|
|
|
|
jobjectArray jbyte_strings,
|
|
|
|
std::function<T(const char*, const size_t)> string_fn,
|
|
|
|
std::function<void(size_t, T)> collector_fn,
|
|
|
|
jboolean *has_exception) {
|
|
|
|
const jsize jlen = env->GetArrayLength(jbyte_strings);
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
for(jsize i = 0; i < jlen; i++) {
|
|
|
|
jobject jbyte_string_obj = env->GetObjectArrayElement(jbyte_strings, i);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
*has_exception = JNI_TRUE; // signal error
|
|
|
|
return;
|
|
|
|
}
|
2014-10-23 15:19:38 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jbyteArray jbyte_string_ary =
|
|
|
|
reinterpret_cast<jbyteArray>(jbyte_string_obj);
|
|
|
|
T result = byteString(env, jbyte_string_ary, string_fn, has_exception);
|
|
|
|
|
|
|
|
env->DeleteLocalRef(jbyte_string_obj);
|
|
|
|
|
|
|
|
if(*has_exception == JNI_TRUE) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
collector_fn(i, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
*has_exception = JNI_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a Java String which is expressed as a Java Byte Array byte[],
|
|
|
|
* the passed function `string_fn` will be called on the String
|
|
|
|
* and the result returned
|
|
|
|
*
|
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param jbyte_string_ary (IN) A Java String expressed in bytes
|
|
|
|
* @param string_fn (IN) A transform function to call on the String
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an OutOfMemoryError exception occurs
|
|
|
|
*/
|
|
|
|
template <typename T> static T byteString(JNIEnv* env,
|
|
|
|
jbyteArray jbyte_string_ary,
|
|
|
|
std::function<T(const char*, const size_t)> string_fn,
|
|
|
|
jboolean* has_exception) {
|
|
|
|
const jsize jbyte_string_len = env->GetArrayLength(jbyte_string_ary);
|
|
|
|
return byteString<T>(env, jbyte_string_ary, jbyte_string_len, string_fn,
|
|
|
|
has_exception);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a Java String which is expressed as a Java Byte Array byte[],
|
|
|
|
* the passed function `string_fn` will be called on the String
|
|
|
|
* and the result returned
|
|
|
|
*
|
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param jbyte_string_ary (IN) A Java String expressed in bytes
|
|
|
|
* @param jbyte_string_len (IN) The length of the Java String
|
|
|
|
* expressed in bytes
|
|
|
|
* @param string_fn (IN) A transform function to call on the String
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an OutOfMemoryError exception occurs
|
|
|
|
*/
|
|
|
|
template <typename T> static T byteString(JNIEnv* env,
|
|
|
|
jbyteArray jbyte_string_ary, const jsize jbyte_string_len,
|
|
|
|
std::function<T(const char*, const size_t)> string_fn,
|
|
|
|
jboolean* has_exception) {
|
|
|
|
jbyte* jbyte_string =
|
|
|
|
env->GetByteArrayElements(jbyte_string_ary, nullptr);
|
|
|
|
if(jbyte_string == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return nullptr; // signal error
|
|
|
|
}
|
|
|
|
|
|
|
|
T result =
|
|
|
|
string_fn(reinterpret_cast<char *>(jbyte_string), jbyte_string_len);
|
|
|
|
|
|
|
|
env->ReleaseByteArrayElements(jbyte_string_ary, jbyte_string, JNI_ABORT);
|
|
|
|
|
|
|
|
*has_exception = JNI_FALSE;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a std::vector<string> to a Java byte[][] where each Java String
|
|
|
|
* is expressed as a Java Byte Array byte[].
|
|
|
|
*
|
|
|
|
* @param env A pointer to the java environment
|
|
|
|
* @param strings A vector of Strings
|
|
|
|
*
|
|
|
|
* @return A Java array of Strings expressed as bytes,
|
|
|
|
* or nullptr if an exception is thrown
|
|
|
|
*/
|
|
|
|
static jobjectArray stringsBytes(JNIEnv* env, std::vector<std::string> strings) {
|
|
|
|
jclass jcls_ba = ByteJni::getArrayJClass(env);
|
|
|
|
if(jcls_ba == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jsize len = static_cast<jsize>(strings.size());
|
|
|
|
|
|
|
|
jobjectArray jbyte_strings = env->NewObjectArray(len, jcls_ba, nullptr);
|
|
|
|
if(jbyte_strings == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (jsize i = 0; i < len; i++) {
|
|
|
|
std::string *str = &strings[i];
|
|
|
|
const jsize str_len = static_cast<jsize>(str->size());
|
|
|
|
|
|
|
|
jbyteArray jbyte_string_ary = env->NewByteArray(str_len);
|
|
|
|
if(jbyte_string_ary == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jbyte_strings);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->SetByteArrayRegion(
|
|
|
|
jbyte_string_ary, 0, str_len,
|
|
|
|
const_cast<jbyte*>(reinterpret_cast<const jbyte*>(str->c_str())));
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->DeleteLocalRef(jbyte_string_ary);
|
|
|
|
env->DeleteLocalRef(jbyte_strings);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->SetObjectArrayElement(jbyte_strings, i, jbyte_string_ary);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
// or ArrayStoreException
|
|
|
|
env->DeleteLocalRef(jbyte_string_ary);
|
|
|
|
env->DeleteLocalRef(jbyte_strings);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->DeleteLocalRef(jbyte_string_ary);
|
|
|
|
}
|
|
|
|
|
|
|
|
return jbyte_strings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Converts a std::vector<std::string> to a Java String[].
|
|
|
|
*
|
|
|
|
* @param env A pointer to the java environment
|
|
|
|
* @param strings A vector of Strings
|
|
|
|
*
|
|
|
|
* @return A Java array of Strings,
|
|
|
|
* or nullptr if an exception is thrown
|
|
|
|
*/
|
|
|
|
static jobjectArray toJavaStrings(JNIEnv* env,
|
|
|
|
const std::vector<std::string>* strings) {
|
|
|
|
jclass jcls_str = env->FindClass("java/lang/String");
|
|
|
|
if(jcls_str == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jsize len = static_cast<jsize>(strings->size());
|
|
|
|
|
|
|
|
jobjectArray jstrings = env->NewObjectArray(len, jcls_str, nullptr);
|
|
|
|
if(jstrings == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (jsize i = 0; i < len; i++) {
|
|
|
|
const std::string *str = &((*strings)[i]);
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring js = ROCKSDB_NAMESPACE::JniUtil::toJavaString(env, str);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (js == nullptr) {
|
|
|
|
env->DeleteLocalRef(jstrings);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->SetObjectArrayElement(jstrings, i, js);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
// or ArrayStoreException
|
|
|
|
env->DeleteLocalRef(js);
|
|
|
|
env->DeleteLocalRef(jstrings);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return jstrings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Java UTF String from a C++ std::string
|
|
|
|
*
|
|
|
|
* @param env A pointer to the java environment
|
|
|
|
* @param string the C++ std::string
|
|
|
|
* @param treat_empty_as_null true if empty strings should be treated as null
|
|
|
|
*
|
|
|
|
* @return the Java UTF string, or nullptr if the provided string
|
|
|
|
* is null (or empty and treat_empty_as_null is set), or if an
|
|
|
|
* exception occurs allocating the Java String.
|
|
|
|
*/
|
|
|
|
static jstring toJavaString(JNIEnv* env, const std::string* string,
|
|
|
|
const bool treat_empty_as_null = false) {
|
|
|
|
if (string == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (treat_empty_as_null && string->empty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return env->NewStringUTF(string->c_str());
|
|
|
|
}
|
2019-04-17 06:29:32 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Copies bytes to a new jByteArray with the check of java array size limitation.
|
|
|
|
*
|
|
|
|
* @param bytes pointer to memory to copy to a new jByteArray
|
|
|
|
* @param size number of bytes to copy
|
|
|
|
*
|
|
|
|
* @return the Java byte[], or nullptr if an exception occurs
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown
|
2019-02-22 22:36:38 +00:00
|
|
|
* if memory size to copy exceeds general java array size limitation to avoid overflow.
|
|
|
|
*/
|
|
|
|
static jbyteArray createJavaByteArrayWithSizeCheck(JNIEnv* env, const char* bytes, const size_t size) {
|
|
|
|
// Limitation for java array size is vm specific
|
|
|
|
// In general it cannot exceed Integer.MAX_VALUE (2^31 - 1)
|
|
|
|
// Current HotSpot VM limitation for array size is Integer.MAX_VALUE - 5 (2^31 - 1 - 5)
|
2019-04-17 06:29:32 +00:00
|
|
|
// It means that the next call to env->NewByteArray can still end with
|
2019-02-22 22:36:38 +00:00
|
|
|
// OutOfMemoryError("Requested array size exceeds VM limit") coming from VM
|
|
|
|
static const size_t MAX_JARRAY_SIZE = (static_cast<size_t>(1)) << 31;
|
|
|
|
if(size > MAX_JARRAY_SIZE) {
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, "Requested array size exceeds VM limit");
|
2019-02-22 22:36:38 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-04-17 06:29:32 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
const jsize jlen = static_cast<jsize>(size);
|
|
|
|
jbyteArray jbytes = env->NewByteArray(jlen);
|
|
|
|
if(jbytes == nullptr) {
|
2019-04-17 06:29:32 +00:00
|
|
|
// exception thrown: OutOfMemoryError
|
2019-02-22 22:36:38 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-04-17 06:29:32 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
env->SetByteArrayRegion(jbytes, 0, jlen,
|
|
|
|
const_cast<jbyte*>(reinterpret_cast<const jbyte*>(bytes)));
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->DeleteLocalRef(jbytes);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jbytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-02-20 20:07:53 +00:00
|
|
|
* Copies bytes from a ROCKSDB_NAMESPACE::Slice to a jByteArray
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the java environment
|
|
|
|
* @param bytes The bytes to copy
|
|
|
|
*
|
|
|
|
* @return the Java byte[] or nullptr if an exception occurs
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
|
|
|
* @throws RocksDBException thrown
|
2020-02-20 20:07:53 +00:00
|
|
|
* if memory size to copy exceeds general java specific array size
|
|
|
|
* limitation.
|
2019-02-22 22:36:38 +00:00
|
|
|
*/
|
|
|
|
static jbyteArray copyBytes(JNIEnv* env, const Slice& bytes) {
|
|
|
|
return createJavaByteArrayWithSizeCheck(env, bytes.data(), bytes.size());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper for operations on a key and value
|
|
|
|
* for example WriteBatch->Put
|
|
|
|
*
|
|
|
|
* TODO(AR) could be used for RocksDB->Put etc.
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static std::unique_ptr<ROCKSDB_NAMESPACE::Status> kv_op(
|
|
|
|
std::function<ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Slice,
|
|
|
|
ROCKSDB_NAMESPACE::Slice)>
|
|
|
|
op,
|
|
|
|
JNIEnv* env, jobject /*jobj*/, jbyteArray jkey, jint jkey_len,
|
2019-02-22 22:36:38 +00:00
|
|
|
jbyteArray jvalue, jint jvalue_len) {
|
|
|
|
jbyte* key = env->GetByteArrayElements(jkey, nullptr);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jbyte* value = env->GetByteArrayElements(jvalue, nullptr);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
if(key != nullptr) {
|
|
|
|
env->ReleaseByteArrayElements(jkey, key, JNI_ABORT);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::Slice key_slice(reinterpret_cast<char*>(key),
|
|
|
|
jkey_len);
|
|
|
|
ROCKSDB_NAMESPACE::Slice value_slice(reinterpret_cast<char*>(value),
|
|
|
|
jvalue_len);
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
auto status = op(key_slice, value_slice);
|
|
|
|
|
|
|
|
if(value != nullptr) {
|
|
|
|
env->ReleaseByteArrayElements(jvalue, value, JNI_ABORT);
|
|
|
|
}
|
|
|
|
if(key != nullptr) {
|
|
|
|
env->ReleaseByteArrayElements(jkey, key, JNI_ABORT);
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
return std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(status));
|
2019-02-22 22:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper for operations on a key
|
|
|
|
* for example WriteBatch->Delete
|
|
|
|
*
|
|
|
|
* TODO(AR) could be used for RocksDB->Delete etc.
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static std::unique_ptr<ROCKSDB_NAMESPACE::Status> k_op(
|
|
|
|
std::function<ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Slice)> op,
|
|
|
|
JNIEnv* env, jobject /*jobj*/, jbyteArray jkey, jint jkey_len) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jbyte* key = env->GetByteArrayElements(jkey, nullptr);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::Slice key_slice(reinterpret_cast<char*>(key),
|
|
|
|
jkey_len);
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
auto status = op(key_slice);
|
|
|
|
|
|
|
|
if(key != nullptr) {
|
|
|
|
env->ReleaseByteArrayElements(jkey, key, JNI_ABORT);
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
return std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(status));
|
2019-02-22 22:36:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper for operations on a value
|
|
|
|
* for example WriteBatchWithIndex->GetFromBatch
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jbyteArray v_op(std::function<ROCKSDB_NAMESPACE::Status(
|
|
|
|
ROCKSDB_NAMESPACE::Slice, std::string*)>
|
|
|
|
op,
|
|
|
|
JNIEnv* env, jbyteArray jkey, jint jkey_len) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jbyte* key = env->GetByteArrayElements(jkey, nullptr);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::Slice key_slice(reinterpret_cast<char*>(key),
|
|
|
|
jkey_len);
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
std::string value;
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::Status s = op(key_slice, &value);
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
if(key != nullptr) {
|
|
|
|
env->ReleaseByteArrayElements(jkey, key, JNI_ABORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.IsNotFound()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
jbyteArray jret_value =
|
|
|
|
env->NewByteArray(static_cast<jsize>(value.size()));
|
|
|
|
if(jret_value == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->SetByteArrayRegion(jret_value, 0, static_cast<jsize>(value.size()),
|
|
|
|
const_cast<jbyte*>(reinterpret_cast<const jbyte*>(value.c_str())));
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
if(jret_value != nullptr) {
|
|
|
|
env->DeleteLocalRef(jret_value);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jret_value;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
|
2019-02-22 22:36:38 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a vector<T*> of C++ pointers from
|
|
|
|
* a Java array of C++ pointer addresses.
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param pointers (IN) A Java array of C++ pointer addresses
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an ArrayIndexOutOfBoundsException or OutOfMemoryError
|
|
|
|
* exception occurs.
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return A vector of C++ pointers.
|
|
|
|
*/
|
|
|
|
template<typename T> static std::vector<T*> fromJPointers(
|
|
|
|
JNIEnv* env, jlongArray jptrs, jboolean *has_exception) {
|
|
|
|
const jsize jptrs_len = env->GetArrayLength(jptrs);
|
|
|
|
std::vector<T*> ptrs;
|
|
|
|
jlong* jptr = env->GetLongArrayElements(jptrs, nullptr);
|
|
|
|
if (jptr == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return ptrs;
|
|
|
|
}
|
|
|
|
ptrs.reserve(jptrs_len);
|
|
|
|
for (jsize i = 0; i < jptrs_len; i++) {
|
|
|
|
ptrs.push_back(reinterpret_cast<T*>(jptr[i]));
|
|
|
|
}
|
|
|
|
env->ReleaseLongArrayElements(jptrs, jptr, JNI_ABORT);
|
|
|
|
return ptrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Java array of C++ pointer addresses
|
|
|
|
* from a vector of C++ pointers.
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @param env (IN) A pointer to the java environment
|
|
|
|
* @param pointers (IN) A vector of C++ pointers
|
|
|
|
* @param has_exception (OUT) will be set to JNI_TRUE
|
|
|
|
* if an ArrayIndexOutOfBoundsException or OutOfMemoryError
|
|
|
|
* exception occurs
|
2019-04-17 06:29:32 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return Java array of C++ pointer addresses.
|
|
|
|
*/
|
|
|
|
template<typename T> static jlongArray toJPointers(JNIEnv* env,
|
|
|
|
const std::vector<T*> &pointers,
|
|
|
|
jboolean *has_exception) {
|
|
|
|
const jsize len = static_cast<jsize>(pointers.size());
|
|
|
|
std::unique_ptr<jlong[]> results(new jlong[len]);
|
|
|
|
std::transform(pointers.begin(), pointers.end(), results.get(), [](T* pointer) -> jlong {
|
|
|
|
return reinterpret_cast<jlong>(pointer);
|
|
|
|
});
|
|
|
|
|
|
|
|
jlongArray jpointers = env->NewLongArray(len);
|
|
|
|
if (jpointers == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
env->SetLongArrayRegion(jpointers, 0, len, results.get());
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
*has_exception = JNI_TRUE;
|
|
|
|
env->DeleteLocalRef(jpointers);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
*has_exception = JNI_FALSE;
|
|
|
|
|
|
|
|
return jpointers;
|
|
|
|
}
|
2020-02-11 22:45:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper for operations on a key and value
|
|
|
|
* for example WriteBatch->Put
|
|
|
|
*
|
2020-02-20 20:07:53 +00:00
|
|
|
* TODO(AR) could be extended to cover returning ROCKSDB_NAMESPACE::Status
|
2020-02-11 22:45:15 +00:00
|
|
|
* from `op` and used for RocksDB->Put etc.
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static void kv_op_direct(std::function<void(ROCKSDB_NAMESPACE::Slice&,
|
|
|
|
ROCKSDB_NAMESPACE::Slice&)>
|
|
|
|
op,
|
|
|
|
JNIEnv* env, jobject jkey, jint jkey_off,
|
|
|
|
jint jkey_len, jobject jval, jint jval_off,
|
|
|
|
jint jval_len) {
|
2020-02-11 22:45:15 +00:00
|
|
|
char* key = reinterpret_cast<char*>(env->GetDirectBufferAddress(jkey));
|
|
|
|
if (key == nullptr ||
|
|
|
|
env->GetDirectBufferCapacity(jkey) < (jkey_off + jkey_len)) {
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, "Invalid key argument");
|
2020-02-11 22:45:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* value = reinterpret_cast<char*>(env->GetDirectBufferAddress(jval));
|
|
|
|
if (value == nullptr ||
|
|
|
|
env->GetDirectBufferCapacity(jval) < (jval_off + jval_len)) {
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, "Invalid value argument");
|
2020-02-11 22:45:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
key += jkey_off;
|
|
|
|
value += jval_off;
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::Slice key_slice(key, jkey_len);
|
|
|
|
ROCKSDB_NAMESPACE::Slice value_slice(value, jval_len);
|
2020-02-11 22:45:15 +00:00
|
|
|
|
|
|
|
op(key_slice, value_slice);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper for operations on a key and value
|
|
|
|
* for example WriteBatch->Delete
|
|
|
|
*
|
2020-02-20 20:07:53 +00:00
|
|
|
* TODO(AR) could be extended to cover returning ROCKSDB_NAMESPACE::Status
|
2020-02-11 22:45:15 +00:00
|
|
|
* from `op` and used for RocksDB->Delete etc.
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static void k_op_direct(std::function<void(ROCKSDB_NAMESPACE::Slice&)> op,
|
2020-02-11 22:45:15 +00:00
|
|
|
JNIEnv* env, jobject jkey, jint jkey_off,
|
|
|
|
jint jkey_len) {
|
|
|
|
char* key = reinterpret_cast<char*>(env->GetDirectBufferAddress(jkey));
|
|
|
|
if (key == nullptr ||
|
|
|
|
env->GetDirectBufferCapacity(jkey) < (jkey_off + jkey_len)) {
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, "Invalid key argument");
|
2020-02-11 22:45:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
key += jkey_off;
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::Slice key_slice(key, jkey_len);
|
2020-02-11 22:45:15 +00:00
|
|
|
|
|
|
|
return op(key_slice);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
static jint copyToDirect(JNIEnv* env, T& source, jobject jtarget,
|
|
|
|
jint jtarget_off, jint jtarget_len) {
|
|
|
|
char* target =
|
|
|
|
reinterpret_cast<char*>(env->GetDirectBufferAddress(jtarget));
|
|
|
|
if (target == nullptr ||
|
|
|
|
env->GetDirectBufferCapacity(jtarget) < (jtarget_off + jtarget_len)) {
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(
|
|
|
|
env, "Invalid target argument");
|
2020-02-11 22:45:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
target += jtarget_off;
|
|
|
|
|
|
|
|
const jint cvalue_len = static_cast<jint>(source.size());
|
|
|
|
const jint length = std::min(jtarget_len, cvalue_len);
|
|
|
|
|
|
|
|
memcpy(target, source.data(), length);
|
|
|
|
|
|
|
|
return cvalue_len;
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class MapJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class java.util.Map
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "java/util/Map");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: Map#put
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getMapPutMethodId(JNIEnv* env) {
|
|
|
|
jclass jlist_clazz = getJClass(env);
|
|
|
|
if(jlist_clazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jlist_clazz, "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class HashMapJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class java.util.HashMap
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "java/util/HashMap");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java java.util.HashMap object.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to a Java java.util.HashMap object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
|
|
|
static jobject construct(JNIEnv* env, const uint32_t initial_capacity = 16) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(I)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jhash_map = env->NewObject(jclazz, mid, static_cast<jint>(initial_capacity));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jhash_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A function which maps a std::pair<K,V> to a std::pair<JK, JV>
|
|
|
|
*
|
|
|
|
* @return Either a pointer to a std::pair<jobject, jobject>, or nullptr
|
|
|
|
* if an error occurs during the mapping
|
|
|
|
*/
|
|
|
|
template <typename K, typename V, typename JK, typename JV>
|
|
|
|
using FnMapKV = std::function<std::unique_ptr<std::pair<JK, JV>> (const std::pair<K, V>&)>;
|
|
|
|
|
|
|
|
// template <class I, typename K, typename V, typename K1, typename V1, typename std::enable_if<std::is_same<typename std::iterator_traits<I>::value_type, std::pair<const K,V>>::value, int32_t>::type = 0>
|
|
|
|
// static void putAll(JNIEnv* env, const jobject jhash_map, I iterator, const FnMapKV<const K,V,K1,V1> &fn_map_kv) {
|
|
|
|
/**
|
|
|
|
* Returns true if it succeeds, false if an error occurs
|
|
|
|
*/
|
|
|
|
template<class iterator_type, typename K, typename V>
|
|
|
|
static bool putAll(JNIEnv* env, const jobject jhash_map, iterator_type iterator, iterator_type end, const FnMapKV<K, V, jobject, jobject> &fn_map_kv) {
|
2020-02-20 20:07:53 +00:00
|
|
|
const jmethodID jmid_put =
|
|
|
|
ROCKSDB_NAMESPACE::MapJni::getMapPutMethodId(env);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (jmid_put == nullptr) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto it = iterator; it != end; ++it) {
|
|
|
|
const std::unique_ptr<std::pair<jobject, jobject>> result = fn_map_kv(*it);
|
|
|
|
if (result == nullptr) {
|
|
|
|
// an error occurred during fn_map_kv
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
env->CallObjectMethod(jhash_map, jmid_put, result->first, result->second);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
env->DeleteLocalRef(result->second);
|
|
|
|
env->DeleteLocalRef(result->first);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// release local references
|
|
|
|
env->DeleteLocalRef(result->second);
|
|
|
|
env->DeleteLocalRef(result->first);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a java.util.Map<String, String> from a std::map<std::string, std::string>
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param map the Cpp map
|
|
|
|
*
|
|
|
|
* @return a reference to the Java java.util.Map object, or nullptr if an exception occcurred
|
|
|
|
*/
|
|
|
|
static jobject fromCppMap(JNIEnv* env, const std::map<std::string, std::string>* map) {
|
|
|
|
if (map == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jhash_map = construct(env, static_cast<uint32_t>(map->size()));
|
|
|
|
if (jhash_map == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::HashMapJni::FnMapKV<
|
|
|
|
const std::string, const std::string, jobject, jobject>
|
|
|
|
fn_map_kv =
|
|
|
|
[env](const std::pair<const std::string, const std::string>& kv) {
|
|
|
|
jstring jkey = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &(kv.first), false);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
jstring jvalue = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &(kv.second), true);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(
|
|
|
|
new std::pair<jobject, jobject>(
|
|
|
|
static_cast<jobject>(jkey),
|
|
|
|
static_cast<jobject>(jvalue)));
|
|
|
|
};
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
if (!putAll(env, jhash_map, map->begin(), map->end(), fn_map_kv)) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jhash_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a java.util.Map<String, Long> from a std::map<std::string, uint32_t>
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param map the Cpp map
|
|
|
|
*
|
|
|
|
* @return a reference to the Java java.util.Map object, or nullptr if an exception occcurred
|
|
|
|
*/
|
|
|
|
static jobject fromCppMap(JNIEnv* env, const std::map<std::string, uint32_t>* map) {
|
|
|
|
if (map == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (map == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jhash_map = construct(env, static_cast<uint32_t>(map->size()));
|
|
|
|
if (jhash_map == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::HashMapJni::FnMapKV<
|
|
|
|
const std::string, const uint32_t, jobject, jobject>
|
|
|
|
fn_map_kv =
|
|
|
|
[env](const std::pair<const std::string, const uint32_t>& kv) {
|
|
|
|
jstring jkey = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &(kv.first), false);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jobject jvalue = ROCKSDB_NAMESPACE::IntegerJni::valueOf(
|
|
|
|
env, static_cast<jint>(kv.second));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(
|
|
|
|
new std::pair<jobject, jobject>(static_cast<jobject>(jkey),
|
|
|
|
jvalue));
|
|
|
|
};
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
if (!putAll(env, jhash_map, map->begin(), map->end(), fn_map_kv)) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jhash_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a java.util.Map<String, Long> from a std::map<std::string, uint64_t>
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param map the Cpp map
|
|
|
|
*
|
|
|
|
* @return a reference to the Java java.util.Map object, or nullptr if an exception occcurred
|
|
|
|
*/
|
|
|
|
static jobject fromCppMap(JNIEnv* env, const std::map<std::string, uint64_t>* map) {
|
|
|
|
if (map == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jhash_map = construct(env, static_cast<uint32_t>(map->size()));
|
|
|
|
if (jhash_map == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::HashMapJni::FnMapKV<
|
|
|
|
const std::string, const uint64_t, jobject, jobject>
|
|
|
|
fn_map_kv =
|
|
|
|
[env](const std::pair<const std::string, const uint64_t>& kv) {
|
|
|
|
jstring jkey = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &(kv.first), false);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jobject jvalue = ROCKSDB_NAMESPACE::LongJni::valueOf(
|
|
|
|
env, static_cast<jlong>(kv.second));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(
|
|
|
|
new std::pair<jobject, jobject>(static_cast<jobject>(jkey),
|
|
|
|
jvalue));
|
|
|
|
};
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
if (!putAll(env, jhash_map, map->begin(), map->end(), fn_map_kv)) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jhash_map;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a java.util.Map<String, Long> from a std::map<uint32_t, uint64_t>
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param map the Cpp map
|
|
|
|
*
|
|
|
|
* @return a reference to the Java java.util.Map object, or nullptr if an exception occcurred
|
|
|
|
*/
|
|
|
|
static jobject fromCppMap(JNIEnv* env, const std::map<uint32_t, uint64_t>* map) {
|
|
|
|
if (map == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jhash_map = construct(env, static_cast<uint32_t>(map->size()));
|
|
|
|
if (jhash_map == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::HashMapJni::FnMapKV<const uint32_t, const uint64_t,
|
|
|
|
jobject, jobject>
|
|
|
|
fn_map_kv = [env](const std::pair<const uint32_t, const uint64_t>& kv) {
|
|
|
|
jobject jkey = ROCKSDB_NAMESPACE::IntegerJni::valueOf(
|
|
|
|
env, static_cast<jint>(kv.first));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jobject jvalue = ROCKSDB_NAMESPACE::LongJni::valueOf(
|
|
|
|
env, static_cast<jlong>(kv.second));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(
|
|
|
|
new std::pair<jobject, jobject>(static_cast<jobject>(jkey),
|
|
|
|
jvalue));
|
|
|
|
};
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
if (!putAll(env, jhash_map, map->begin(), map->end(), fn_map_kv)) {
|
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jhash_map;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.RocksDB
|
2020-02-20 20:07:53 +00:00
|
|
|
class RocksDBJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::DB*, RocksDBJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.RocksDB
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/RocksDB");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.Options
|
2020-02-20 20:07:53 +00:00
|
|
|
class OptionsJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::Options*, OptionsJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.Options
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/Options");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.DBOptions
|
2020-02-20 20:07:53 +00:00
|
|
|
class DBOptionsJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::DBOptions*, DBOptionsJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.DBOptions
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/DBOptions");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.ColumnFamilyOptions
|
|
|
|
class ColumnFamilyOptionsJni
|
2020-02-20 20:07:53 +00:00
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::ColumnFamilyOptions*,
|
2019-02-22 22:36:38 +00:00
|
|
|
ColumnFamilyOptionsJni> {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.ColumnFamilyOptions
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/ColumnFamilyOptions");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.ColumnFamilyOptions object with the same
|
2020-02-20 20:07:53 +00:00
|
|
|
* properties as the provided C++ ROCKSDB_NAMESPACE::ColumnFamilyOptions
|
|
|
|
* object
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2020-02-20 20:07:53 +00:00
|
|
|
* @param cfoptions A pointer to ROCKSDB_NAMESPACE::ColumnFamilyOptions object
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.ColumnFamilyOptions object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
|
|
|
static jobject construct(JNIEnv* env, const ColumnFamilyOptions* cfoptions) {
|
2020-02-20 20:07:53 +00:00
|
|
|
auto* cfo = new ROCKSDB_NAMESPACE::ColumnFamilyOptions(*cfoptions);
|
2019-02-22 22:36:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(J)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jcfd = env->NewObject(jclazz, mid, reinterpret_cast<jlong>(cfo));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jcfd;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.WriteOptions
|
2020-02-20 20:07:53 +00:00
|
|
|
class WriteOptionsJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::WriteOptions*,
|
|
|
|
WriteOptionsJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.WriteOptions
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/WriteOptions");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.ReadOptions
|
2020-02-20 20:07:53 +00:00
|
|
|
class ReadOptionsJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::ReadOptions*,
|
|
|
|
ReadOptionsJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.ReadOptions
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/ReadOptions");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.WriteBatch
|
2020-02-20 20:07:53 +00:00
|
|
|
class WriteBatchJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::WriteBatch*, WriteBatchJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.WriteBatch
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/WriteBatch");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.WriteBatch object
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2020-02-20 20:07:53 +00:00
|
|
|
* @param wb A pointer to ROCKSDB_NAMESPACE::WriteBatch object
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.WriteBatch object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
|
|
|
static jobject construct(JNIEnv* env, const WriteBatch* wb) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(J)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jwb = env->NewObject(jclazz, mid, reinterpret_cast<jlong>(wb));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jwb;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.WriteBatch.Handler
|
2020-02-20 20:07:53 +00:00
|
|
|
class WriteBatchHandlerJni
|
|
|
|
: public RocksDBNativeClass<
|
|
|
|
const ROCKSDB_NAMESPACE::WriteBatchHandlerJniCallback*,
|
|
|
|
WriteBatchHandlerJni> {
|
2015-01-03 14:52:07 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.WriteBatch.Handler
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2015-01-03 14:52:07 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2015-01-24 22:38:43 +00:00
|
|
|
return RocksDBNativeClass::getJClass(env,
|
2019-02-22 22:36:38 +00:00
|
|
|
"org/rocksdb/WriteBatch$Handler");
|
2015-01-03 14:52:07 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#put
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getPutCfMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "put", "(I[B[B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#put
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getPutMethodId(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "put", "([B[B)V");
|
2014-04-17 04:38:33 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-04-18 17:47:03 +00:00
|
|
|
}
|
2014-05-14 05:22:21 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#merge
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getMergeCfMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "merge", "(I[B[B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-04-17 04:38:33 +00:00
|
|
|
}
|
2014-04-19 10:26:22 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#merge
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getMergeMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "merge", "([B[B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2015-08-04 23:07:17 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#delete
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getDeleteCfMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "delete", "(I[B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-04-19 10:26:22 +00:00
|
|
|
}
|
2014-04-22 06:56:19 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#delete
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getDeleteMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "delete", "([B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-10-13 08:34:52 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#singleDelete
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getSingleDeleteCfMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "singleDelete", "(I[B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-04-22 06:56:19 +00:00
|
|
|
}
|
2014-04-25 20:57:20 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#singleDelete
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getSingleDeleteMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "singleDelete", "([B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2015-01-24 22:38:43 +00:00
|
|
|
}
|
2014-11-09 19:09:39 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#deleteRange
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getDeleteRangeCfMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "deleteRange", "(I[B[B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: WriteBatch.Handler#deleteRange
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getDeleteRangeMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "deleteRange", "([B[B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: WriteBatch.Handler#logData
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getLogDataMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "logData", "([B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2015-01-24 22:38:43 +00:00
|
|
|
}
|
2014-08-15 12:34:10 +00:00
|
|
|
|
2017-10-12 18:06:51 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#putBlobIndex
|
2017-10-12 18:06:51 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-10-12 18:06:51 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getPutBlobIndexCfMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "putBlobIndex", "(I[B[B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2017-10-12 18:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#markBeginPrepare
|
2017-10-12 18:06:51 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getMarkBeginPrepareMethodId(JNIEnv* env) {
|
2017-10-12 18:06:51 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "markBeginPrepare", "()V");
|
2017-10-12 18:06:51 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#markEndPrepare
|
2017-10-12 18:06:51 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getMarkEndPrepareMethodId(JNIEnv* env) {
|
2017-10-12 18:06:51 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "markEndPrepare", "([B)V");
|
2017-10-12 18:06:51 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2018-03-02 18:22:38 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Method: WriteBatch.Handler#markNoop
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getMarkNoopMethodId(JNIEnv* env) {
|
2018-03-02 18:22:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "markNoop", "(Z)V");
|
2018-03-02 18:22:38 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#markRollback
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getMarkRollbackMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "markRollback", "([B)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2014-08-03 20:11:44 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#markCommit
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getMarkCommitMethodId(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "markCommit", "([B)V");
|
2014-08-03 20:11:44 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: WriteBatch.Handler#shouldContinue
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getContinueMethodId(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "shouldContinue", "()Z");
|
2014-08-03 20:11:44 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2014-08-03 20:11:44 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
class WriteBatchSavePointJni : public JavaClass {
|
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.WriteBatch.SavePoint
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/WriteBatch$SavePoint");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: HistogramData constructor
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getConstructorMethodId(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "<init>", "(JJJ)V");
|
2014-08-03 20:11:44 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Create a new Java org.rocksdb.WriteBatch.SavePoint object
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2020-02-20 20:07:53 +00:00
|
|
|
* @param savePoint A pointer to ROCKSDB_NAMESPACE::WriteBatch::SavePoint
|
|
|
|
* object
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return A reference to a Java org.rocksdb.WriteBatch.SavePoint object, or
|
|
|
|
* nullptr if an an exception occurs
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jobject construct(JNIEnv* env, const SavePoint &save_point) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jmethodID mid = getConstructorMethodId(env);
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jsave_point = env->NewObject(jclazz, mid,
|
|
|
|
static_cast<jlong>(save_point.size),
|
|
|
|
static_cast<jlong>(save_point.count),
|
|
|
|
static_cast<jlong>(save_point.content_flags));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jsave_point;
|
2014-08-03 20:11:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.WriteBatchWithIndex
|
2020-02-20 20:07:53 +00:00
|
|
|
class WriteBatchWithIndexJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::WriteBatchWithIndex*,
|
|
|
|
WriteBatchWithIndexJni> {
|
2014-08-03 20:11:44 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.WriteBatchWithIndex
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2014-08-03 20:11:44 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/WriteBatchWithIndex");
|
2014-08-03 20:11:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.HistogramData
|
|
|
|
class HistogramDataJni : public JavaClass {
|
2014-08-03 20:11:44 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.HistogramData
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2014-08-03 20:11:44 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/HistogramData");
|
2014-08-03 20:11:44 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: HistogramData constructor
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getConstructorMethodId(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "<init>", "(DDDDDDJJD)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
};
|
2017-09-22 00:15:27 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.BackupableDBOptions
|
2020-02-20 20:07:53 +00:00
|
|
|
class BackupableDBOptionsJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::BackupableDBOptions*,
|
|
|
|
BackupableDBOptionsJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.BackupableDBOptions
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/BackupableDBOptions");
|
|
|
|
}
|
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.BackupEngine
|
2020-02-20 20:07:53 +00:00
|
|
|
class BackupEngineJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::BackupEngine*,
|
|
|
|
BackupEngineJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.BackupableEngine
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/BackupEngine");
|
2014-08-03 20:11:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.RocksIterator
|
2020-02-20 20:07:53 +00:00
|
|
|
class IteratorJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::Iterator*, IteratorJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.RocksIterator
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/RocksIterator");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.Filter
|
2020-02-20 20:07:53 +00:00
|
|
|
class FilterJni
|
|
|
|
: public RocksDBNativeClass<
|
|
|
|
std::shared_ptr<ROCKSDB_NAMESPACE::FilterPolicy>*, FilterJni> {
|
2014-08-03 20:11:44 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.Filter
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2014-08-03 20:11:44 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/Filter");
|
2014-08-03 20:11:44 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2014-08-03 20:11:44 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.ColumnFamilyHandle
|
2020-02-20 20:07:53 +00:00
|
|
|
class ColumnFamilyHandleJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::ColumnFamilyHandle*,
|
|
|
|
ColumnFamilyHandleJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.ColumnFamilyHandle
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/ColumnFamilyHandle");
|
2014-08-03 20:11:44 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.FlushOptions
|
2020-02-20 20:07:53 +00:00
|
|
|
class FlushOptionsJni
|
|
|
|
: public RocksDBNativeClass<ROCKSDB_NAMESPACE::FlushOptions*,
|
|
|
|
FlushOptionsJni> {
|
2014-04-25 20:57:20 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.FlushOptions
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/FlushOptions");
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.ComparatorOptions
|
2020-02-20 20:07:53 +00:00
|
|
|
class ComparatorOptionsJni
|
|
|
|
: public RocksDBNativeClass<
|
|
|
|
ROCKSDB_NAMESPACE::ComparatorJniCallbackOptions*,
|
|
|
|
ComparatorOptionsJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.ComparatorOptions
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/ComparatorOptions");
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.AbstractCompactionFilterFactory
|
2020-02-20 20:07:53 +00:00
|
|
|
class AbstractCompactionFilterFactoryJni
|
|
|
|
: public RocksDBNativeClass<
|
|
|
|
const ROCKSDB_NAMESPACE::CompactionFilterFactoryJniCallback*,
|
|
|
|
AbstractCompactionFilterFactoryJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.AbstractCompactionFilterFactory
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/AbstractCompactionFilterFactory");
|
2014-04-25 20:57:20 +00:00
|
|
|
}
|
2014-04-26 03:59:16 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: AbstractCompactionFilterFactory#name
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getNameMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
2017-02-28 00:26:12 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "name", "()Ljava/lang/String;");
|
2014-04-25 20:57:20 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2014-04-26 03:59:16 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: AbstractCompactionFilterFactory#createCompactionFilter
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getCreateCompactionFilterMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
2017-02-28 00:26:12 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz,
|
|
|
|
"createCompactionFilter",
|
|
|
|
"(ZZ)J");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.AbstractTransactionNotifier
|
2020-02-20 20:07:53 +00:00
|
|
|
class AbstractTransactionNotifierJni
|
|
|
|
: public RocksDBNativeClass<
|
|
|
|
const ROCKSDB_NAMESPACE::TransactionNotifierJniCallback*,
|
|
|
|
AbstractTransactionNotifierJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/AbstractTransactionNotifier");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the java method `snapshotCreated`
|
|
|
|
// of org.rocksdb.AbstractTransactionNotifier.
|
|
|
|
static jmethodID getSnapshotCreatedMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "snapshotCreated", "(J)V");
|
2014-04-25 20:57:20 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
|
|
|
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
// The portal class for org.rocksdb.AbstractComparatorJniBridge
|
|
|
|
class AbstractComparatorJniBridge : public JavaClass {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
* Get the Java Class org.rocksdb.AbstractComparatorJniBridge
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
return JavaClass::getJClass(env,
|
|
|
|
"org/rocksdb/AbstractComparatorJniBridge");
|
2019-02-22 22:36:38 +00:00
|
|
|
}
|
2014-04-26 03:59:16 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
* Get the Java Method: Comparator#compareInternal
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
* @param jclazz the AbstractComparatorJniBridge class
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
static jmethodID getCompareInternalMethodId(JNIEnv* env, jclass jclazz) {
|
2017-02-28 00:26:12 +00:00
|
|
|
static jmethodID mid =
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
env->GetStaticMethodID(jclazz, "compareInternal",
|
|
|
|
"(Lorg/rocksdb/AbstractComparator;Ljava/nio/ByteBuffer;ILjava/nio/ByteBuffer;I)I");
|
2014-04-25 20:57:20 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2014-04-26 03:59:16 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
* Get the Java Method: Comparator#findShortestSeparatorInternal
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
* @param jclazz the AbstractComparatorJniBridge class
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
static jmethodID getFindShortestSeparatorInternalMethodId(JNIEnv* env, jclass jclazz) {
|
2017-02-28 00:26:12 +00:00
|
|
|
static jmethodID mid =
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
env->GetStaticMethodID(jclazz, "findShortestSeparatorInternal",
|
|
|
|
"(Lorg/rocksdb/AbstractComparator;Ljava/nio/ByteBuffer;ILjava/nio/ByteBuffer;I)I");
|
2014-04-25 20:57:20 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2014-04-26 03:59:16 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
* Get the Java Method: Comparator#findShortSuccessorInternal
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
* @param jclazz the AbstractComparatorJniBridge class
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
static jmethodID getFindShortSuccessorInternalMethodId(JNIEnv* env, jclass jclazz) {
|
2017-02-28 00:26:12 +00:00
|
|
|
static jmethodID mid =
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
env->GetStaticMethodID(jclazz, "findShortSuccessorInternal",
|
|
|
|
"(Lorg/rocksdb/AbstractComparator;Ljava/nio/ByteBuffer;I)I");
|
2014-04-25 20:57:20 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
};
|
2014-08-03 20:11:44 +00:00
|
|
|
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
// The portal class for org.rocksdb.AbstractComparator
|
2020-02-20 20:07:53 +00:00
|
|
|
class AbstractComparatorJni
|
|
|
|
: public RocksDBNativeClass<const ROCKSDB_NAMESPACE::ComparatorJniCallback*,
|
|
|
|
AbstractComparatorJni> {
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
* Get the Java Class org.rocksdb.AbstractComparator
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/AbstractComparator");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: Comparator#name
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
static jmethodID getNameMethodId(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
env->GetMethodID(jclazz, "name", "()Ljava/lang/String;");
|
2019-02-22 22:36:38 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.AbstractSlice
|
2020-02-20 20:07:53 +00:00
|
|
|
class AbstractSliceJni
|
|
|
|
: public NativeRocksMutableObject<const ROCKSDB_NAMESPACE::Slice*,
|
|
|
|
AbstractSliceJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.AbstractSlice
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/AbstractSlice");
|
2015-03-19 22:50:45 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2015-03-19 22:50:45 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.Slice
|
2020-02-20 20:07:53 +00:00
|
|
|
class SliceJni
|
|
|
|
: public NativeRocksMutableObject<const ROCKSDB_NAMESPACE::Slice*,
|
|
|
|
AbstractSliceJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.Slice
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/Slice");
|
2015-03-19 22:50:45 +00:00
|
|
|
}
|
2018-10-08 18:03:34 +00:00
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Constructs a Slice object
|
2018-10-08 18:03:34 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return A reference to a Java Slice object, or a nullptr if an
|
|
|
|
* exception occurs
|
2018-10-08 18:03:34 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jobject construct0(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
2018-10-08 18:03:34 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "<init>", "()V");
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception occurred accessing method
|
2018-10-08 18:03:34 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jobject jslice = env->NewObject(jclazz, mid);
|
|
|
|
if(env->ExceptionCheck()) {
|
2018-10-08 18:03:34 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jslice;
|
2018-10-08 18:03:34 +00:00
|
|
|
}
|
2015-03-19 22:50:45 +00:00
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.DirectSlice
|
2020-02-20 20:07:53 +00:00
|
|
|
class DirectSliceJni
|
|
|
|
: public NativeRocksMutableObject<const ROCKSDB_NAMESPACE::Slice*,
|
|
|
|
AbstractSliceJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.DirectSlice
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2014-10-26 22:23:06 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/DirectSlice");
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Constructs a DirectSlice object
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return A reference to a Java DirectSlice object, or a nullptr if an
|
|
|
|
* exception occurs
|
2017-02-28 00:26:12 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jobject construct0(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "<init>", "()V");
|
2017-02-28 00:26:12 +00:00
|
|
|
if(mid == nullptr) {
|
2019-02-22 22:36:38 +00:00
|
|
|
// exception occurred accessing method
|
2017-02-28 00:26:12 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jobject jdirect_slice = env->NewObject(jclazz, mid);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jdirect_slice;
|
2014-10-26 22:23:06 +00:00
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
};
|
2014-10-26 22:23:06 +00:00
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// The portal class for org.rocksdb.BackupInfo
|
|
|
|
class BackupInfoJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.BackupInfo
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/BackupInfo");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs a BackupInfo object
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param backup_id id of the backup
|
|
|
|
* @param timestamp timestamp of the backup
|
|
|
|
* @param size size of the backup
|
|
|
|
* @param number_files number of files related to the backup
|
2018-07-11 22:44:52 +00:00
|
|
|
* @param app_metadata application specific metadata
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @return A reference to a Java BackupInfo object, or a nullptr if an
|
|
|
|
* exception occurs
|
|
|
|
*/
|
2014-10-26 22:23:06 +00:00
|
|
|
static jobject construct0(JNIEnv* env, uint32_t backup_id, int64_t timestamp,
|
2018-07-14 05:40:23 +00:00
|
|
|
uint64_t size, uint32_t number_files,
|
|
|
|
const std::string& app_metadata) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-07-14 05:40:23 +00:00
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "<init>", "(IJJILjava/lang/String;)V");
|
2017-02-28 00:26:12 +00:00
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception occurred accessing method
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-07-11 22:44:52 +00:00
|
|
|
jstring japp_metadata = nullptr;
|
|
|
|
if (app_metadata != nullptr) {
|
|
|
|
japp_metadata = env->NewStringUTF(app_metadata.c_str());
|
|
|
|
if (japp_metadata == nullptr) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-14 05:40:23 +00:00
|
|
|
jobject jbackup_info = env->NewObject(jclazz, mid, backup_id, timestamp,
|
|
|
|
size, number_files, japp_metadata);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(env->ExceptionCheck()) {
|
2018-07-11 22:44:52 +00:00
|
|
|
env->DeleteLocalRef(japp_metadata);
|
2017-02-28 00:26:12 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jbackup_info;
|
2014-10-26 22:23:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class BackupInfoListJni {
|
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Converts a C++ std::vector<BackupInfo> object to
|
|
|
|
* a Java ArrayList<org.rocksdb.BackupInfo> object
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param backup_infos A vector of BackupInfo
|
|
|
|
*
|
|
|
|
* @return Either a reference to a Java ArrayList object, or a nullptr
|
|
|
|
* if an exception occurs
|
|
|
|
*/
|
2014-10-26 22:23:06 +00:00
|
|
|
static jobject getBackupInfo(JNIEnv* env,
|
|
|
|
std::vector<BackupInfo> backup_infos) {
|
2020-02-20 20:07:53 +00:00
|
|
|
jclass jarray_list_clazz =
|
|
|
|
ROCKSDB_NAMESPACE::ListJni::getArrayListClass(env);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(jarray_list_clazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jmethodID cstr_mid =
|
|
|
|
ROCKSDB_NAMESPACE::ListJni::getArrayListConstructorMethodId(env);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(cstr_mid == nullptr) {
|
|
|
|
// exception occurred accessing method
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jmethodID add_mid = ROCKSDB_NAMESPACE::ListJni::getListAddMethodId(env);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(add_mid == nullptr) {
|
|
|
|
// exception occurred accessing method
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// create java list
|
|
|
|
jobject jbackup_info_handle_list =
|
|
|
|
env->NewObject(jarray_list_clazz, cstr_mid, backup_infos.size());
|
|
|
|
if(env->ExceptionCheck()) {
|
2017-06-05 18:23:31 +00:00
|
|
|
// exception occurred constructing object
|
2017-02-28 00:26:12 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2014-10-26 22:23:06 +00:00
|
|
|
// insert in java list
|
2017-02-28 00:26:12 +00:00
|
|
|
auto end = backup_infos.end();
|
|
|
|
for (auto it = backup_infos.begin(); it != end; ++it) {
|
|
|
|
auto backup_info = *it;
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jobject obj = ROCKSDB_NAMESPACE::BackupInfoJni::construct0(
|
2018-07-14 05:40:23 +00:00
|
|
|
env, backup_info.backup_id, backup_info.timestamp, backup_info.size,
|
|
|
|
backup_info.number_files, backup_info.app_metadata);
|
2017-02-28 00:26:12 +00:00
|
|
|
if(env->ExceptionCheck()) {
|
2017-06-05 18:23:31 +00:00
|
|
|
// exception occurred constructing object
|
2017-02-28 00:26:12 +00:00
|
|
|
if(obj != nullptr) {
|
|
|
|
env->DeleteLocalRef(obj);
|
|
|
|
}
|
|
|
|
if(jbackup_info_handle_list != nullptr) {
|
|
|
|
env->DeleteLocalRef(jbackup_info_handle_list);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jboolean rs =
|
|
|
|
env->CallBooleanMethod(jbackup_info_handle_list, add_mid, obj);
|
|
|
|
if(env->ExceptionCheck() || rs == JNI_FALSE) {
|
2017-06-05 18:23:31 +00:00
|
|
|
// exception occurred calling method, or could not add
|
2017-02-28 00:26:12 +00:00
|
|
|
if(obj != nullptr) {
|
|
|
|
env->DeleteLocalRef(obj);
|
|
|
|
}
|
|
|
|
if(jbackup_info_handle_list != nullptr) {
|
|
|
|
env->DeleteLocalRef(jbackup_info_handle_list);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-10-26 22:23:06 +00:00
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2014-10-26 22:23:06 +00:00
|
|
|
return jbackup_info_handle_list;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// The portal class for org.rocksdb.WBWIRocksIterator
|
|
|
|
class WBWIRocksIteratorJni : public JavaClass {
|
2015-01-03 15:23:24 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.WBWIRocksIterator
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/WBWIRocksIterator");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Field: WBWIRocksIterator#entry
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Field ID or nullptr if the class or field id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jfieldID getWriteEntryField(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
2015-01-03 15:23:24 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
static jfieldID fid =
|
|
|
|
env->GetFieldID(jclazz, "entry",
|
|
|
|
"Lorg/rocksdb/WBWIRocksIterator$WriteEntry;");
|
|
|
|
assert(fid != nullptr);
|
|
|
|
return fid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the value of the WBWIRocksIterator#entry
|
|
|
|
*
|
2017-09-22 00:15:27 +00:00
|
|
|
* @param env A pointer to the Java environment
|
2017-02-28 00:26:12 +00:00
|
|
|
* @param jwbwi_rocks_iterator A reference to a WBWIIterator
|
|
|
|
*
|
|
|
|
* @return A reference to a Java WBWIRocksIterator.WriteEntry object, or
|
|
|
|
* a nullptr if an exception occurs
|
|
|
|
*/
|
|
|
|
static jobject getWriteEntry(JNIEnv* env, jobject jwbwi_rocks_iterator) {
|
|
|
|
assert(jwbwi_rocks_iterator != nullptr);
|
|
|
|
|
|
|
|
jfieldID jwrite_entry_field = getWriteEntryField(env);
|
|
|
|
if(jwrite_entry_field == nullptr) {
|
|
|
|
// exception occurred accessing the field
|
|
|
|
return nullptr;
|
2015-01-03 15:23:24 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
jobject jwe = env->GetObjectField(jwbwi_rocks_iterator, jwrite_entry_field);
|
|
|
|
assert(jwe != nullptr);
|
|
|
|
return jwe;
|
|
|
|
}
|
2015-01-03 15:23:24 +00:00
|
|
|
};
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// The portal class for org.rocksdb.WBWIRocksIterator.WriteType
|
|
|
|
class WriteTypeJni : public JavaClass {
|
2015-01-03 15:23:24 +00:00
|
|
|
public:
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
|
|
|
* Get the PUT enum field value of WBWIRocksIterator.WriteType
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
|
|
|
static jobject PUT(JNIEnv* env) {
|
|
|
|
return getEnum(env, "PUT");
|
|
|
|
}
|
2015-01-03 15:23:24 +00:00
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
|
|
|
* Get the MERGE enum field value of WBWIRocksIterator.WriteType
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
|
|
|
static jobject MERGE(JNIEnv* env) {
|
|
|
|
return getEnum(env, "MERGE");
|
|
|
|
}
|
2015-01-03 15:23:24 +00:00
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
|
|
|
* Get the DELETE enum field value of WBWIRocksIterator.WriteType
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
|
|
|
static jobject DELETE(JNIEnv* env) {
|
|
|
|
return getEnum(env, "DELETE");
|
|
|
|
}
|
2015-01-03 15:23:24 +00:00
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
/**
|
|
|
|
* Get the LOG enum field value of WBWIRocksIterator.WriteType
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
|
|
|
static jobject LOG(JNIEnv* env) {
|
|
|
|
return getEnum(env, "LOG");
|
|
|
|
}
|
2018-04-13 00:55:14 +00:00
|
|
|
|
2018-03-02 23:33:08 +00:00
|
|
|
// Returns the equivalent org.rocksdb.WBWIRocksIterator.WriteType for the
|
2020-02-20 20:07:53 +00:00
|
|
|
// provided C++ ROCKSDB_NAMESPACE::WriteType enum
|
|
|
|
static jbyte toJavaWriteType(const ROCKSDB_NAMESPACE::WriteType& writeType) {
|
2018-03-02 23:33:08 +00:00
|
|
|
switch (writeType) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WriteType::kPutRecord:
|
2018-03-02 23:33:08 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WriteType::kMergeRecord:
|
2018-03-02 23:33:08 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WriteType::kDeleteRecord:
|
2018-03-02 23:33:08 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WriteType::kSingleDeleteRecord:
|
2018-03-02 23:33:08 +00:00
|
|
|
return 0x3;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WriteType::kDeleteRangeRecord:
|
2018-03-02 23:33:08 +00:00
|
|
|
return 0x4;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WriteType::kLogDataRecord:
|
2018-03-02 23:33:08 +00:00
|
|
|
return 0x5;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WriteType::kXIDRecord:
|
2018-03-02 23:33:08 +00:00
|
|
|
return 0x6;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
2015-01-03 15:23:24 +00:00
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
2015-01-03 15:23:24 +00:00
|
|
|
|
|
|
|
private:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.WBWIRocksIterator.WriteType
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/WBWIRocksIterator$WriteType");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an enum field of org.rocksdb.WBWIRocksIterator.WriteType
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param name The name of the enum field
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
|
|
|
static jobject getEnum(JNIEnv* env, const char name[]) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
2015-01-03 15:23:24 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
jfieldID jfid =
|
|
|
|
env->GetStaticFieldID(jclazz, name,
|
|
|
|
"Lorg/rocksdb/WBWIRocksIterator$WriteType;");
|
|
|
|
if(env->ExceptionCheck()) {
|
2017-06-05 18:23:31 +00:00
|
|
|
// exception occurred while getting field
|
2017-02-28 00:26:12 +00:00
|
|
|
return nullptr;
|
|
|
|
} else if(jfid == nullptr) {
|
|
|
|
return nullptr;
|
2015-01-03 15:23:24 +00:00
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
|
|
|
jobject jwrite_type = env->GetStaticObjectField(jclazz, jfid);
|
|
|
|
assert(jwrite_type != nullptr);
|
|
|
|
return jwrite_type;
|
|
|
|
}
|
2015-01-03 15:23:24 +00:00
|
|
|
};
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// The portal class for org.rocksdb.WBWIRocksIterator.WriteEntry
|
|
|
|
class WriteEntryJni : public JavaClass {
|
2015-01-03 15:23:24 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.WBWIRocksIterator.WriteEntry
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2015-01-03 15:23:24 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/WBWIRocksIterator$WriteEntry");
|
2015-01-03 15:23:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// The portal class for org.rocksdb.InfoLogLevel
|
|
|
|
class InfoLogLevelJni : public JavaClass {
|
2015-02-10 20:59:40 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the DEBUG_LEVEL enum field value of InfoLogLevel
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
2015-02-10 20:59:40 +00:00
|
|
|
static jobject DEBUG_LEVEL(JNIEnv* env) {
|
|
|
|
return getEnum(env, "DEBUG_LEVEL");
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the INFO_LEVEL enum field value of InfoLogLevel
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
2015-02-10 20:59:40 +00:00
|
|
|
static jobject INFO_LEVEL(JNIEnv* env) {
|
|
|
|
return getEnum(env, "INFO_LEVEL");
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the WARN_LEVEL enum field value of InfoLogLevel
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
2015-02-10 20:59:40 +00:00
|
|
|
static jobject WARN_LEVEL(JNIEnv* env) {
|
|
|
|
return getEnum(env, "WARN_LEVEL");
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the ERROR_LEVEL enum field value of InfoLogLevel
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
2015-02-10 20:59:40 +00:00
|
|
|
static jobject ERROR_LEVEL(JNIEnv* env) {
|
|
|
|
return getEnum(env, "ERROR_LEVEL");
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the FATAL_LEVEL enum field value of InfoLogLevel
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
2015-02-10 20:59:40 +00:00
|
|
|
static jobject FATAL_LEVEL(JNIEnv* env) {
|
|
|
|
return getEnum(env, "FATAL_LEVEL");
|
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the HEADER_LEVEL enum field value of InfoLogLevel
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
2016-05-06 22:06:12 +00:00
|
|
|
static jobject HEADER_LEVEL(JNIEnv* env) {
|
|
|
|
return getEnum(env, "HEADER_LEVEL");
|
|
|
|
}
|
|
|
|
|
2015-02-10 20:59:40 +00:00
|
|
|
private:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.InfoLogLevel
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/InfoLogLevel");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an enum field of org.rocksdb.InfoLogLevel
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param name The name of the enum field
|
|
|
|
*
|
|
|
|
* @return A reference to the enum field value or a nullptr if
|
|
|
|
* the enum field value could not be retrieved
|
|
|
|
*/
|
|
|
|
static jobject getEnum(JNIEnv* env, const char name[]) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
2015-02-10 20:59:40 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
jfieldID jfid =
|
|
|
|
env->GetStaticFieldID(jclazz, name, "Lorg/rocksdb/InfoLogLevel;");
|
|
|
|
if(env->ExceptionCheck()) {
|
2017-06-05 18:23:31 +00:00
|
|
|
// exception occurred while getting field
|
2017-02-28 00:26:12 +00:00
|
|
|
return nullptr;
|
|
|
|
} else if(jfid == nullptr) {
|
|
|
|
return nullptr;
|
2015-02-10 20:59:40 +00:00
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
|
|
|
jobject jinfo_log_level = env->GetStaticObjectField(jclazz, jfid);
|
|
|
|
assert(jinfo_log_level != nullptr);
|
|
|
|
return jinfo_log_level;
|
|
|
|
}
|
2015-02-10 20:59:40 +00:00
|
|
|
};
|
|
|
|
|
2015-03-10 22:16:21 +00:00
|
|
|
// The portal class for org.rocksdb.Logger
|
2020-02-20 20:07:53 +00:00
|
|
|
class LoggerJni
|
|
|
|
: public RocksDBNativeClass<
|
|
|
|
std::shared_ptr<ROCKSDB_NAMESPACE::LoggerJniCallback>*, LoggerJni> {
|
2015-02-10 20:59:40 +00:00
|
|
|
public:
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Class org/rocksdb/Logger
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
2015-02-10 20:59:40 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
return RocksDBNativeClass::getJClass(env, "org/rocksdb/Logger");
|
2015-02-10 20:59:40 +00:00
|
|
|
}
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Method: Logger#log
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2015-02-10 20:59:40 +00:00
|
|
|
static jmethodID getLogMethodId(JNIEnv* env) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "log",
|
|
|
|
"(Lorg/rocksdb/InfoLogLevel;Ljava/lang/String;)V");
|
2015-02-10 20:59:40 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-28 00:26:12 +00:00
|
|
|
// The portal class for org.rocksdb.TransactionLogIterator.BatchResult
|
|
|
|
class BatchResultJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.TransactionLogIterator.BatchResult
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env,
|
|
|
|
"org/rocksdb/TransactionLogIterator$BatchResult");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.TransactionLogIterator.BatchResult object
|
2020-02-20 20:07:53 +00:00
|
|
|
* with the same properties as the provided C++ ROCKSDB_NAMESPACE::BatchResult
|
|
|
|
* object
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2020-02-20 20:07:53 +00:00
|
|
|
* @param batch_result The ROCKSDB_NAMESPACE::BatchResult object
|
2017-02-28 00:26:12 +00:00
|
|
|
*
|
|
|
|
* @return A reference to a Java
|
|
|
|
* org.rocksdb.TransactionLogIterator.BatchResult object,
|
|
|
|
* or nullptr if an an exception occurs
|
|
|
|
*/
|
|
|
|
static jobject construct(JNIEnv* env,
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::BatchResult& batch_result) {
|
2017-02-28 00:26:12 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "<init>", "(JJ)V");
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jbatch_result = env->NewObject(jclazz, mid,
|
|
|
|
batch_result.sequence, batch_result.writeBatchPtr.get());
|
|
|
|
if(jbatch_result == nullptr) {
|
|
|
|
// exception thrown: InstantiationException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
batch_result.writeBatchPtr.release();
|
|
|
|
return jbatch_result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-08-17 17:52:58 +00:00
|
|
|
// The portal class for org.rocksdb.BottommostLevelCompaction
|
|
|
|
class BottommostLevelCompactionJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.BottommostLevelCompaction for the
|
|
|
|
// provided C++ ROCKSDB_NAMESPACE::BottommostLevelCompaction enum
|
2018-08-17 17:52:58 +00:00
|
|
|
static jint toJavaBottommostLevelCompaction(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::BottommostLevelCompaction&
|
|
|
|
bottommost_level_compaction) {
|
2018-08-17 17:52:58 +00:00
|
|
|
switch(bottommost_level_compaction) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::BottommostLevelCompaction::kSkip:
|
2018-08-17 17:52:58 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::BottommostLevelCompaction::
|
|
|
|
kIfHaveCompactionFilter:
|
2018-08-17 17:52:58 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::BottommostLevelCompaction::kForce:
|
2018-08-17 17:52:58 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::BottommostLevelCompaction::kForceOptimized:
|
2019-04-17 06:29:32 +00:00
|
|
|
return 0x3;
|
2018-08-17 17:52:58 +00:00
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::BottommostLevelCompaction
|
|
|
|
// enum for the provided Java org.rocksdb.BottommostLevelCompaction
|
|
|
|
static ROCKSDB_NAMESPACE::BottommostLevelCompaction
|
|
|
|
toCppBottommostLevelCompaction(jint bottommost_level_compaction) {
|
2018-08-17 17:52:58 +00:00
|
|
|
switch(bottommost_level_compaction) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::BottommostLevelCompaction::kSkip;
|
2018-08-17 17:52:58 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::BottommostLevelCompaction::
|
|
|
|
kIfHaveCompactionFilter;
|
2018-08-17 17:52:58 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::BottommostLevelCompaction::kForce;
|
2019-04-17 06:29:32 +00:00
|
|
|
case 0x3:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::BottommostLevelCompaction::kForceOptimized;
|
2018-08-17 17:52:58 +00:00
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::BottommostLevelCompaction::
|
|
|
|
kIfHaveCompactionFilter;
|
2018-08-17 17:52:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-03-30 19:04:09 +00:00
|
|
|
// The portal class for org.rocksdb.CompactionStopStyle
|
|
|
|
class CompactionStopStyleJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.CompactionStopStyle for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::CompactionStopStyle enum
|
2017-03-30 19:04:09 +00:00
|
|
|
static jbyte toJavaCompactionStopStyle(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::CompactionStopStyle& compaction_stop_style) {
|
2017-03-30 19:04:09 +00:00
|
|
|
switch(compaction_stop_style) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompactionStopStyle::
|
|
|
|
kCompactionStopStyleSimilarSize:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompactionStopStyle::
|
|
|
|
kCompactionStopStyleTotalSize:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x1;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::CompactionStopStyle enum for
|
|
|
|
// the provided Java org.rocksdb.CompactionStopStyle
|
|
|
|
static ROCKSDB_NAMESPACE::CompactionStopStyle toCppCompactionStopStyle(
|
2017-03-30 19:04:09 +00:00
|
|
|
jbyte jcompaction_stop_style) {
|
|
|
|
switch(jcompaction_stop_style) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompactionStopStyle::
|
|
|
|
kCompactionStopStyleSimilarSize;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompactionStopStyle::
|
|
|
|
kCompactionStopStyleTotalSize;
|
2017-03-30 19:04:09 +00:00
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompactionStopStyle::
|
|
|
|
kCompactionStopStyleSimilarSize;
|
2017-03-30 19:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.CompressionType
|
|
|
|
class CompressionTypeJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.CompressionType for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::CompressionType enum
|
2017-03-30 19:04:09 +00:00
|
|
|
static jbyte toJavaCompressionType(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::CompressionType& compression_type) {
|
2017-03-30 19:04:09 +00:00
|
|
|
switch(compression_type) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kNoCompression:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kSnappyCompression:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kZlibCompression:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kBZip2Compression:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x3;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kLZ4Compression:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x4;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kLZ4HCCompression:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x5;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kXpressCompression:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x6;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kZSTD:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x7;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompressionType::kDisableCompressionOption:
|
2017-03-30 19:04:09 +00:00
|
|
|
default:
|
|
|
|
return 0x7F;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::CompressionType enum for the
|
2017-03-30 19:04:09 +00:00
|
|
|
// provided Java org.rocksdb.CompressionType
|
2020-02-20 20:07:53 +00:00
|
|
|
static ROCKSDB_NAMESPACE::CompressionType toCppCompressionType(
|
2017-03-30 19:04:09 +00:00
|
|
|
jbyte jcompression_type) {
|
|
|
|
switch(jcompression_type) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kNoCompression;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kSnappyCompression;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kZlibCompression;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x3:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kBZip2Compression;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x4:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kLZ4Compression;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x5:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kLZ4HCCompression;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x6:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kXpressCompression;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x7:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kZSTD;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x7F:
|
|
|
|
default:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompressionType::kDisableCompressionOption;
|
2017-03-30 19:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.CompactionPriority
|
|
|
|
class CompactionPriorityJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.CompactionPriority for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::CompactionPri enum
|
2017-03-30 19:04:09 +00:00
|
|
|
static jbyte toJavaCompactionPriority(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::CompactionPri& compaction_priority) {
|
2017-03-30 19:04:09 +00:00
|
|
|
switch(compaction_priority) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompactionPri::kByCompensatedSize:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompactionPri::kOldestLargestSeqFirst:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompactionPri::kOldestSmallestSeqFirst:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::CompactionPri::kMinOverlappingRatio:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
return 0x0; // undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::CompactionPri enum for the
|
2017-03-30 19:04:09 +00:00
|
|
|
// provided Java org.rocksdb.CompactionPriority
|
2020-02-20 20:07:53 +00:00
|
|
|
static ROCKSDB_NAMESPACE::CompactionPri toCppCompactionPriority(
|
2017-03-30 19:04:09 +00:00
|
|
|
jbyte jcompaction_priority) {
|
|
|
|
switch(jcompaction_priority) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompactionPri::kByCompensatedSize;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompactionPri::kOldestLargestSeqFirst;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompactionPri::kOldestSmallestSeqFirst;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x3:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompactionPri::kMinOverlappingRatio;
|
2017-03-30 19:04:09 +00:00
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::CompactionPri::kByCompensatedSize;
|
2017-03-30 19:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.AccessHint
|
|
|
|
class AccessHintJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.AccessHint for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::DBOptions::AccessHint enum
|
2017-03-30 19:04:09 +00:00
|
|
|
static jbyte toJavaAccessHint(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::DBOptions::AccessHint& access_hint) {
|
2017-03-30 19:04:09 +00:00
|
|
|
switch(access_hint) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::DBOptions::AccessHint::NONE:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::DBOptions::AccessHint::NORMAL:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::DBOptions::AccessHint::SEQUENTIAL:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::DBOptions::AccessHint::WILLNEED:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return 0x1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::DBOptions::AccessHint enum
|
|
|
|
// for the provided Java org.rocksdb.AccessHint
|
|
|
|
static ROCKSDB_NAMESPACE::DBOptions::AccessHint toCppAccessHint(
|
|
|
|
jbyte jaccess_hint) {
|
2017-03-30 19:04:09 +00:00
|
|
|
switch(jaccess_hint) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::DBOptions::AccessHint::NONE;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::DBOptions::AccessHint::NORMAL;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::DBOptions::AccessHint::SEQUENTIAL;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x3:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::DBOptions::AccessHint::WILLNEED;
|
2017-03-30 19:04:09 +00:00
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::DBOptions::AccessHint::NORMAL;
|
2017-03-30 19:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.WALRecoveryMode
|
|
|
|
class WALRecoveryModeJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.WALRecoveryMode for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::WALRecoveryMode enum
|
2017-03-30 19:04:09 +00:00
|
|
|
static jbyte toJavaWALRecoveryMode(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::WALRecoveryMode& wal_recovery_mode) {
|
2017-03-30 19:04:09 +00:00
|
|
|
switch(wal_recovery_mode) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WALRecoveryMode::kTolerateCorruptedTailRecords:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WALRecoveryMode::kAbsoluteConsistency:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WALRecoveryMode::kPointInTimeRecovery:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::WALRecoveryMode::kSkipAnyCorruptedRecords:
|
2017-03-30 19:04:09 +00:00
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return 0x2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::WALRecoveryMode enum for the
|
2017-03-30 19:04:09 +00:00
|
|
|
// provided Java org.rocksdb.WALRecoveryMode
|
2020-02-20 20:07:53 +00:00
|
|
|
static ROCKSDB_NAMESPACE::WALRecoveryMode toCppWALRecoveryMode(
|
|
|
|
jbyte jwal_recovery_mode) {
|
2017-03-30 19:04:09 +00:00
|
|
|
switch(jwal_recovery_mode) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::WALRecoveryMode::
|
|
|
|
kTolerateCorruptedTailRecords;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::WALRecoveryMode::kAbsoluteConsistency;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::WALRecoveryMode::kPointInTimeRecovery;
|
2017-03-30 19:04:09 +00:00
|
|
|
case 0x3:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::WALRecoveryMode::kSkipAnyCorruptedRecords;
|
2017-03-30 19:04:09 +00:00
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::WALRecoveryMode::kPointInTimeRecovery;
|
2017-03-30 19:04:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-12 06:19:53 +00:00
|
|
|
// The portal class for org.rocksdb.TickerType
|
|
|
|
class TickerTypeJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.TickerType for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::Tickers enum
|
|
|
|
static jbyte toJavaTickerType(const ROCKSDB_NAMESPACE::Tickers& tickers) {
|
2017-07-12 06:19:53 +00:00
|
|
|
switch(tickers) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_ADD:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_ADD_FAILURES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x3;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x4;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x5;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_ADD:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x6;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_BYTES_INSERT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x7;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_BYTES_EVICT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x8;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x9;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xA;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_ADD:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xB;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_BYTES_INSERT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xC;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_BYTES_EVICT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xD;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_DATA_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xE;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_DATA_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xF;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_DATA_ADD:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x10;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_DATA_BYTES_INSERT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x11;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_BYTES_READ:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x12;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_BYTES_WRITE:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x13;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_USEFUL:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x14;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::PERSISTENT_CACHE_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x15;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::PERSISTENT_CACHE_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x16;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::SIM_BLOCK_CACHE_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x17;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::SIM_BLOCK_CACHE_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x18;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::MEMTABLE_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x19;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::MEMTABLE_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::GET_HIT_L0:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::GET_HIT_L1:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::GET_HIT_L2_AND_UP:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACTION_KEY_DROP_NEWER_ENTRY:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1E;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACTION_KEY_DROP_OBSOLETE:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1F;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACTION_KEY_DROP_RANGE_DEL:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x20;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACTION_KEY_DROP_USER:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x21;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACTION_RANGE_DEL_DROP_OBSOLETE:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x22;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_KEYS_WRITTEN:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x23;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_KEYS_READ:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x24;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_KEYS_UPDATED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x25;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BYTES_WRITTEN:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x26;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BYTES_READ:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x27;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_SEEK:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x28;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_NEXT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x29;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_PREV:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_SEEK_FOUND:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_NEXT_FOUND:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_PREV_FOUND:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::ITER_BYTES_READ:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2E;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NO_FILE_CLOSES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2F;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NO_FILE_OPENS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x30;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NO_FILE_ERRORS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x31;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::STALL_L0_SLOWDOWN_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x32;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::STALL_MEMTABLE_COMPACTION_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x33;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::STALL_L0_NUM_FILES_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x34;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::STALL_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x35;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::DB_MUTEX_WAIT_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x36;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::RATE_LIMIT_DELAY_MILLIS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x37;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NO_ITERATORS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x38;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_MULTIGET_CALLS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x39;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_MULTIGET_KEYS_READ:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x3A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_MULTIGET_BYTES_READ:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x3B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_FILTERED_DELETES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x3C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_MERGE_FAILURES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x3D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_PREFIX_CHECKED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x3E;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_PREFIX_USEFUL:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x3F;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_OF_RESEEKS_IN_ITERATION:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x40;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::GET_UPDATES_SINCE_CALLS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x41;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_COMPRESSED_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x42;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_COMPRESSED_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x43;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_COMPRESSED_ADD:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x44;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_COMPRESSED_ADD_FAILURES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x45;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::WAL_FILE_SYNCED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x46;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::WAL_FILE_BYTES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x47;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::WRITE_DONE_BY_SELF:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x48;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::WRITE_DONE_BY_OTHER:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x49;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::WRITE_TIMEDOUT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x4A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::WRITE_WITH_WAL:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x4B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACT_READ_BYTES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x4C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACT_WRITE_BYTES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x4D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::FLUSH_WRITE_BYTES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x4E;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_DIRECT_LOAD_TABLE_PROPERTIES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x4F;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_SUPERVERSION_ACQUIRES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x50;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_SUPERVERSION_RELEASES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x51;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_SUPERVERSION_CLEANUPS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x52;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_BLOCK_COMPRESSED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x53;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_BLOCK_DECOMPRESSED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x54;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_BLOCK_NOT_COMPRESSED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x55;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::MERGE_OPERATION_TOTAL_TIME:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x56;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::FILTER_OPERATION_TOTAL_TIME:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x57;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::ROW_CACHE_HIT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x58;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::ROW_CACHE_MISS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x59;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::READ_AMP_ESTIMATE_USEFUL_BYTES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x5A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::READ_AMP_TOTAL_READ_BYTES:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x5B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_RATE_LIMITER_DRAINS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x5C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_ITER_SKIP:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x5D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NUMBER_MULTIGET_KEYS_FOUND:
|
2017-11-21 05:12:55 +00:00
|
|
|
return 0x5E;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NO_ITERATOR_CREATED:
|
2018-12-14 19:34:29 +00:00
|
|
|
// -0x01 to fixate the new value that incorrectly changed TICKER_ENUM_MAX.
|
|
|
|
return -0x01;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::NO_ITERATOR_DELETED:
|
2018-11-13 19:44:25 +00:00
|
|
|
return 0x60;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACTION_OPTIMIZED_DEL_DROP_OBSOLETE:
|
2018-11-20 21:10:05 +00:00
|
|
|
return 0x61;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACTION_CANCELLED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x62;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_FULL_POSITIVE:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x63;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_FULL_TRUE_POSITIVE:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x64;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_PUT:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x65;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_WRITE:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x66;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_GET:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x67;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_MULTIGET:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x68;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_SEEK:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x69;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_NEXT:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x6A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_PREV:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x6B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_KEYS_WRITTEN:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x6C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_KEYS_READ:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x6D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BYTES_WRITTEN:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x6E;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BYTES_READ:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x6F;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_WRITE_INLINED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x70;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_WRITE_INLINED_TTL:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x71;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_WRITE_BLOB:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x72;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_WRITE_BLOB_TTL:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x73;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_FILE_BYTES_WRITTEN:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x74;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_FILE_BYTES_READ:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x75;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_FILE_SYNCED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x76;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_INDEX_EXPIRED_COUNT:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x77;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_INDEX_EXPIRED_SIZE:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x78;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_INDEX_EVICTED_COUNT:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x79;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_INDEX_EVICTED_SIZE:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x7A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_FILES:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x7B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_NEW_FILES:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x7C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_FAILURES:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x7D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_KEYS_OVERWRITTEN:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x7E;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_KEYS_EXPIRED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x7F;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_KEYS_RELOCATED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x02;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_BYTES_OVERWRITTEN:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x03;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_BYTES_EXPIRED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x04;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_BYTES_RELOCATED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x05;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_FIFO_NUM_FILES_EVICTED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x06;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_FIFO_NUM_KEYS_EVICTED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x07;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::BLOB_DB_FIFO_BYTES_EVICTED:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x08;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::TXN_PREPARE_MUTEX_OVERHEAD:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x09;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::TXN_OLD_COMMIT_MAP_MUTEX_OVERHEAD:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x0A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::TXN_DUPLICATE_KEY_OVERHEAD:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x0B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::TXN_SNAPSHOT_MUTEX_OVERHEAD:
|
2018-12-14 19:34:29 +00:00
|
|
|
return -0x0C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::TXN_GET_TRY_AGAIN:
|
2019-08-05 20:30:56 +00:00
|
|
|
return -0x0D;
|
2020-06-05 16:41:03 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::FILES_MARKED_TRASH:
|
|
|
|
return -0x0E;
|
|
|
|
case ROCKSDB_NAMESPACE::Tickers::FILES_DELETED_IMMEDIATELY:
|
|
|
|
return -0X0F;
|
2020-07-29 20:38:07 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACT_READ_BYTES_MARKED:
|
|
|
|
return -0x10;
|
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACT_READ_BYTES_PERIODIC:
|
|
|
|
return -0x11;
|
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACT_READ_BYTES_TTL:
|
|
|
|
return -0x12;
|
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACT_WRITE_BYTES_MARKED:
|
|
|
|
return -0x13;
|
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACT_WRITE_BYTES_PERIODIC:
|
|
|
|
return -0x14;
|
|
|
|
case ROCKSDB_NAMESPACE::Tickers::COMPACT_WRITE_BYTES_TTL:
|
|
|
|
return -0x15;
|
2020-06-05 16:41:03 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Tickers::TICKER_ENUM_MAX:
|
2018-12-14 19:34:29 +00:00
|
|
|
// 0x5F for backwards compatibility on current minor version.
|
|
|
|
return 0x5F;
|
2017-07-12 06:19:53 +00:00
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::Tickers enum for the
|
2017-07-12 06:19:53 +00:00
|
|
|
// provided Java org.rocksdb.TickerType
|
2020-02-20 20:07:53 +00:00
|
|
|
static ROCKSDB_NAMESPACE::Tickers toCppTickers(jbyte jticker_type) {
|
2017-07-12 06:19:53 +00:00
|
|
|
switch(jticker_type) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_ADD;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x3:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_ADD_FAILURES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x4:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x5:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x6:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_ADD;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x7:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_BYTES_INSERT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x8:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_INDEX_BYTES_EVICT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x9:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xA:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xB:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_ADD;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xC:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_BYTES_INSERT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xD:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_FILTER_BYTES_EVICT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xE:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_DATA_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xF:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_DATA_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x10:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_DATA_ADD;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x11:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_DATA_BYTES_INSERT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x12:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_BYTES_READ;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x13:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_BYTES_WRITE;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x14:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_USEFUL;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x15:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::PERSISTENT_CACHE_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x16:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::PERSISTENT_CACHE_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x17:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::SIM_BLOCK_CACHE_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x18:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::SIM_BLOCK_CACHE_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x19:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::MEMTABLE_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::MEMTABLE_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::GET_HIT_L0;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::GET_HIT_L1;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::GET_HIT_L2_AND_UP;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACTION_KEY_DROP_NEWER_ENTRY;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1F:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACTION_KEY_DROP_OBSOLETE;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x20:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACTION_KEY_DROP_RANGE_DEL;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x21:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACTION_KEY_DROP_USER;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x22:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACTION_RANGE_DEL_DROP_OBSOLETE;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x23:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_KEYS_WRITTEN;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x24:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_KEYS_READ;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x25:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_KEYS_UPDATED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x26:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BYTES_WRITTEN;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x27:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BYTES_READ;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x28:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_SEEK;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x29:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_NEXT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_PREV;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_SEEK_FOUND;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_NEXT_FOUND;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_DB_PREV_FOUND;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::ITER_BYTES_READ;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2F:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NO_FILE_CLOSES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x30:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NO_FILE_OPENS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x31:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NO_FILE_ERRORS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x32:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::STALL_L0_SLOWDOWN_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x33:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::STALL_MEMTABLE_COMPACTION_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x34:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::STALL_L0_NUM_FILES_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x35:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::STALL_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x36:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::DB_MUTEX_WAIT_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x37:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::RATE_LIMIT_DELAY_MILLIS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x38:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NO_ITERATORS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x39:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_MULTIGET_CALLS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x3A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_MULTIGET_KEYS_READ;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x3B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_MULTIGET_BYTES_READ;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x3C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_FILTERED_DELETES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x3D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_MERGE_FAILURES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x3E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_PREFIX_CHECKED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x3F:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_PREFIX_USEFUL;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x40:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_OF_RESEEKS_IN_ITERATION;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x41:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::GET_UPDATES_SINCE_CALLS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x42:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_COMPRESSED_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x43:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_COMPRESSED_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x44:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_COMPRESSED_ADD;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x45:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_COMPRESSED_ADD_FAILURES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x46:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::WAL_FILE_SYNCED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x47:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::WAL_FILE_BYTES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x48:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::WRITE_DONE_BY_SELF;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x49:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::WRITE_DONE_BY_OTHER;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x4A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::WRITE_TIMEDOUT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x4B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::WRITE_WITH_WAL;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x4C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACT_READ_BYTES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x4D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACT_WRITE_BYTES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x4E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::FLUSH_WRITE_BYTES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x4F:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_DIRECT_LOAD_TABLE_PROPERTIES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x50:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_SUPERVERSION_ACQUIRES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x51:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_SUPERVERSION_RELEASES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x52:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_SUPERVERSION_CLEANUPS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x53:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_BLOCK_COMPRESSED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x54:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_BLOCK_DECOMPRESSED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x55:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_BLOCK_NOT_COMPRESSED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x56:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::MERGE_OPERATION_TOTAL_TIME;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x57:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::FILTER_OPERATION_TOTAL_TIME;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x58:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::ROW_CACHE_HIT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x59:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::ROW_CACHE_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x5A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::READ_AMP_ESTIMATE_USEFUL_BYTES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x5B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::READ_AMP_TOTAL_READ_BYTES;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x5C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_RATE_LIMITER_DRAINS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x5D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_ITER_SKIP;
|
2017-11-21 05:12:55 +00:00
|
|
|
case 0x5E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NUMBER_MULTIGET_KEYS_FOUND;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x01:
|
|
|
|
// -0x01 to fixate the new value that incorrectly changed TICKER_ENUM_MAX.
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NO_ITERATOR_CREATED;
|
2018-11-13 19:44:25 +00:00
|
|
|
case 0x60:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::NO_ITERATOR_DELETED;
|
2018-11-27 18:12:11 +00:00
|
|
|
case 0x61:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::
|
|
|
|
COMPACTION_OPTIMIZED_DEL_DROP_OBSOLETE;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x62:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACTION_CANCELLED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x63:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_FULL_POSITIVE;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x64:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOOM_FILTER_FULL_TRUE_POSITIVE;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x65:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_PUT;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x66:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_WRITE;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x67:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_GET;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x68:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_MULTIGET;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x69:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_SEEK;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x6A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_NEXT;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x6B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_PREV;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x6C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_KEYS_WRITTEN;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x6D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_NUM_KEYS_READ;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x6E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BYTES_WRITTEN;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x6F:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BYTES_READ;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x70:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_WRITE_INLINED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x71:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_WRITE_INLINED_TTL;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x72:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_WRITE_BLOB;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x73:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_WRITE_BLOB_TTL;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x74:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_FILE_BYTES_WRITTEN;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x75:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_FILE_BYTES_READ;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x76:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_FILE_SYNCED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x77:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_INDEX_EXPIRED_COUNT;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x78:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_INDEX_EXPIRED_SIZE;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x79:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_INDEX_EVICTED_COUNT;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x7A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_BLOB_INDEX_EVICTED_SIZE;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x7B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_FILES;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x7C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_NEW_FILES;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x7D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_FAILURES;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x7E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_KEYS_OVERWRITTEN;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x7F:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_KEYS_EXPIRED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x02:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_NUM_KEYS_RELOCATED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x03:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_BYTES_OVERWRITTEN;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x04:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_BYTES_EXPIRED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x05:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_GC_BYTES_RELOCATED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x06:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_FIFO_NUM_FILES_EVICTED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x07:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_FIFO_NUM_KEYS_EVICTED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x08:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOB_DB_FIFO_BYTES_EVICTED;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x09:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::TXN_PREPARE_MUTEX_OVERHEAD;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x0A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::TXN_OLD_COMMIT_MAP_MUTEX_OVERHEAD;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x0B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::TXN_DUPLICATE_KEY_OVERHEAD;
|
2018-12-14 19:34:29 +00:00
|
|
|
case -0x0C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::TXN_SNAPSHOT_MUTEX_OVERHEAD;
|
2019-08-05 20:30:56 +00:00
|
|
|
case -0x0D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::TXN_GET_TRY_AGAIN;
|
2020-06-05 16:41:03 +00:00
|
|
|
case -0x0E:
|
|
|
|
return ROCKSDB_NAMESPACE::Tickers::FILES_MARKED_TRASH;
|
|
|
|
case -0x0F:
|
|
|
|
return ROCKSDB_NAMESPACE::Tickers::FILES_DELETED_IMMEDIATELY;
|
2020-07-29 20:38:07 +00:00
|
|
|
case -0x10:
|
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACT_READ_BYTES_MARKED;
|
|
|
|
case -0x11:
|
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACT_READ_BYTES_PERIODIC;
|
|
|
|
case -0x12:
|
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACT_READ_BYTES_TTL;
|
|
|
|
case -0x13:
|
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACT_WRITE_BYTES_MARKED;
|
|
|
|
case -0x14:
|
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACT_WRITE_BYTES_PERIODIC;
|
|
|
|
case -0x15:
|
|
|
|
return ROCKSDB_NAMESPACE::Tickers::COMPACT_WRITE_BYTES_TTL;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x5F:
|
|
|
|
// 0x5F for backwards compatibility on current minor version.
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::TICKER_ENUM_MAX;
|
2017-07-12 06:19:53 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Tickers::BLOCK_CACHE_MISS;
|
2017-07-12 06:19:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.HistogramType
|
|
|
|
class HistogramTypeJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.HistogramType for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::Histograms enum
|
2017-07-12 06:19:53 +00:00
|
|
|
static jbyte toJavaHistogramsType(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::Histograms& histograms) {
|
2017-07-12 06:19:53 +00:00
|
|
|
switch(histograms) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::DB_GET:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::DB_WRITE:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::COMPACTION_TIME:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::SUBCOMPACTION_SETUP_TIME:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x3;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::TABLE_SYNC_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x4;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::COMPACTION_OUTFILE_SYNC_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x5;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::WAL_FILE_SYNC_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x6;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::MANIFEST_FILE_SYNC_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x7;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::TABLE_OPEN_IO_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x8;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::DB_MULTIGET:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x9;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::READ_BLOCK_COMPACTION_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xA;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::READ_BLOCK_GET_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xB;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::WRITE_RAW_BLOCK_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xC;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::STALL_L0_SLOWDOWN_COUNT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xD;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::STALL_MEMTABLE_COMPACTION_COUNT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xE;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::STALL_L0_NUM_FILES_COUNT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0xF;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::HARD_RATE_LIMIT_DELAY_COUNT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x10;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::SOFT_RATE_LIMIT_DELAY_COUNT:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x11;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::NUM_FILES_IN_SINGLE_COMPACTION:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x12;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::DB_SEEK:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x13;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::WRITE_STALL:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x14;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::SST_READ_MICROS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x15;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::NUM_SUBCOMPACTIONS_SCHEDULED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x16;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BYTES_PER_READ:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x17;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BYTES_PER_WRITE:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x18;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BYTES_PER_MULTIGET:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x19;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BYTES_COMPRESSED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BYTES_DECOMPRESSED:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::COMPRESSION_TIMES_NANOS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::DECOMPRESSION_TIMES_NANOS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::READ_NUM_MERGE_OPERANDS:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1E;
|
2018-12-14 19:34:29 +00:00
|
|
|
// 0x20 to skip 0x1F so TICKER_ENUM_MAX remains unchanged for minor version compatibility.
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::FLUSH_TIME:
|
2017-12-16 02:45:38 +00:00
|
|
|
return 0x20;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_KEY_SIZE:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x21;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_VALUE_SIZE:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x22;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_WRITE_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x23;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_GET_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x24;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_MULTIGET_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x25;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_SEEK_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x26;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_NEXT_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x27;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_PREV_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x28;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_BLOB_FILE_WRITE_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x29;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_BLOB_FILE_READ_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x2A;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_BLOB_FILE_SYNC_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x2B;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_GC_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x2C;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_COMPRESSION_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x2D;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::BLOB_DB_DECOMPRESSION_MICROS:
|
2018-12-14 19:34:29 +00:00
|
|
|
return 0x2E;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::Histograms::HISTOGRAM_ENUM_MAX:
|
2018-12-14 19:34:29 +00:00
|
|
|
// 0x1F for backwards compatibility on current minor version.
|
|
|
|
return 0x1F;
|
2017-07-12 06:19:53 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::Histograms enum for the
|
2017-07-12 06:19:53 +00:00
|
|
|
// provided Java org.rocksdb.HistogramsType
|
2020-02-20 20:07:53 +00:00
|
|
|
static ROCKSDB_NAMESPACE::Histograms toCppHistograms(jbyte jhistograms_type) {
|
2017-07-12 06:19:53 +00:00
|
|
|
switch(jhistograms_type) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::DB_GET;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::DB_WRITE;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::COMPACTION_TIME;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x3:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::SUBCOMPACTION_SETUP_TIME;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x4:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::TABLE_SYNC_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x5:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::COMPACTION_OUTFILE_SYNC_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x6:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::WAL_FILE_SYNC_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x7:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::MANIFEST_FILE_SYNC_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x8:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::TABLE_OPEN_IO_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x9:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::DB_MULTIGET;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xA:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::READ_BLOCK_COMPACTION_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xB:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::READ_BLOCK_GET_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xC:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::WRITE_RAW_BLOCK_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xD:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::STALL_L0_SLOWDOWN_COUNT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xE:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::STALL_MEMTABLE_COMPACTION_COUNT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0xF:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::STALL_L0_NUM_FILES_COUNT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x10:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::HARD_RATE_LIMIT_DELAY_COUNT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x11:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::SOFT_RATE_LIMIT_DELAY_COUNT;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x12:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::NUM_FILES_IN_SINGLE_COMPACTION;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x13:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::DB_SEEK;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x14:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::WRITE_STALL;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x15:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::SST_READ_MICROS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x16:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::NUM_SUBCOMPACTIONS_SCHEDULED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x17:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BYTES_PER_READ;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x18:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BYTES_PER_WRITE;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x19:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BYTES_PER_MULTIGET;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BYTES_COMPRESSED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BYTES_DECOMPRESSED;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::COMPRESSION_TIMES_NANOS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::DECOMPRESSION_TIMES_NANOS;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::READ_NUM_MERGE_OPERANDS;
|
2018-12-14 19:34:29 +00:00
|
|
|
// 0x20 to skip 0x1F so TICKER_ENUM_MAX remains unchanged for minor version compatibility.
|
2017-12-16 02:45:38 +00:00
|
|
|
case 0x20:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::FLUSH_TIME;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x21:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_KEY_SIZE;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x22:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_VALUE_SIZE;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x23:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_WRITE_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x24:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_GET_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x25:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_MULTIGET_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x26:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_SEEK_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x27:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_NEXT_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x28:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_PREV_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x29:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_BLOB_FILE_WRITE_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x2A:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_BLOB_FILE_READ_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x2B:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_BLOB_FILE_SYNC_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x2C:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_GC_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x2D:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_COMPRESSION_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x2E:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::BLOB_DB_DECOMPRESSION_MICROS;
|
2018-12-14 19:34:29 +00:00
|
|
|
case 0x1F:
|
|
|
|
// 0x1F for backwards compatibility on current minor version.
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::HISTOGRAM_ENUM_MAX;
|
2017-07-12 06:19:53 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::Histograms::DB_GET;
|
2017-07-12 06:19:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.StatsLevel
|
|
|
|
class StatsLevelJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.StatsLevel for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::StatsLevel enum
|
2017-07-12 06:19:53 +00:00
|
|
|
static jbyte toJavaStatsLevel(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::StatsLevel& stats_level) {
|
2017-07-12 06:19:53 +00:00
|
|
|
switch(stats_level) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::StatsLevel::kExceptDetailedTimers:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::StatsLevel::kExceptTimeForMutex:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::StatsLevel::kAll:
|
2017-07-12 06:19:53 +00:00
|
|
|
return 0x2;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return 0x0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::StatsLevel enum for the
|
2017-07-12 06:19:53 +00:00
|
|
|
// provided Java org.rocksdb.StatsLevel
|
2020-02-20 20:07:53 +00:00
|
|
|
static ROCKSDB_NAMESPACE::StatsLevel toCppStatsLevel(jbyte jstats_level) {
|
2017-07-12 06:19:53 +00:00
|
|
|
switch(jstats_level) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::StatsLevel::kExceptDetailedTimers;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::StatsLevel::kExceptTimeForMutex;
|
2017-07-12 06:19:53 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::StatsLevel::kAll;
|
2017-07-12 06:19:53 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::StatsLevel::kExceptDetailedTimers;
|
2017-07-12 06:19:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-01-08 20:20:48 +00:00
|
|
|
// The portal class for org.rocksdb.RateLimiterMode
|
|
|
|
class RateLimiterModeJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.RateLimiterMode for the provided
|
2020-02-20 20:07:53 +00:00
|
|
|
// C++ ROCKSDB_NAMESPACE::RateLimiter::Mode enum
|
2018-01-08 20:20:48 +00:00
|
|
|
static jbyte toJavaRateLimiterMode(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::RateLimiter::Mode& rate_limiter_mode) {
|
2018-01-08 20:20:48 +00:00
|
|
|
switch(rate_limiter_mode) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::RateLimiter::Mode::kReadsOnly:
|
2018-01-08 20:20:48 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::RateLimiter::Mode::kWritesOnly:
|
2018-01-08 20:20:48 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::RateLimiter::Mode::kAllIo:
|
2018-01-08 20:20:48 +00:00
|
|
|
return 0x2;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return 0x1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::RateLimiter::Mode enum for
|
|
|
|
// the provided Java org.rocksdb.RateLimiterMode
|
|
|
|
static ROCKSDB_NAMESPACE::RateLimiter::Mode toCppRateLimiterMode(
|
|
|
|
jbyte jrate_limiter_mode) {
|
2018-01-08 20:20:48 +00:00
|
|
|
switch(jrate_limiter_mode) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::RateLimiter::Mode::kReadsOnly;
|
2018-01-08 20:20:48 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::RateLimiter::Mode::kWritesOnly;
|
2018-01-08 20:20:48 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::RateLimiter::Mode::kAllIo;
|
2018-01-08 20:20:48 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::RateLimiter::Mode::kWritesOnly;
|
2018-01-08 20:20:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-10-08 18:03:34 +00:00
|
|
|
// The portal class for org.rocksdb.MemoryUsageType
|
|
|
|
class MemoryUsageTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.MemoryUsageType for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::MemoryUtil::UsageType enum
|
|
|
|
static jbyte toJavaMemoryUsageType(
|
|
|
|
const ROCKSDB_NAMESPACE::MemoryUtil::UsageType& usage_type) {
|
|
|
|
switch (usage_type) {
|
|
|
|
case ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kMemTableTotal:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kMemTableUnFlushed:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kTableReadersTotal:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kCacheTotal:
|
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
// undefined: use kNumUsageTypes
|
|
|
|
return 0x4;
|
|
|
|
}
|
|
|
|
}
|
2018-10-08 18:03:34 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::MemoryUtil::UsageType enum for
|
|
|
|
// the provided Java org.rocksdb.MemoryUsageType
|
|
|
|
static ROCKSDB_NAMESPACE::MemoryUtil::UsageType toCppMemoryUsageType(
|
|
|
|
jbyte usage_type) {
|
|
|
|
switch (usage_type) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kMemTableTotal;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kMemTableUnFlushed;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kTableReadersTotal;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kCacheTotal;
|
|
|
|
default:
|
|
|
|
// undefined/default: use kNumUsageTypes
|
|
|
|
return ROCKSDB_NAMESPACE::MemoryUtil::UsageType::kNumUsageTypes;
|
|
|
|
}
|
|
|
|
}
|
2018-10-08 18:03:34 +00:00
|
|
|
};
|
|
|
|
|
2018-03-02 18:22:38 +00:00
|
|
|
// The portal class for org.rocksdb.Transaction
|
|
|
|
class TransactionJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.Transaction
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env,
|
|
|
|
"org/rocksdb/Transaction");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.Transaction.WaitingTransactions object
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param jtransaction A Java org.rocksdb.Transaction object
|
|
|
|
* @param column_family_id The id of the column family
|
|
|
|
* @param key The key
|
|
|
|
* @param transaction_ids The transaction ids
|
|
|
|
*
|
|
|
|
* @return A reference to a Java
|
|
|
|
* org.rocksdb.Transaction.WaitingTransactions object,
|
|
|
|
* or nullptr if an an exception occurs
|
|
|
|
*/
|
|
|
|
static jobject newWaitingTransactions(JNIEnv* env, jobject jtransaction,
|
|
|
|
const uint32_t column_family_id, const std::string &key,
|
|
|
|
const std::vector<TransactionID> &transaction_ids) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "newWaitingTransactions", "(JLjava/lang/String;[J)Lorg/rocksdb/Transaction$WaitingTransactions;");
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jstring jkey = env->NewStringUTF(key.c_str());
|
|
|
|
if(jkey == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t len = transaction_ids.size();
|
|
|
|
jlongArray jtransaction_ids = env->NewLongArray(static_cast<jsize>(len));
|
|
|
|
if(jtransaction_ids == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jlong *body = env->GetLongArrayElements(jtransaction_ids, nullptr);
|
|
|
|
if(body == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
env->DeleteLocalRef(jtransaction_ids);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for(size_t i = 0; i < len; ++i) {
|
|
|
|
body[i] = static_cast<jlong>(transaction_ids[i]);
|
|
|
|
}
|
|
|
|
env->ReleaseLongArrayElements(jtransaction_ids, body, 0);
|
|
|
|
|
|
|
|
jobject jwaiting_transactions = env->CallObjectMethod(jtransaction,
|
|
|
|
mid, static_cast<jlong>(column_family_id), jkey, jtransaction_ids);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: InstantiationException or OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
env->DeleteLocalRef(jtransaction_ids);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jwaiting_transactions;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.TransactionDB
|
|
|
|
class TransactionDBJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.TransactionDB
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env,
|
|
|
|
"org/rocksdb/TransactionDB");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.TransactionDB.DeadlockInfo object
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param jtransaction A Java org.rocksdb.Transaction object
|
|
|
|
* @param column_family_id The id of the column family
|
|
|
|
* @param key The key
|
|
|
|
* @param transaction_ids The transaction ids
|
|
|
|
*
|
|
|
|
* @return A reference to a Java
|
|
|
|
* org.rocksdb.Transaction.WaitingTransactions object,
|
|
|
|
* or nullptr if an an exception occurs
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject newDeadlockInfo(
|
|
|
|
JNIEnv* env, jobject jtransaction_db,
|
|
|
|
const ROCKSDB_NAMESPACE::TransactionID transaction_id,
|
|
|
|
const uint32_t column_family_id, const std::string& waiting_key,
|
2018-03-02 18:22:38 +00:00
|
|
|
const bool exclusive) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "newDeadlockInfo", "(JJLjava/lang/String;Z)Lorg/rocksdb/TransactionDB$DeadlockInfo;");
|
|
|
|
if(mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jstring jwaiting_key = env->NewStringUTF(waiting_key.c_str());
|
|
|
|
if(jwaiting_key == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// resolve the column family id to a ColumnFamilyHandle
|
|
|
|
jobject jdeadlock_info = env->CallObjectMethod(jtransaction_db,
|
|
|
|
mid, transaction_id, static_cast<jlong>(column_family_id),
|
|
|
|
jwaiting_key, exclusive);
|
|
|
|
if(env->ExceptionCheck()) {
|
|
|
|
// exception thrown: InstantiationException or OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jwaiting_key);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jdeadlock_info;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.TxnDBWritePolicy
|
|
|
|
class TxnDBWritePolicyJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.TxnDBWritePolicy for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::TxnDBWritePolicy enum
|
|
|
|
static jbyte toJavaTxnDBWritePolicy(
|
|
|
|
const ROCKSDB_NAMESPACE::TxnDBWritePolicy& txndb_write_policy) {
|
|
|
|
switch (txndb_write_policy) {
|
|
|
|
case ROCKSDB_NAMESPACE::TxnDBWritePolicy::WRITE_COMMITTED:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::TxnDBWritePolicy::WRITE_PREPARED:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::TxnDBWritePolicy::WRITE_UNPREPARED:
|
|
|
|
return 0x2;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 18:22:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::TxnDBWritePolicy enum for the
|
|
|
|
// provided Java org.rocksdb.TxnDBWritePolicy
|
|
|
|
static ROCKSDB_NAMESPACE::TxnDBWritePolicy toCppTxnDBWritePolicy(
|
|
|
|
jbyte jtxndb_write_policy) {
|
|
|
|
switch (jtxndb_write_policy) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::TxnDBWritePolicy::WRITE_COMMITTED;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::TxnDBWritePolicy::WRITE_PREPARED;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::TxnDBWritePolicy::WRITE_UNPREPARED;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::TxnDBWritePolicy::WRITE_COMMITTED;
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 18:22:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.TransactionDB.KeyLockInfo
|
|
|
|
class KeyLockInfoJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.TransactionDB.KeyLockInfo
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env,
|
|
|
|
"org/rocksdb/TransactionDB$KeyLockInfo");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.TransactionDB.KeyLockInfo object
|
2020-02-20 20:07:53 +00:00
|
|
|
* with the same properties as the provided C++ ROCKSDB_NAMESPACE::KeyLockInfo
|
|
|
|
* object
|
2018-03-02 18:22:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2020-02-20 20:07:53 +00:00
|
|
|
* @param key_lock_info The ROCKSDB_NAMESPACE::KeyLockInfo object
|
2018-03-02 18:22:38 +00:00
|
|
|
*
|
|
|
|
* @return A reference to a Java
|
|
|
|
* org.rocksdb.TransactionDB.KeyLockInfo object,
|
|
|
|
* or nullptr if an an exception occurs
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject construct(
|
|
|
|
JNIEnv* env, const ROCKSDB_NAMESPACE::KeyLockInfo& key_lock_info) {
|
2018-03-02 18:22:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "<init>", "(Ljava/lang/String;[JZ)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jstring jkey = env->NewStringUTF(key_lock_info.key.c_str());
|
|
|
|
if (jkey == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jsize jtransaction_ids_len = static_cast<jsize>(key_lock_info.ids.size());
|
|
|
|
jlongArray jtransactions_ids = env->NewLongArray(jtransaction_ids_len);
|
|
|
|
if (jtransactions_ids == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jobject jkey_lock_info = env->NewObject(jclazz, mid,
|
|
|
|
jkey, jtransactions_ids, key_lock_info.exclusive);
|
|
|
|
if(jkey_lock_info == nullptr) {
|
|
|
|
// exception thrown: InstantiationException or OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jtransactions_ids);
|
|
|
|
env->DeleteLocalRef(jkey);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jkey_lock_info;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.TransactionDB.DeadlockInfo
|
|
|
|
class DeadlockInfoJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.TransactionDB.DeadlockInfo
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env,"org/rocksdb/TransactionDB$DeadlockInfo");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.TransactionDB.DeadlockPath
|
|
|
|
class DeadlockPathJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.TransactionDB.DeadlockPath
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env,
|
|
|
|
"org/rocksdb/TransactionDB$DeadlockPath");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.TransactionDB.DeadlockPath object
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return A reference to a Java
|
|
|
|
* org.rocksdb.TransactionDB.DeadlockPath object,
|
|
|
|
* or nullptr if an an exception occurs
|
|
|
|
*/
|
|
|
|
static jobject construct(JNIEnv* env,
|
|
|
|
const jobjectArray jdeadlock_infos, const bool limit_exceeded) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "<init>", "([LDeadlockInfo;Z)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jobject jdeadlock_path = env->NewObject(jclazz, mid,
|
|
|
|
jdeadlock_infos, limit_exceeded);
|
|
|
|
if(jdeadlock_path == nullptr) {
|
|
|
|
// exception thrown: InstantiationException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jdeadlock_path;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
class AbstractTableFilterJni
|
|
|
|
: public RocksDBNativeClass<
|
|
|
|
const ROCKSDB_NAMESPACE::TableFilterJniCallback*,
|
|
|
|
AbstractTableFilterJni> {
|
2014-08-21 20:55:51 +00:00
|
|
|
public:
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Method: TableFilter#filter(TableProperties)
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getFilterMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid =
|
|
|
|
env->GetMethodID(jclazz, "filter", "(Lorg/rocksdb/TableProperties;)Z");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
private:
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/TableFilter");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TablePropertiesJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.TableProperties object.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param table_properties A Cpp table properties object
|
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.TableProperties object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject fromCppTableProperties(
|
|
|
|
JNIEnv* env, const ROCKSDB_NAMESPACE::TableProperties& table_properties) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(JJJJJJJJJJJJJJJJJJJ[BLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Map;Ljava/util/Map;Ljava/util/Map;)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jbyteArray jcolumn_family_name = ROCKSDB_NAMESPACE::JniUtil::copyBytes(
|
|
|
|
env, table_properties.column_family_name);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (jcolumn_family_name == nullptr) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jfilter_policy_name = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &table_properties.filter_policy_name, true);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jcomparator_name = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &table_properties.comparator_name, true);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfilter_policy_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jmerge_operator_name = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &table_properties.merge_operator_name, true);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfilter_policy_name);
|
|
|
|
env->DeleteLocalRef(jcomparator_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jprefix_extractor_name = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &table_properties.prefix_extractor_name, true);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfilter_policy_name);
|
|
|
|
env->DeleteLocalRef(jcomparator_name);
|
|
|
|
env->DeleteLocalRef(jmerge_operator_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-04-17 06:29:32 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jproperty_collectors_names =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &table_properties.property_collectors_names, true);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfilter_policy_name);
|
|
|
|
env->DeleteLocalRef(jcomparator_name);
|
|
|
|
env->DeleteLocalRef(jmerge_operator_name);
|
|
|
|
env->DeleteLocalRef(jprefix_extractor_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jcompression_name = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
|
|
|
env, &table_properties.compression_name, true);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfilter_policy_name);
|
|
|
|
env->DeleteLocalRef(jcomparator_name);
|
|
|
|
env->DeleteLocalRef(jmerge_operator_name);
|
|
|
|
env->DeleteLocalRef(jprefix_extractor_name);
|
|
|
|
env->DeleteLocalRef(jproperty_collectors_names);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map<String, String>
|
2020-02-20 20:07:53 +00:00
|
|
|
jobject juser_collected_properties =
|
|
|
|
ROCKSDB_NAMESPACE::HashMapJni::fromCppMap(
|
|
|
|
env, &table_properties.user_collected_properties);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java map
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfilter_policy_name);
|
|
|
|
env->DeleteLocalRef(jcomparator_name);
|
|
|
|
env->DeleteLocalRef(jmerge_operator_name);
|
|
|
|
env->DeleteLocalRef(jprefix_extractor_name);
|
|
|
|
env->DeleteLocalRef(jproperty_collectors_names);
|
|
|
|
env->DeleteLocalRef(jcompression_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map<String, String>
|
2020-02-20 20:07:53 +00:00
|
|
|
jobject jreadable_properties = ROCKSDB_NAMESPACE::HashMapJni::fromCppMap(
|
|
|
|
env, &table_properties.readable_properties);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java map
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfilter_policy_name);
|
|
|
|
env->DeleteLocalRef(jcomparator_name);
|
|
|
|
env->DeleteLocalRef(jmerge_operator_name);
|
|
|
|
env->DeleteLocalRef(jprefix_extractor_name);
|
|
|
|
env->DeleteLocalRef(jproperty_collectors_names);
|
|
|
|
env->DeleteLocalRef(jcompression_name);
|
|
|
|
env->DeleteLocalRef(juser_collected_properties);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Map<String, Long>
|
2020-02-20 20:07:53 +00:00
|
|
|
jobject jproperties_offsets = ROCKSDB_NAMESPACE::HashMapJni::fromCppMap(
|
|
|
|
env, &table_properties.properties_offsets);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java map
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfilter_policy_name);
|
|
|
|
env->DeleteLocalRef(jcomparator_name);
|
|
|
|
env->DeleteLocalRef(jmerge_operator_name);
|
|
|
|
env->DeleteLocalRef(jprefix_extractor_name);
|
|
|
|
env->DeleteLocalRef(jproperty_collectors_names);
|
|
|
|
env->DeleteLocalRef(jcompression_name);
|
|
|
|
env->DeleteLocalRef(juser_collected_properties);
|
|
|
|
env->DeleteLocalRef(jreadable_properties);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jtable_properties = env->NewObject(jclazz, mid,
|
|
|
|
static_cast<jlong>(table_properties.data_size),
|
|
|
|
static_cast<jlong>(table_properties.index_size),
|
|
|
|
static_cast<jlong>(table_properties.index_partitions),
|
|
|
|
static_cast<jlong>(table_properties.top_level_index_size),
|
|
|
|
static_cast<jlong>(table_properties.index_key_is_user_key),
|
|
|
|
static_cast<jlong>(table_properties.index_value_is_delta_encoded),
|
|
|
|
static_cast<jlong>(table_properties.filter_size),
|
|
|
|
static_cast<jlong>(table_properties.raw_key_size),
|
|
|
|
static_cast<jlong>(table_properties.raw_value_size),
|
|
|
|
static_cast<jlong>(table_properties.num_data_blocks),
|
|
|
|
static_cast<jlong>(table_properties.num_entries),
|
|
|
|
static_cast<jlong>(table_properties.num_deletions),
|
|
|
|
static_cast<jlong>(table_properties.num_merge_operands),
|
|
|
|
static_cast<jlong>(table_properties.num_range_deletions),
|
|
|
|
static_cast<jlong>(table_properties.format_version),
|
|
|
|
static_cast<jlong>(table_properties.fixed_key_len),
|
|
|
|
static_cast<jlong>(table_properties.column_family_id),
|
|
|
|
static_cast<jlong>(table_properties.creation_time),
|
|
|
|
static_cast<jlong>(table_properties.oldest_key_time),
|
|
|
|
jcolumn_family_name,
|
|
|
|
jfilter_policy_name,
|
|
|
|
jcomparator_name,
|
|
|
|
jmerge_operator_name,
|
|
|
|
jprefix_extractor_name,
|
|
|
|
jproperty_collectors_names,
|
|
|
|
jcompression_name,
|
|
|
|
juser_collected_properties,
|
|
|
|
jreadable_properties,
|
|
|
|
jproperties_offsets
|
|
|
|
);
|
|
|
|
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jtable_properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/TableProperties");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class ColumnFamilyDescriptorJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.ColumnFamilyDescriptor
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/ColumnFamilyDescriptor");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.ColumnFamilyDescriptor object with the same
|
2020-02-20 20:07:53 +00:00
|
|
|
* properties as the provided C++ ROCKSDB_NAMESPACE::ColumnFamilyDescriptor
|
|
|
|
* object
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2020-02-20 20:07:53 +00:00
|
|
|
* @param cfd A pointer to ROCKSDB_NAMESPACE::ColumnFamilyDescriptor object
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.ColumnFamilyDescriptor object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
|
|
|
static jobject construct(JNIEnv* env, ColumnFamilyDescriptor* cfd) {
|
|
|
|
jbyteArray jcf_name = JniUtil::copyBytes(env, cfd->name);
|
|
|
|
jobject cfopts = ColumnFamilyOptionsJni::construct(env, &(cfd->options));
|
|
|
|
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>",
|
|
|
|
"([BLorg/rocksdb/ColumnFamilyOptions;)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jcf_name);
|
|
|
|
return nullptr;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jobject jcfd = env->NewObject(jclazz, mid, jcf_name, cfopts);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
env->DeleteLocalRef(jcf_name);
|
|
|
|
return nullptr;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jcfd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: ColumnFamilyDescriptor#columnFamilyName
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getColumnFamilyNameMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(jclazz, "columnFamilyName", "()[B");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Get the Java Method: ColumnFamilyDescriptor#columnFamilyOptions
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
|
|
|
static jmethodID getColumnFamilyOptionsMethod(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "columnFamilyOptions", "()Lorg/rocksdb/ColumnFamilyOptions;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.IndexType
|
|
|
|
class IndexTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.IndexType for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::IndexType enum
|
|
|
|
static jbyte toJavaIndexType(
|
|
|
|
const ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType& index_type) {
|
|
|
|
switch (index_type) {
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::kBinarySearch:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::kHashSearch:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::
|
|
|
|
kTwoLevelIndexSearch:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::
|
|
|
|
kBinarySearchWithFirstKey:
|
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::IndexType enum for the
|
|
|
|
// provided Java org.rocksdb.IndexType
|
|
|
|
static ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType toCppIndexType(
|
|
|
|
jbyte jindex_type) {
|
|
|
|
switch (jindex_type) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::
|
|
|
|
kBinarySearch;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::
|
|
|
|
kHashSearch;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::
|
|
|
|
kTwoLevelIndexSearch;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::
|
|
|
|
kBinarySearchWithFirstKey;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexType::
|
|
|
|
kBinarySearch;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.DataBlockIndexType
|
|
|
|
class DataBlockIndexTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.DataBlockIndexType for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::DataBlockIndexType enum
|
|
|
|
static jbyte toJavaDataBlockIndexType(
|
|
|
|
const ROCKSDB_NAMESPACE::BlockBasedTableOptions::DataBlockIndexType&
|
|
|
|
index_type) {
|
|
|
|
switch (index_type) {
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::DataBlockIndexType::
|
|
|
|
kDataBlockBinarySearch:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::DataBlockIndexType::
|
|
|
|
kDataBlockBinaryAndHash:
|
|
|
|
return 0x1;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-10-12 18:06:51 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::DataBlockIndexType enum for
|
|
|
|
// the provided Java org.rocksdb.DataBlockIndexType
|
|
|
|
static ROCKSDB_NAMESPACE::BlockBasedTableOptions::DataBlockIndexType
|
|
|
|
toCppDataBlockIndexType(jbyte jindex_type) {
|
|
|
|
switch (jindex_type) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::DataBlockIndexType::
|
|
|
|
kDataBlockBinarySearch;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::DataBlockIndexType::
|
|
|
|
kDataBlockBinaryAndHash;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::DataBlockIndexType::
|
|
|
|
kDataBlockBinarySearch;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-10-12 18:06:51 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.ChecksumType
|
|
|
|
class ChecksumTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.ChecksumType for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::ChecksumType enum
|
|
|
|
static jbyte toJavaChecksumType(
|
|
|
|
const ROCKSDB_NAMESPACE::ChecksumType& checksum_type) {
|
|
|
|
switch (checksum_type) {
|
|
|
|
case ROCKSDB_NAMESPACE::ChecksumType::kNoChecksum:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::ChecksumType::kCRC32c:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::ChecksumType::kxxHash:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::ChecksumType::kxxHash64:
|
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::ChecksumType enum for the
|
|
|
|
// provided Java org.rocksdb.ChecksumType
|
|
|
|
static ROCKSDB_NAMESPACE::ChecksumType toCppChecksumType(
|
|
|
|
jbyte jchecksum_type) {
|
|
|
|
switch (jchecksum_type) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::ChecksumType::kNoChecksum;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::ChecksumType::kCRC32c;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::ChecksumType::kxxHash;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::ChecksumType::kxxHash64;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::ChecksumType::kCRC32c;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2015-01-03 17:52:17 +00:00
|
|
|
|
2020-07-10 21:31:25 +00:00
|
|
|
// The portal class for org.rocksdb.IndexShorteningMode
|
|
|
|
class IndexShorteningModeJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.IndexShorteningMode for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::IndexShorteningMode enum
|
|
|
|
static jbyte toJavaIndexShorteningMode(
|
|
|
|
const ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode&
|
|
|
|
index_shortening_mode) {
|
|
|
|
switch (index_shortening_mode) {
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode::
|
|
|
|
kNoShortening:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode::
|
|
|
|
kShortenSeparators:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode::
|
|
|
|
kShortenSeparatorsAndSuccessor:
|
|
|
|
return 0x2;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::IndexShorteningMode enum for
|
|
|
|
// the provided Java org.rocksdb.IndexShorteningMode
|
|
|
|
static ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode
|
|
|
|
toCppIndexShorteningMode(jbyte jindex_shortening_mode) {
|
|
|
|
switch (jindex_shortening_mode) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode::
|
|
|
|
kNoShortening;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode::
|
|
|
|
kShortenSeparators;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode::
|
|
|
|
kShortenSeparatorsAndSuccessor;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::BlockBasedTableOptions::IndexShorteningMode::
|
|
|
|
kShortenSeparators;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.Priority
|
|
|
|
class PriorityJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.Priority for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::Env::Priority enum
|
|
|
|
static jbyte toJavaPriority(
|
|
|
|
const ROCKSDB_NAMESPACE::Env::Priority& priority) {
|
|
|
|
switch (priority) {
|
|
|
|
case ROCKSDB_NAMESPACE::Env::Priority::BOTTOM:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::Env::Priority::LOW:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::Env::Priority::HIGH:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::Env::Priority::TOTAL:
|
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::env::Priority enum for the
|
|
|
|
// provided Java org.rocksdb.Priority
|
|
|
|
static ROCKSDB_NAMESPACE::Env::Priority toCppPriority(jbyte jpriority) {
|
|
|
|
switch (jpriority) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::Env::Priority::BOTTOM;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::Env::Priority::LOW;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::Env::Priority::HIGH;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::Env::Priority::TOTAL;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::Env::Priority::LOW;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.ThreadType
|
|
|
|
class ThreadTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.ThreadType for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::ThreadStatus::ThreadType enum
|
|
|
|
static jbyte toJavaThreadType(
|
|
|
|
const ROCKSDB_NAMESPACE::ThreadStatus::ThreadType& thread_type) {
|
|
|
|
switch (thread_type) {
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::ThreadType::HIGH_PRIORITY:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::ThreadType::LOW_PRIORITY:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::ThreadType::USER:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::ThreadType::BOTTOM_PRIORITY:
|
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::ThreadStatus::ThreadType enum
|
|
|
|
// for the provided Java org.rocksdb.ThreadType
|
|
|
|
static ROCKSDB_NAMESPACE::ThreadStatus::ThreadType toCppThreadType(
|
|
|
|
jbyte jthread_type) {
|
|
|
|
switch (jthread_type) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::ThreadType::HIGH_PRIORITY;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::ThreadType::LOW_PRIORITY;
|
|
|
|
case 0x2:
|
|
|
|
return ThreadStatus::ThreadType::USER;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::ThreadType::BOTTOM_PRIORITY;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::ThreadType::LOW_PRIORITY;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.OperationType
|
|
|
|
class OperationTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.OperationType for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::ThreadStatus::OperationType enum
|
|
|
|
static jbyte toJavaOperationType(
|
|
|
|
const ROCKSDB_NAMESPACE::ThreadStatus::OperationType& operation_type) {
|
|
|
|
switch (operation_type) {
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationType::OP_UNKNOWN:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationType::OP_COMPACTION:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationType::OP_FLUSH:
|
|
|
|
return 0x2;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::ThreadStatus::OperationType
|
|
|
|
// enum for the provided Java org.rocksdb.OperationType
|
|
|
|
static ROCKSDB_NAMESPACE::ThreadStatus::OperationType toCppOperationType(
|
|
|
|
jbyte joperation_type) {
|
|
|
|
switch (joperation_type) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationType::OP_UNKNOWN;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationType::OP_COMPACTION;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationType::OP_FLUSH;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationType::OP_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.OperationStage
|
|
|
|
class OperationStageJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.OperationStage for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::ThreadStatus::OperationStage enum
|
|
|
|
static jbyte toJavaOperationStage(
|
|
|
|
const ROCKSDB_NAMESPACE::ThreadStatus::OperationStage& operation_stage) {
|
|
|
|
switch (operation_stage) {
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::STAGE_UNKNOWN:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::STAGE_FLUSH_RUN:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_FLUSH_WRITE_L0:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_PREPARE:
|
|
|
|
return 0x3;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_RUN:
|
|
|
|
return 0x4;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_PROCESS_KV:
|
|
|
|
return 0x5;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_INSTALL:
|
|
|
|
return 0x6;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_SYNC_FILE:
|
|
|
|
return 0x7;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_PICK_MEMTABLES_TO_FLUSH:
|
|
|
|
return 0x8;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_MEMTABLE_ROLLBACK:
|
|
|
|
return 0x9;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS:
|
|
|
|
return 0xA;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::ThreadStatus::OperationStage
|
|
|
|
// enum for the provided Java org.rocksdb.OperationStage
|
|
|
|
static ROCKSDB_NAMESPACE::ThreadStatus::OperationStage toCppOperationStage(
|
|
|
|
jbyte joperation_stage) {
|
|
|
|
switch (joperation_stage) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::STAGE_UNKNOWN;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::STAGE_FLUSH_RUN;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_FLUSH_WRITE_L0;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_PREPARE;
|
|
|
|
case 0x4:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_RUN;
|
|
|
|
case 0x5:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_PROCESS_KV;
|
|
|
|
case 0x6:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_INSTALL;
|
|
|
|
case 0x7:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_COMPACTION_SYNC_FILE;
|
|
|
|
case 0x8:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_PICK_MEMTABLES_TO_FLUSH;
|
|
|
|
case 0x9:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_MEMTABLE_ROLLBACK;
|
|
|
|
case 0xA:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::
|
|
|
|
STAGE_MEMTABLE_INSTALL_FLUSH_RESULTS;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::OperationStage::STAGE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.StateType
|
|
|
|
class StateTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.StateType for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::ThreadStatus::StateType enum
|
|
|
|
static jbyte toJavaStateType(
|
|
|
|
const ROCKSDB_NAMESPACE::ThreadStatus::StateType& state_type) {
|
|
|
|
switch (state_type) {
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::StateType::STATE_UNKNOWN:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::ThreadStatus::StateType::STATE_MUTEX_WAIT:
|
|
|
|
return 0x1;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::ThreadStatus::StateType enum
|
|
|
|
// for the provided Java org.rocksdb.StateType
|
|
|
|
static ROCKSDB_NAMESPACE::ThreadStatus::StateType toCppStateType(
|
|
|
|
jbyte jstate_type) {
|
|
|
|
switch (jstate_type) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::StateType::STATE_UNKNOWN;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::StateType::STATE_MUTEX_WAIT;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::ThreadStatus::StateType::STATE_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.ThreadStatus
|
|
|
|
class ThreadStatusJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Get the Java Class org.rocksdb.ThreadStatus
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env,
|
|
|
|
"org/rocksdb/ThreadStatus");
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.ThreadStatus object with the same
|
2020-02-20 20:07:53 +00:00
|
|
|
* properties as the provided C++ ROCKSDB_NAMESPACE::ThreadStatus object
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2020-02-20 20:07:53 +00:00
|
|
|
* @param thread_status A pointer to ROCKSDB_NAMESPACE::ThreadStatus object
|
2019-02-22 22:36:38 +00:00
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.ColumnFamilyOptions object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject construct(
|
|
|
|
JNIEnv* env, const ROCKSDB_NAMESPACE::ThreadStatus* thread_status) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(JBLjava/lang/String;Ljava/lang/String;BJB[JB)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jstring jdb_name =
|
|
|
|
JniUtil::toJavaString(env, &(thread_status->db_name), true);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
2017-02-28 00:26:12 +00:00
|
|
|
return nullptr;
|
2019-02-22 22:36:38 +00:00
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jstring jcf_name =
|
|
|
|
JniUtil::toJavaString(env, &(thread_status->cf_name), true);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// an error occurred
|
|
|
|
env->DeleteLocalRef(jdb_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// long[]
|
2020-02-20 20:07:53 +00:00
|
|
|
const jsize len = static_cast<jsize>(
|
|
|
|
ROCKSDB_NAMESPACE::ThreadStatus::kNumOperationProperties);
|
2019-02-22 22:36:38 +00:00
|
|
|
jlongArray joperation_properties =
|
|
|
|
env->NewLongArray(len);
|
|
|
|
if (joperation_properties == nullptr) {
|
|
|
|
// an exception occurred
|
|
|
|
env->DeleteLocalRef(jdb_name);
|
|
|
|
env->DeleteLocalRef(jcf_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
jlong *body = env->GetLongArrayElements(joperation_properties, nullptr);
|
|
|
|
if (body == nullptr) {
|
2017-02-28 00:26:12 +00:00
|
|
|
// exception thrown: OutOfMemoryError
|
2019-02-22 22:36:38 +00:00
|
|
|
env->DeleteLocalRef(jdb_name);
|
|
|
|
env->DeleteLocalRef(jcf_name);
|
|
|
|
env->DeleteLocalRef(joperation_properties);
|
2017-02-28 00:26:12 +00:00
|
|
|
return nullptr;
|
2019-02-22 22:36:38 +00:00
|
|
|
}
|
|
|
|
for (size_t i = 0; i < len; ++i) {
|
|
|
|
body[i] = static_cast<jlong>(thread_status->op_properties[i]);
|
|
|
|
}
|
|
|
|
env->ReleaseLongArrayElements(joperation_properties, body, 0);
|
|
|
|
|
|
|
|
jobject jcfd = env->NewObject(jclazz, mid,
|
|
|
|
static_cast<jlong>(thread_status->thread_id),
|
|
|
|
ThreadTypeJni::toJavaThreadType(thread_status->thread_type),
|
|
|
|
jdb_name,
|
|
|
|
jcf_name,
|
|
|
|
OperationTypeJni::toJavaOperationType(thread_status->operation_type),
|
|
|
|
static_cast<jlong>(thread_status->op_elapsed_micros),
|
|
|
|
OperationStageJni::toJavaOperationStage(thread_status->operation_stage),
|
|
|
|
joperation_properties,
|
|
|
|
StateTypeJni::toJavaStateType(thread_status->state_type));
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred
|
|
|
|
env->DeleteLocalRef(jdb_name);
|
|
|
|
env->DeleteLocalRef(jcf_name);
|
|
|
|
env->DeleteLocalRef(joperation_properties);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// cleanup
|
|
|
|
env->DeleteLocalRef(jdb_name);
|
|
|
|
env->DeleteLocalRef(jcf_name);
|
|
|
|
env->DeleteLocalRef(joperation_properties);
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jcfd;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.CompactionStyle
|
|
|
|
class CompactionStyleJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.CompactionStyle for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::CompactionStyle enum
|
|
|
|
static jbyte toJavaCompactionStyle(
|
|
|
|
const ROCKSDB_NAMESPACE::CompactionStyle& compaction_style) {
|
|
|
|
switch (compaction_style) {
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleLevel:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleUniversal:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleFIFO:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleNone:
|
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::CompactionStyle enum for the
|
|
|
|
// provided Java org.rocksdb.CompactionStyle
|
|
|
|
static ROCKSDB_NAMESPACE::CompactionStyle toCppCompactionStyle(
|
|
|
|
jbyte jcompaction_style) {
|
|
|
|
switch (jcompaction_style) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleLevel;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleUniversal;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleFIFO;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleNone;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionStyle::kCompactionStyleLevel;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// The portal class for org.rocksdb.CompactionReason
|
|
|
|
class CompactionReasonJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.CompactionReason for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::CompactionReason enum
|
|
|
|
static jbyte toJavaCompactionReason(
|
|
|
|
const ROCKSDB_NAMESPACE::CompactionReason& compaction_reason) {
|
|
|
|
switch (compaction_reason) {
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kUnknown:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kLevelL0FilesNum:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kLevelMaxLevelSize:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kUniversalSizeAmplification:
|
|
|
|
return 0x3;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kUniversalSizeRatio:
|
|
|
|
return 0x4;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kUniversalSortedRunNum:
|
|
|
|
return 0x5;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kFIFOMaxSize:
|
|
|
|
return 0x6;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kFIFOReduceNumFiles:
|
|
|
|
return 0x7;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kFIFOTtl:
|
|
|
|
return 0x8;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kManualCompaction:
|
|
|
|
return 0x9;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kFilesMarkedForCompaction:
|
|
|
|
return 0x10;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kBottommostFiles:
|
|
|
|
return 0x0A;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kTtl:
|
|
|
|
return 0x0B;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kFlush:
|
|
|
|
return 0x0C;
|
|
|
|
case ROCKSDB_NAMESPACE::CompactionReason::kExternalSstIngestion:
|
|
|
|
return 0x0D;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::CompactionReason enum for the
|
|
|
|
// provided Java org.rocksdb.CompactionReason
|
|
|
|
static ROCKSDB_NAMESPACE::CompactionReason toCppCompactionReason(
|
|
|
|
jbyte jcompaction_reason) {
|
|
|
|
switch (jcompaction_reason) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kUnknown;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kLevelL0FilesNum;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kLevelMaxLevelSize;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kUniversalSizeAmplification;
|
|
|
|
case 0x4:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kUniversalSizeRatio;
|
|
|
|
case 0x5:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kUniversalSortedRunNum;
|
|
|
|
case 0x6:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kFIFOMaxSize;
|
|
|
|
case 0x7:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kFIFOReduceNumFiles;
|
|
|
|
case 0x8:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kFIFOTtl;
|
|
|
|
case 0x9:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kManualCompaction;
|
|
|
|
case 0x10:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kFilesMarkedForCompaction;
|
|
|
|
case 0x0A:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kBottommostFiles;
|
|
|
|
case 0x0B:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kTtl;
|
|
|
|
case 0x0C:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kFlush;
|
|
|
|
case 0x0D:
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kExternalSstIngestion;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::CompactionReason::kUnknown;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.WalFileType
|
|
|
|
class WalFileTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.WalFileType for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::WalFileType enum
|
|
|
|
static jbyte toJavaWalFileType(
|
|
|
|
const ROCKSDB_NAMESPACE::WalFileType& wal_file_type) {
|
|
|
|
switch (wal_file_type) {
|
|
|
|
case ROCKSDB_NAMESPACE::WalFileType::kArchivedLogFile:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::WalFileType::kAliveLogFile:
|
|
|
|
return 0x1;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::WalFileType enum for the
|
|
|
|
// provided Java org.rocksdb.WalFileType
|
|
|
|
static ROCKSDB_NAMESPACE::WalFileType toCppWalFileType(jbyte jwal_file_type) {
|
|
|
|
switch (jwal_file_type) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::WalFileType::kArchivedLogFile;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::WalFileType::kAliveLogFile;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::WalFileType::kAliveLogFile;
|
|
|
|
}
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
class LogFileJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.LogFile object.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param log_file A Cpp log file object
|
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.LogFile object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject fromCppLogFile(JNIEnv* env,
|
|
|
|
ROCKSDB_NAMESPACE::LogFile* log_file) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
2017-02-28 00:26:12 +00:00
|
|
|
}
|
2019-02-20 23:46:59 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(Ljava/lang/String;JBJJ)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-20 23:46:59 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
std::string path_name = log_file->PathName();
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jpath_name =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::toJavaString(env, &path_name, true);
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-20 23:46:59 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jobject jlog_file = env->NewObject(
|
|
|
|
jclazz, mid, jpath_name, static_cast<jlong>(log_file->LogNumber()),
|
|
|
|
ROCKSDB_NAMESPACE::WalFileTypeJni::toJavaWalFileType(log_file->Type()),
|
2019-02-22 22:36:38 +00:00
|
|
|
static_cast<jlong>(log_file->StartSequence()),
|
2020-02-20 20:07:53 +00:00
|
|
|
static_cast<jlong>(log_file->SizeFileBytes()));
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
env->DeleteLocalRef(jpath_name);
|
|
|
|
return nullptr;
|
2018-03-02 23:33:08 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// cleanup
|
|
|
|
env->DeleteLocalRef(jpath_name);
|
2018-06-29 23:03:28 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jlog_file;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/LogFile");
|
|
|
|
}
|
|
|
|
};
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
class LiveFileMetaDataJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.LiveFileMetaData object.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param live_file_meta_data A Cpp live file meta data object
|
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.LiveFileMetaData object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject fromCppLiveFileMetaData(
|
|
|
|
JNIEnv* env, ROCKSDB_NAMESPACE::LiveFileMetaData* live_file_meta_data) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-01-03 17:52:17 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "([BILjava/lang/String;Ljava/lang/String;JJJ[B[BJZJJ)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-01-03 17:52:17 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jbyteArray jcolumn_family_name = ROCKSDB_NAMESPACE::JniUtil::copyBytes(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, live_file_meta_data->column_family_name);
|
|
|
|
if (jcolumn_family_name == nullptr) {
|
|
|
|
// exception occurred creating java byte array
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jfile_name = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, &live_file_meta_data->name, true);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
return nullptr;
|
2015-01-03 17:52:17 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jpath = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, &live_file_meta_data->db_path, true);
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
// exception occurred creating java string
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jbyteArray jsmallest_key = ROCKSDB_NAMESPACE::JniUtil::copyBytes(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, live_file_meta_data->smallestkey);
|
|
|
|
if (jsmallest_key == nullptr) {
|
|
|
|
// exception occurred creating java byte array
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
env->DeleteLocalRef(jpath);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-01-03 17:52:17 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jbyteArray jlargest_key = ROCKSDB_NAMESPACE::JniUtil::copyBytes(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, live_file_meta_data->largestkey);
|
|
|
|
if (jlargest_key == nullptr) {
|
|
|
|
// exception occurred creating java byte array
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
env->DeleteLocalRef(jpath);
|
|
|
|
env->DeleteLocalRef(jsmallest_key);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2015-01-03 17:52:17 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jobject jlive_file_meta_data = env->NewObject(jclazz, mid,
|
|
|
|
jcolumn_family_name,
|
|
|
|
static_cast<jint>(live_file_meta_data->level),
|
|
|
|
jfile_name,
|
|
|
|
jpath,
|
|
|
|
static_cast<jlong>(live_file_meta_data->size),
|
|
|
|
static_cast<jlong>(live_file_meta_data->smallest_seqno),
|
|
|
|
static_cast<jlong>(live_file_meta_data->largest_seqno),
|
|
|
|
jsmallest_key,
|
|
|
|
jlargest_key,
|
|
|
|
static_cast<jlong>(live_file_meta_data->num_reads_sampled),
|
|
|
|
static_cast<jboolean>(live_file_meta_data->being_compacted),
|
|
|
|
static_cast<jlong>(live_file_meta_data->num_entries),
|
|
|
|
static_cast<jlong>(live_file_meta_data->num_deletions)
|
|
|
|
);
|
2018-03-02 23:33:08 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
env->DeleteLocalRef(jpath);
|
|
|
|
env->DeleteLocalRef(jsmallest_key);
|
|
|
|
env->DeleteLocalRef(jlargest_key);
|
|
|
|
return nullptr;
|
2015-01-03 17:52:17 +00:00
|
|
|
}
|
2016-11-06 09:25:39 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// cleanup
|
|
|
|
env->DeleteLocalRef(jcolumn_family_name);
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
env->DeleteLocalRef(jpath);
|
|
|
|
env->DeleteLocalRef(jsmallest_key);
|
|
|
|
env->DeleteLocalRef(jlargest_key);
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
return jlive_file_meta_data;
|
|
|
|
}
|
2016-11-06 09:25:39 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/LiveFileMetaData");
|
|
|
|
}
|
|
|
|
};
|
2016-11-06 09:25:39 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
class SstFileMetaDataJni : public JavaClass {
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create a new Java org.rocksdb.SstFileMetaData object.
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
* @param sst_file_meta_data A Cpp sst file meta data object
|
|
|
|
*
|
|
|
|
* @return A reference to a Java org.rocksdb.SstFileMetaData object, or
|
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject fromCppSstFileMetaData(
|
|
|
|
JNIEnv* env,
|
|
|
|
const ROCKSDB_NAMESPACE::SstFileMetaData* sst_file_meta_data) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-11-06 09:25:39 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(Ljava/lang/String;Ljava/lang/String;JJJ[B[BJZJJ)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-11-06 09:25:39 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jfile_name = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, &sst_file_meta_data->name, true);
|
|
|
|
if (jfile_name == nullptr) {
|
|
|
|
// exception occurred creating java byte array
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jstring jpath = ROCKSDB_NAMESPACE::JniUtil::toJavaString(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, &sst_file_meta_data->db_path, true);
|
|
|
|
if (jpath == nullptr) {
|
|
|
|
// exception occurred creating java byte array
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-02-28 00:26:12 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jbyteArray jsmallest_key = ROCKSDB_NAMESPACE::JniUtil::copyBytes(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, sst_file_meta_data->smallestkey);
|
|
|
|
if (jsmallest_key == nullptr) {
|
|
|
|
// exception occurred creating java byte array
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
env->DeleteLocalRef(jpath);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-11-06 09:25:39 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jbyteArray jlargest_key = ROCKSDB_NAMESPACE::JniUtil::copyBytes(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, sst_file_meta_data->largestkey);
|
|
|
|
if (jlargest_key == nullptr) {
|
|
|
|
// exception occurred creating java byte array
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
env->DeleteLocalRef(jpath);
|
|
|
|
env->DeleteLocalRef(jsmallest_key);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jsst_file_meta_data = env->NewObject(jclazz, mid,
|
|
|
|
jfile_name,
|
|
|
|
jpath,
|
|
|
|
static_cast<jlong>(sst_file_meta_data->size),
|
|
|
|
static_cast<jint>(sst_file_meta_data->smallest_seqno),
|
|
|
|
static_cast<jlong>(sst_file_meta_data->largest_seqno),
|
|
|
|
jsmallest_key,
|
|
|
|
jlargest_key,
|
|
|
|
static_cast<jlong>(sst_file_meta_data->num_reads_sampled),
|
|
|
|
static_cast<jboolean>(sst_file_meta_data->being_compacted),
|
|
|
|
static_cast<jlong>(sst_file_meta_data->num_entries),
|
|
|
|
static_cast<jlong>(sst_file_meta_data->num_deletions)
|
|
|
|
);
|
|
|
|
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
env->DeleteLocalRef(jpath);
|
|
|
|
env->DeleteLocalRef(jsmallest_key);
|
|
|
|
env->DeleteLocalRef(jlargest_key);
|
2016-11-06 09:25:39 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
|
|
|
|
// cleanup
|
|
|
|
env->DeleteLocalRef(jfile_name);
|
|
|
|
env->DeleteLocalRef(jpath);
|
|
|
|
env->DeleteLocalRef(jsmallest_key);
|
|
|
|
env->DeleteLocalRef(jlargest_key);
|
|
|
|
|
|
|
|
return jsst_file_meta_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/SstFileMetaData");
|
|
|
|
}
|
2014-08-03 20:11:44 +00:00
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
class LevelMetaDataJni : public JavaClass {
|
2017-09-22 00:15:27 +00:00
|
|
|
public:
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Create a new Java org.rocksdb.LevelMetaData object.
|
2017-09-22 00:15:27 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2019-02-22 22:36:38 +00:00
|
|
|
* @param level_meta_data A Cpp level meta data object
|
2017-09-22 00:15:27 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return A reference to a Java org.rocksdb.LevelMetaData object, or
|
|
|
|
* nullptr if an an exception occurs
|
2017-09-22 00:15:27 +00:00
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject fromCppLevelMetaData(
|
|
|
|
JNIEnv* env, const ROCKSDB_NAMESPACE::LevelMetaData* level_meta_data) {
|
2019-02-22 22:36:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(IJ[Lorg/rocksdb/SstFileMetaData;)V");
|
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jsize jlen =
|
|
|
|
static_cast<jsize>(level_meta_data->files.size());
|
|
|
|
jobjectArray jfiles = env->NewObjectArray(jlen, SstFileMetaDataJni::getJClass(env), nullptr);
|
|
|
|
if (jfiles == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsize i = 0;
|
|
|
|
for (auto it = level_meta_data->files.begin();
|
|
|
|
it != level_meta_data->files.end(); ++it) {
|
|
|
|
jobject jfile = SstFileMetaDataJni::fromCppSstFileMetaData(env, &(*it));
|
|
|
|
if (jfile == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
env->DeleteLocalRef(jfiles);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
env->SetObjectArrayElement(jfiles, i++, jfile);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jlevel_meta_data = env->NewObject(jclazz, mid,
|
|
|
|
static_cast<jint>(level_meta_data->level),
|
|
|
|
static_cast<jlong>(level_meta_data->size),
|
|
|
|
jfiles
|
|
|
|
);
|
|
|
|
|
|
|
|
if (env->ExceptionCheck()) {
|
|
|
|
env->DeleteLocalRef(jfiles);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cleanup
|
|
|
|
env->DeleteLocalRef(jfiles);
|
|
|
|
|
|
|
|
return jlevel_meta_data;
|
|
|
|
}
|
|
|
|
|
2017-09-22 00:15:27 +00:00
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/LevelMetaData");
|
2017-09-22 00:15:27 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-09-22 00:15:27 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
class ColumnFamilyMetaDataJni : public JavaClass {
|
|
|
|
public:
|
2017-09-22 00:15:27 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Create a new Java org.rocksdb.ColumnFamilyMetaData object.
|
2017-09-22 00:15:27 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
2019-02-22 22:36:38 +00:00
|
|
|
* @param column_famly_meta_data A Cpp live file meta data object
|
2017-09-22 00:15:27 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return A reference to a Java org.rocksdb.ColumnFamilyMetaData object, or
|
2017-09-22 00:15:27 +00:00
|
|
|
* nullptr if an an exception occurs
|
|
|
|
*/
|
2020-02-20 20:07:53 +00:00
|
|
|
static jobject fromCppColumnFamilyMetaData(
|
|
|
|
JNIEnv* env,
|
|
|
|
const ROCKSDB_NAMESPACE::ColumnFamilyMetaData* column_famly_meta_data) {
|
2017-09-22 00:15:27 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if (jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
jmethodID mid = env->GetMethodID(jclazz, "<init>", "(JJ[B[Lorg/rocksdb/LevelMetaData;)V");
|
2017-09-22 00:15:27 +00:00
|
|
|
if (mid == nullptr) {
|
|
|
|
// exception thrown: NoSuchMethodException or OutOfMemoryError
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
jbyteArray jname = ROCKSDB_NAMESPACE::JniUtil::copyBytes(
|
2019-02-22 22:36:38 +00:00
|
|
|
env, column_famly_meta_data->name);
|
|
|
|
if (jname == nullptr) {
|
|
|
|
// exception occurred creating java byte array
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const jsize jlen =
|
|
|
|
static_cast<jsize>(column_famly_meta_data->levels.size());
|
|
|
|
jobjectArray jlevels = env->NewObjectArray(jlen, LevelMetaDataJni::getJClass(env), nullptr);
|
|
|
|
if(jlevels == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
env->DeleteLocalRef(jname);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsize i = 0;
|
|
|
|
for (auto it = column_famly_meta_data->levels.begin();
|
|
|
|
it != column_famly_meta_data->levels.end(); ++it) {
|
|
|
|
jobject jlevel = LevelMetaDataJni::fromCppLevelMetaData(env, &(*it));
|
|
|
|
if (jlevel == nullptr) {
|
|
|
|
// exception occurred
|
|
|
|
env->DeleteLocalRef(jname);
|
|
|
|
env->DeleteLocalRef(jlevels);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
env->SetObjectArrayElement(jlevels, i++, jlevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
jobject jcolumn_family_meta_data = env->NewObject(jclazz, mid,
|
|
|
|
static_cast<jlong>(column_famly_meta_data->size),
|
|
|
|
static_cast<jlong>(column_famly_meta_data->file_count),
|
|
|
|
jname,
|
|
|
|
jlevels
|
|
|
|
);
|
|
|
|
|
2017-09-22 00:15:27 +00:00
|
|
|
if (env->ExceptionCheck()) {
|
2019-02-22 22:36:38 +00:00
|
|
|
env->DeleteLocalRef(jname);
|
|
|
|
env->DeleteLocalRef(jlevels);
|
2017-09-22 00:15:27 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// cleanup
|
|
|
|
env->DeleteLocalRef(jname);
|
|
|
|
env->DeleteLocalRef(jlevels);
|
|
|
|
|
|
|
|
return jcolumn_family_meta_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return JavaClass::getJClass(env, "org/rocksdb/ColumnFamilyMetaData");
|
2017-09-22 00:15:27 +00:00
|
|
|
}
|
2019-02-22 22:36:38 +00:00
|
|
|
};
|
2017-09-22 00:15:27 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.AbstractTraceWriter
|
2020-02-20 20:07:53 +00:00
|
|
|
class AbstractTraceWriterJni
|
|
|
|
: public RocksDBNativeClass<
|
|
|
|
const ROCKSDB_NAMESPACE::TraceWriterJniCallback*,
|
|
|
|
AbstractTraceWriterJni> {
|
2019-02-22 22:36:38 +00:00
|
|
|
public:
|
2017-09-22 00:15:27 +00:00
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.AbstractTraceWriter
|
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/AbstractTraceWriter");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the Java Method: AbstractTraceWriter#write
|
2017-09-22 00:15:27 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getWriteProxyMethodId(JNIEnv* env) {
|
2017-09-22 00:15:27 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
2019-02-22 22:36:38 +00:00
|
|
|
if(jclazz == nullptr) {
|
2017-09-22 00:15:27 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "writeProxy", "(J)S");
|
2017-09-22 00:15:27 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: AbstractTraceWriter#closeWriter
|
2017-09-22 00:15:27 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getCloseWriterProxyMethodId(JNIEnv* env) {
|
2017-09-22 00:15:27 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
2019-02-22 22:36:38 +00:00
|
|
|
if(jclazz == nullptr) {
|
2017-09-22 00:15:27 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static jmethodID mid = env->GetMethodID(
|
2019-02-22 22:36:38 +00:00
|
|
|
jclazz, "closeWriterProxy", "()S");
|
2017-09-22 00:15:27 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
2018-03-02 18:22:38 +00:00
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: AbstractTraceWriter#getFileSize
|
2018-03-02 18:22:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getGetFileSizeMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
2018-03-02 18:22:38 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "getFileSize", "()J");
|
2018-03-02 18:22:38 +00:00
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.AbstractWalFilter
|
2020-02-20 20:07:53 +00:00
|
|
|
class AbstractWalFilterJni
|
|
|
|
: public RocksDBNativeClass<const ROCKSDB_NAMESPACE::WalFilterJniCallback*,
|
|
|
|
AbstractWalFilterJni> {
|
2018-03-02 18:22:38 +00:00
|
|
|
public:
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Class org.rocksdb.AbstractWalFilter
|
2018-03-02 18:22:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Class or nullptr if one of the
|
|
|
|
* ClassFormatError, ClassCircularityError, NoClassDefFoundError,
|
|
|
|
* OutOfMemoryError or ExceptionInInitializerError exceptions is thrown
|
|
|
|
*/
|
|
|
|
static jclass getJClass(JNIEnv* env) {
|
2019-02-22 22:36:38 +00:00
|
|
|
return RocksDBNativeClass::getJClass(env,
|
|
|
|
"org/rocksdb/AbstractWalFilter");
|
2018-03-02 18:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: AbstractWalFilter#columnFamilyLogNumberMap
|
2018-03-02 18:22:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2018-03-02 18:22:38 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getColumnFamilyLogNumberMapMethodId(JNIEnv* env) {
|
2018-03-02 18:22:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
2019-02-22 22:36:38 +00:00
|
|
|
if(jclazz == nullptr) {
|
2018-03-02 18:22:38 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "columnFamilyLogNumberMap",
|
|
|
|
"(Ljava/util/Map;Ljava/util/Map;)V");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2018-03-02 18:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: AbstractTraceWriter#logRecordFoundProxy
|
2018-04-13 00:55:14 +00:00
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2018-03-02 18:22:38 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getLogRecordFoundProxyMethodId(JNIEnv* env) {
|
|
|
|
jclass jclazz = getJClass(env);
|
|
|
|
if(jclazz == nullptr) {
|
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
2018-03-02 18:22:38 +00:00
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "logRecordFoundProxy", "(JLjava/lang/String;JJ)S");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
2018-03-02 18:22:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-02-22 22:36:38 +00:00
|
|
|
* Get the Java Method: AbstractTraceWriter#name
|
2018-03-02 18:22:38 +00:00
|
|
|
*
|
|
|
|
* @param env A pointer to the Java environment
|
|
|
|
*
|
2019-02-22 22:36:38 +00:00
|
|
|
* @return The Java Method ID or nullptr if the class or method id could not
|
|
|
|
* be retieved
|
2018-03-02 18:22:38 +00:00
|
|
|
*/
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID getNameMethodId(JNIEnv* env) {
|
2018-03-02 18:22:38 +00:00
|
|
|
jclass jclazz = getJClass(env);
|
2019-02-22 22:36:38 +00:00
|
|
|
if(jclazz == nullptr) {
|
2018-03-02 18:22:38 +00:00
|
|
|
// exception occurred accessing class
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
static jmethodID mid = env->GetMethodID(
|
|
|
|
jclazz, "name", "()Ljava/lang/String;");
|
|
|
|
assert(mid != nullptr);
|
|
|
|
return mid;
|
|
|
|
}
|
|
|
|
};
|
2018-03-02 18:22:38 +00:00
|
|
|
|
2019-02-22 22:36:38 +00:00
|
|
|
// The portal class for org.rocksdb.WalProcessingOption
|
|
|
|
class WalProcessingOptionJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.WalProcessingOption for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption enum
|
|
|
|
static jbyte toJavaWalProcessingOption(
|
|
|
|
const ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption&
|
|
|
|
wal_processing_option) {
|
|
|
|
switch (wal_processing_option) {
|
|
|
|
case ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::
|
|
|
|
kContinueProcessing:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::
|
|
|
|
kIgnoreCurrentRecord:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::kStopReplay:
|
|
|
|
return 0x2;
|
|
|
|
case ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::kCorruptedRecord:
|
|
|
|
return 0x3;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 18:22:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++
|
|
|
|
// ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption enum for the provided
|
|
|
|
// Java org.rocksdb.WalProcessingOption
|
|
|
|
static ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption
|
|
|
|
toCppWalProcessingOption(jbyte jwal_processing_option) {
|
|
|
|
switch (jwal_processing_option) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::
|
|
|
|
kContinueProcessing;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::
|
|
|
|
kIgnoreCurrentRecord;
|
|
|
|
case 0x2:
|
|
|
|
return ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::kStopReplay;
|
|
|
|
case 0x3:
|
|
|
|
return ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::
|
|
|
|
kCorruptedRecord;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::WalFilter::WalProcessingOption::
|
|
|
|
kCorruptedRecord;
|
|
|
|
}
|
|
|
|
}
|
2018-03-02 18:22:38 +00:00
|
|
|
};
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
|
|
|
|
// The portal class for org.rocksdb.ReusedSynchronisationType
|
|
|
|
class ReusedSynchronisationTypeJni {
|
|
|
|
public:
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent org.rocksdb.ReusedSynchronisationType for the
|
|
|
|
// provided C++ ROCKSDB_NAMESPACE::ReusedSynchronisationType enum
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
static jbyte toJavaReusedSynchronisationType(
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::ReusedSynchronisationType&
|
|
|
|
reused_synchronisation_type) {
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
switch(reused_synchronisation_type) {
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::ReusedSynchronisationType::MUTEX:
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
return 0x0;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::ReusedSynchronisationType::ADAPTIVE_MUTEX:
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
return 0x1;
|
2020-02-20 20:07:53 +00:00
|
|
|
case ROCKSDB_NAMESPACE::ReusedSynchronisationType::THREAD_LOCAL:
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
return 0x2;
|
|
|
|
default:
|
|
|
|
return 0x7F; // undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::ReusedSynchronisationType
|
|
|
|
// enum for the provided Java org.rocksdb.ReusedSynchronisationType
|
|
|
|
static ROCKSDB_NAMESPACE::ReusedSynchronisationType
|
|
|
|
toCppReusedSynchronisationType(jbyte reused_synchronisation_type) {
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
switch(reused_synchronisation_type) {
|
|
|
|
case 0x0:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::ReusedSynchronisationType::MUTEX;
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
case 0x1:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::ReusedSynchronisationType::ADAPTIVE_MUTEX;
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
case 0x2:
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::ReusedSynchronisationType::THREAD_LOCAL;
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
default:
|
|
|
|
// undefined/default
|
2020-02-20 20:07:53 +00:00
|
|
|
return ROCKSDB_NAMESPACE::ReusedSynchronisationType::ADAPTIVE_MUTEX;
|
Improve RocksJava Comparator (#6252)
Summary:
This is a redesign of the API for RocksJava comparators with the aim of improving performance. It also simplifies the class hierarchy.
**NOTE**: This breaks backwards compatibility for existing 3rd party Comparators implemented in Java... so we need to consider carefully which release branches this goes into.
Previously when implementing a comparator in Java the developer had a choice of subclassing either `DirectComparator` or `Comparator` which would use direct and non-direct byte-buffers resepectively (via `DirectSlice` and `Slice`).
In this redesign there we have eliminated the overhead of using the Java Slice classes, and just use `ByteBuffer`s. The `ComparatorOptions` supplied when constructing a Comparator allow you to choose between direct and non-direct byte buffers by setting `useDirect`.
In addition, the `ComparatorOptions` now allow you to choose whether a ByteBuffer is reused over multiple comparator calls, by setting `maxReusedBufferSize > 0`. When buffers are reused, ComparatorOptions provides a choice of mutex type by setting `useAdaptiveMutex`.
---
[JMH benchmarks previously indicated](https://github.com/facebook/rocksdb/pull/6241#issue-356398306) that the difference between C++ and Java for implementing a comparator was ~7x slowdown in Java.
With these changes, when reusing buffers and guarding access to them via mutexes the slowdown is approximately the same. However, these changes offer a new facility to not reuse mutextes, which reduces the slowdown to ~5.5x in Java. We also offer a `thread_local` mechanism for reusing buffers, which reduces slowdown to ~5.2x in Java (closes https://github.com/facebook/rocksdb/pull/4425).
These changes also form a good base for further optimisation work such as further JNI lookup caching, and JNI critical.
---
These numbers were captured without jemalloc. With jemalloc, the performance improves for all tests, and the Java slowdown reduces to between 4.8x and 5.x.
```
ComparatorBenchmarks.put native_bytewise thrpt 25 124483.795 ± 2032.443 ops/s
ComparatorBenchmarks.put native_reverse_bytewise thrpt 25 114414.536 ± 3486.156 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 17228.250 ± 1288.546 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 16035.865 ± 1248.099 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_reused-64_thread-local thrpt 25 21571.500 ± 871.521 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_adaptive-mutex thrpt 25 23613.773 ± 8465.660 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 16768.172 ± 5618.489 ops/s
ComparatorBenchmarks.put java_bytewise_direct_reused-64_thread-local thrpt 25 23921.164 ± 8734.742 ops/s
ComparatorBenchmarks.put java_bytewise_non-direct_no-reuse thrpt 25 17899.684 ± 839.679 ops/s
ComparatorBenchmarks.put java_bytewise_direct_no-reuse thrpt 25 22148.316 ± 1215.527 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_adaptive-mutex thrpt 25 11311.126 ± 820.602 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_non-adaptive-mutex thrpt 25 11421.311 ± 807.210 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_reused-64_thread-local thrpt 25 11554.005 ± 960.556 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_adaptive-mutex thrpt 25 22960.523 ± 1673.421 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_non-adaptive-mutex thrpt 25 18293.317 ± 1434.601 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_reused-64_thread-local thrpt 25 24479.361 ± 2157.306 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_non-direct_no-reuse thrpt 25 7942.286 ± 626.170 ops/s
ComparatorBenchmarks.put java_reverse_bytewise_direct_no-reuse thrpt 25 11781.955 ± 1019.843 ops/s
```
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6252
Differential Revision: D19331064
Pulled By: pdillinger
fbshipit-source-id: 1f3b794e6a14162b2c3ffb943e8c0e64a0c03738
2020-02-03 20:28:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-04-22 00:35:28 +00:00
|
|
|
// The portal class for org.rocksdb.SanityLevel
|
|
|
|
class SanityLevelJni {
|
|
|
|
public:
|
|
|
|
// Returns the equivalent org.rocksdb.SanityLevel for the provided
|
|
|
|
// C++ ROCKSDB_NAMESPACE::ConfigOptions::SanityLevel enum
|
|
|
|
static jbyte toJavaSanityLevel(
|
|
|
|
const ROCKSDB_NAMESPACE::ConfigOptions::SanityLevel &sanity_level) {
|
|
|
|
switch (sanity_level) {
|
|
|
|
case ROCKSDB_NAMESPACE::ConfigOptions::SanityLevel::kSanityLevelNone:
|
|
|
|
return 0x0;
|
|
|
|
case ROCKSDB_NAMESPACE::ConfigOptions::SanityLevel::
|
|
|
|
kSanityLevelLooselyCompatible:
|
|
|
|
return 0x1;
|
|
|
|
case ROCKSDB_NAMESPACE::ConfigOptions::SanityLevel::
|
|
|
|
kSanityLevelExactMatch:
|
|
|
|
return -0x01;
|
|
|
|
default:
|
|
|
|
return -0x01; // undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the equivalent C++ ROCKSDB_NAMESPACE::ConfigOptions::SanityLevel enum for
|
|
|
|
// the provided Java org.rocksdb.SanityLevel
|
|
|
|
static ROCKSDB_NAMESPACE::ConfigOptions::SanityLevel toCppSanityLevel(
|
|
|
|
jbyte sanity_level) {
|
|
|
|
switch (sanity_level) {
|
|
|
|
case 0x0:
|
|
|
|
return ROCKSDB_NAMESPACE::ConfigOptions::kSanityLevelNone;
|
|
|
|
case 0x1:
|
|
|
|
return ROCKSDB_NAMESPACE::ConfigOptions::kSanityLevelLooselyCompatible;
|
|
|
|
default:
|
|
|
|
// undefined/default
|
|
|
|
return ROCKSDB_NAMESPACE::ConfigOptions::kSanityLevelExactMatch;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
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 21:19:21 +00:00
|
|
|
#endif // JAVA_ROCKSJNI_PORTAL_H_
|