2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2015-01-03 15:52:07 +01:00
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ and enables
|
2020-02-20 21:07:53 +01:00
|
|
|
// calling c++ ROCKSDB_NAMESPACE::WriteBatchWithIndex methods from Java side.
|
2015-01-03 15:52:07 +01:00
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
#include "rocksdb/utilities/write_batch_with_index.h"
|
2022-03-01 18:02:15 +01:00
|
|
|
|
2015-01-03 16:23:24 +01:00
|
|
|
#include "include/org_rocksdb_WBWIRocksIterator.h"
|
2015-01-03 15:52:07 +01:00
|
|
|
#include "include/org_rocksdb_WriteBatchWithIndex.h"
|
|
|
|
#include "rocksdb/comparator.h"
|
2022-03-01 18:02:15 +01:00
|
|
|
#include "rocksjni/cplusplus_to_java_convert.h"
|
2015-01-03 16:23:24 +01:00
|
|
|
#include "rocksjni/portal.h"
|
2015-01-03 15:52:07 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: newWriteBatchWithIndex
|
2016-01-20 18:05:41 +01:00
|
|
|
* Signature: ()J
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2016-01-20 18:05:41 +01:00
|
|
|
jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* /*env*/, jclass /*jcls*/) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex();
|
2022-03-01 18:02:15 +01:00
|
|
|
return GET_CPLUSPLUS_POINTER(wbwi);
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: newWriteBatchWithIndex
|
2016-01-20 18:05:41 +01:00
|
|
|
* Signature: (Z)J
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2016-01-20 18:05:41 +01:00
|
|
|
jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__Z(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* /*env*/, jclass /*jcls*/, jboolean joverwrite_key) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex(
|
|
|
|
ROCKSDB_NAMESPACE::BytewiseComparator(), 0,
|
|
|
|
static_cast<bool>(joverwrite_key));
|
2022-03-01 18:02:15 +01:00
|
|
|
return GET_CPLUSPLUS_POINTER(wbwi);
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: newWriteBatchWithIndex
|
2018-03-08 20:16:46 +01:00
|
|
|
* Signature: (JBIZ)J
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2018-03-08 20:16:46 +01:00
|
|
|
jlong Java_org_rocksdb_WriteBatchWithIndex_newWriteBatchWithIndex__JBIZ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* /*env*/, jclass /*jcls*/, jlong jfallback_index_comparator_handle,
|
2018-03-08 20:16:46 +01:00
|
|
|
jbyte jcomparator_type, jint jreserved_bytes, jboolean joverwrite_key) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Comparator* fallback_comparator = nullptr;
|
2018-04-13 02:55:14 +02:00
|
|
|
switch (jcomparator_type) {
|
|
|
|
// JAVA_COMPARATOR
|
|
|
|
case 0x0:
|
2020-02-20 21:07:53 +01:00
|
|
|
fallback_comparator =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ComparatorJniCallback*>(
|
|
|
|
jfallback_index_comparator_handle);
|
2018-04-13 02:55:14 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
// JAVA_NATIVE_COMPARATOR_WRAPPER
|
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 21:28:25 +01:00
|
|
|
case 0x1:
|
2020-02-20 21:07:53 +01:00
|
|
|
fallback_comparator = reinterpret_cast<ROCKSDB_NAMESPACE::Comparator*>(
|
2018-04-13 02:55:14 +02:00
|
|
|
jfallback_index_comparator_handle);
|
|
|
|
break;
|
2018-03-08 20:16:46 +01:00
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi = new ROCKSDB_NAMESPACE::WriteBatchWithIndex(
|
2018-04-13 02:55:14 +02:00
|
|
|
fallback_comparator, static_cast<size_t>(jreserved_bytes),
|
|
|
|
static_cast<bool>(joverwrite_key));
|
2022-03-01 18:02:15 +01:00
|
|
|
return GET_CPLUSPLUS_POINTER(wbwi);
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
2016-02-01 21:00:40 +01:00
|
|
|
* Method: count0
|
|
|
|
* Signature: (J)I
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jint Java_org_rocksdb_WriteBatchWithIndex_count0(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jwbwi_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 15:52:07 +01:00
|
|
|
assert(wbwi != nullptr);
|
|
|
|
|
|
|
|
return static_cast<jint>(wbwi->GetWriteBatch()->Count());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: put
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[BI[BI)V
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2016-02-01 21:00:40 +01:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_put__J_3BI_3BI(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
|
|
|
jint jkey_len, jbyteArray jentry_value, jint jentry_value_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 18:52:17 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto put = [&wbwi](ROCKSDB_NAMESPACE::Slice key,
|
|
|
|
ROCKSDB_NAMESPACE::Slice value) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->Put(key, value);
|
2015-01-03 18:52:17 +01:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::kv_op(put, env, jobj, jkey, jkey_len,
|
|
|
|
jentry_value, jentry_value_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: put
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[BI[BIJ)V
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2016-02-01 21:00:40 +01:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_put__J_3BI_3BIJ(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
|
|
|
jint jkey_len, jbyteArray jentry_value, jint jentry_value_len,
|
|
|
|
jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 15:52:07 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
2015-01-03 18:52:17 +01:00
|
|
|
assert(cf_handle != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto put = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice key,
|
|
|
|
ROCKSDB_NAMESPACE::Slice value) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->Put(cf_handle, key, value);
|
2015-01-03 18:52:17 +01:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::kv_op(put, env, jobj, jkey, jkey_len,
|
|
|
|
jentry_value, jentry_value_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
2020-02-11 23:45:15 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: putDirect
|
|
|
|
* Signature: (JLjava/nio/ByteBuffer;IILjava/nio/ByteBuffer;IIJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_putDirect(
|
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong jwb_handle, jobject jkey,
|
|
|
|
jint jkey_offset, jint jkey_len, jobject jval, jint jval_offset,
|
|
|
|
jint jval_len, jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wb = reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatch*>(jwb_handle);
|
2020-02-11 23:45:15 +01:00
|
|
|
assert(wb != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
auto put = [&wb, &cf_handle](ROCKSDB_NAMESPACE::Slice& key,
|
|
|
|
ROCKSDB_NAMESPACE::Slice& value) {
|
2020-02-11 23:45:15 +01:00
|
|
|
if (cf_handle == nullptr) {
|
|
|
|
wb->Put(key, value);
|
|
|
|
} else {
|
|
|
|
wb->Put(cf_handle, key, value);
|
|
|
|
}
|
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::JniUtil::kv_op_direct(
|
|
|
|
put, env, jkey, jkey_offset, jkey_len, jval, jval_offset, jval_len);
|
2020-02-11 23:45:15 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 15:52:07 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: merge
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[BI[BI)V
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2016-02-01 21:00:40 +01:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_merge__J_3BI_3BI(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
|
|
|
jint jkey_len, jbyteArray jentry_value, jint jentry_value_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 18:52:17 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto merge = [&wbwi](ROCKSDB_NAMESPACE::Slice key,
|
|
|
|
ROCKSDB_NAMESPACE::Slice value) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->Merge(key, value);
|
2015-01-03 18:52:17 +01:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::kv_op(merge, env, jobj, jkey, jkey_len,
|
|
|
|
jentry_value, jentry_value_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: merge
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[BI[BIJ)V
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2016-02-01 21:00:40 +01:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_merge__J_3BI_3BIJ(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
|
|
|
jint jkey_len, jbyteArray jentry_value, jint jentry_value_len,
|
|
|
|
jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 15:52:07 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
2015-01-03 18:52:17 +01:00
|
|
|
assert(cf_handle != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto merge = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice key,
|
|
|
|
ROCKSDB_NAMESPACE::Slice value) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->Merge(cf_handle, key, value);
|
2015-01-03 18:52:17 +01:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::kv_op(merge, env, jobj, jkey, jkey_len,
|
|
|
|
jentry_value, jentry_value_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
2018-03-03 00:33:08 +01:00
|
|
|
* Method: delete
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[BI)V
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_delete__J_3BI(JNIEnv* env,
|
|
|
|
jobject jobj,
|
|
|
|
jlong jwbwi_handle,
|
|
|
|
jbyteArray jkey,
|
|
|
|
jint jkey_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 18:52:17 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto remove = [&wbwi](ROCKSDB_NAMESPACE::Slice key) {
|
|
|
|
return wbwi->Delete(key);
|
|
|
|
};
|
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::k_op(remove, env, jobj, jkey, jkey_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
2018-03-03 00:33:08 +01:00
|
|
|
* Method: delete
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[BIJ)V
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2018-03-03 00:33:08 +01:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_delete__J_3BIJ(
|
2016-02-01 21:00:40 +01:00
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
|
|
|
jint jkey_len, jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 18:52:17 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
2015-01-03 18:52:17 +01:00
|
|
|
assert(cf_handle != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto remove = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice key) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->Delete(cf_handle, key);
|
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::k_op(remove, env, jobj, jkey, jkey_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: singleDelete
|
|
|
|
* Signature: (J[BI)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_singleDelete__J_3BI(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
|
|
|
jint jkey_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2018-03-03 00:33:08 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto single_delete = [&wbwi](ROCKSDB_NAMESPACE::Slice key) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->SingleDelete(key);
|
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::k_op(single_delete, env, jobj, jkey,
|
|
|
|
jkey_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: singleDelete
|
|
|
|
* Signature: (J[BIJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_singleDelete__J_3BIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jkey,
|
|
|
|
jint jkey_len, jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2018-03-03 00:33:08 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
2018-03-03 00:33:08 +01:00
|
|
|
assert(cf_handle != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto single_delete = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice key) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->SingleDelete(cf_handle, key);
|
2015-01-03 18:52:17 +01:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::k_op(single_delete, env, jobj, jkey,
|
|
|
|
jkey_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
2020-02-11 23:45:15 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
2021-12-10 18:16:47 +01:00
|
|
|
* Method: deleteDirect
|
2020-02-11 23:45:15 +01:00
|
|
|
* Signature: (JLjava/nio/ByteBuffer;IIJ)V
|
|
|
|
*/
|
2021-12-10 18:16:47 +01:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_deleteDirect(
|
2020-02-11 23:45:15 +01:00
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong jwb_handle, jobject jkey,
|
|
|
|
jint jkey_offset, jint jkey_len, jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wb = reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatch*>(jwb_handle);
|
2020-02-11 23:45:15 +01:00
|
|
|
assert(wb != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
auto remove = [&wb, &cf_handle](ROCKSDB_NAMESPACE::Slice& key) {
|
2020-02-11 23:45:15 +01:00
|
|
|
if (cf_handle == nullptr) {
|
|
|
|
wb->Delete(key);
|
|
|
|
} else {
|
|
|
|
wb->Delete(cf_handle, key);
|
|
|
|
}
|
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::JniUtil::k_op_direct(remove, env, jkey, jkey_offset,
|
|
|
|
jkey_len);
|
2020-02-11 23:45:15 +01:00
|
|
|
}
|
|
|
|
|
2017-03-07 07:13:53 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: deleteRange
|
|
|
|
* Signature: (J[BI[BI)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_deleteRange__J_3BI_3BI(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jbegin_key,
|
|
|
|
jint jbegin_key_len, jbyteArray jend_key, jint jend_key_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2017-03-07 07:13:53 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto deleteRange = [&wbwi](ROCKSDB_NAMESPACE::Slice beginKey,
|
|
|
|
ROCKSDB_NAMESPACE::Slice endKey) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->DeleteRange(beginKey, endKey);
|
2017-03-07 07:13:53 +01:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::kv_op(deleteRange, env, jobj, jbegin_key,
|
|
|
|
jbegin_key_len, jend_key, jend_key_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2017-03-07 07:13:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: deleteRange
|
|
|
|
* Signature: (J[BI[BIJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_deleteRange__J_3BI_3BIJ(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jwbwi_handle, jbyteArray jbegin_key,
|
|
|
|
jint jbegin_key_len, jbyteArray jend_key, jint jend_key_len,
|
|
|
|
jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2017-03-07 07:13:53 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
2017-03-07 07:13:53 +01:00
|
|
|
assert(cf_handle != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto deleteRange = [&wbwi, &cf_handle](ROCKSDB_NAMESPACE::Slice beginKey,
|
|
|
|
ROCKSDB_NAMESPACE::Slice endKey) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->DeleteRange(cf_handle, beginKey, endKey);
|
2017-03-07 07:13:53 +01:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::kv_op(deleteRange, env, jobj, jbegin_key,
|
|
|
|
jbegin_key_len, jend_key, jend_key_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2017-03-07 07:13:53 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 15:52:07 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: putLogData
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J[BI)V
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_putLogData(JNIEnv* env, jobject jobj,
|
|
|
|
jlong jwbwi_handle,
|
|
|
|
jbyteArray jblob,
|
|
|
|
jint jblob_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 15:52:07 +01:00
|
|
|
assert(wbwi != nullptr);
|
2020-02-20 21:07:53 +01:00
|
|
|
auto putLogData = [&wbwi](ROCKSDB_NAMESPACE::Slice blob) {
|
2018-03-03 00:33:08 +01:00
|
|
|
return wbwi->PutLogData(blob);
|
2015-01-03 18:52:17 +01:00
|
|
|
};
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::k_op(putLogData, env, jobj, jblob, jblob_len);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status != nullptr && !status->ok()) {
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: clear
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J)V
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_clear0(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jwbwi_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2015-01-03 15:52:07 +01:00
|
|
|
assert(wbwi != nullptr);
|
|
|
|
|
2016-06-14 18:51:14 +02:00
|
|
|
wbwi->Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: setSavePoint0
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_setSavePoint0(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jwbwi_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2016-06-14 18:51:14 +02:00
|
|
|
assert(wbwi != nullptr);
|
|
|
|
|
|
|
|
wbwi->SetSavePoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: rollbackToSavePoint0
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_rollbackToSavePoint0(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2016-06-14 18:51:14 +02:00
|
|
|
assert(wbwi != nullptr);
|
|
|
|
|
|
|
|
auto s = wbwi->RollbackToSavePoint();
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: popSavePoint
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_popSavePoint(JNIEnv* env,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jwbwi_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2018-03-03 00:33:08 +01:00
|
|
|
assert(wbwi != nullptr);
|
|
|
|
|
|
|
|
auto s = wbwi->PopSavePoint();
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: setMaxBytes
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_setMaxBytes(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jwbwi_handle,
|
|
|
|
jlong jmax_bytes) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2018-03-03 00:33:08 +01:00
|
|
|
assert(wbwi != nullptr);
|
|
|
|
|
|
|
|
wbwi->SetMaxBytes(static_cast<size_t>(jmax_bytes));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: getWriteBatch
|
|
|
|
* Signature: (J)Lorg/rocksdb/WriteBatch;
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jobject Java_org_rocksdb_WriteBatchWithIndex_getWriteBatch(JNIEnv* env,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jwbwi_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2018-03-03 00:33:08 +01:00
|
|
|
assert(wbwi != nullptr);
|
|
|
|
|
|
|
|
auto* wb = wbwi->GetWriteBatch();
|
|
|
|
|
|
|
|
// TODO(AR) is the `wb` object owned by us?
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::WriteBatchJni::construct(env, wb);
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 15:52:07 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: iterator0
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (J)J
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_WriteBatchWithIndex_iterator0(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jwbwi_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* wbwi_iterator = wbwi->NewIterator();
|
2022-03-01 18:02:15 +01:00
|
|
|
return GET_CPLUSPLUS_POINTER(wbwi_iterator);
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: iterator1
|
2016-02-01 21:00:40 +01:00
|
|
|
* Signature: (JJ)J
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlong Java_org_rocksdb_WriteBatchWithIndex_iterator1(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jwbwi_handle,
|
|
|
|
jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
auto* wbwi_iterator = wbwi->NewIterator(cf_handle);
|
2022-03-01 18:02:15 +01:00
|
|
|
return GET_CPLUSPLUS_POINTER(wbwi_iterator);
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: iteratorWithBase
|
2020-05-27 20:56:53 +02:00
|
|
|
* Signature: (JJJJ)J
|
2015-01-03 15:52:07 +01:00
|
|
|
*/
|
2020-05-27 20:56:53 +02:00
|
|
|
jlong Java_org_rocksdb_WriteBatchWithIndex_iteratorWithBase(
|
|
|
|
JNIEnv*, jobject, jlong jwbwi_handle, jlong jcf_handle,
|
|
|
|
jlong jbase_iterator_handle, jlong jread_opts_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
auto* base_iterator =
|
2020-05-27 20:56:53 +02:00
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::Iterator*>(jbase_iterator_handle);
|
|
|
|
ROCKSDB_NAMESPACE::ReadOptions* read_opts =
|
|
|
|
jread_opts_handle == 0
|
|
|
|
? nullptr
|
|
|
|
: reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(
|
|
|
|
jread_opts_handle);
|
|
|
|
auto* iterator =
|
|
|
|
wbwi->NewIteratorWithBase(cf_handle, base_iterator, read_opts);
|
2022-03-01 18:02:15 +01:00
|
|
|
return GET_CPLUSPLUS_POINTER(iterator);
|
2015-01-03 15:52:07 +01:00
|
|
|
}
|
|
|
|
|
2016-11-06 10:25:39 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: getFromBatch
|
|
|
|
* Signature: (JJ[BI)[B
|
|
|
|
*/
|
|
|
|
jbyteArray JNICALL Java_org_rocksdb_WriteBatchWithIndex_getFromBatch__JJ_3BI(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdbopt_handle,
|
2016-11-06 10:25:39 +01:00
|
|
|
jbyteArray jkey, jint jkey_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
|
|
|
auto* dbopt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jdbopt_handle);
|
2016-11-06 10:25:39 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
auto getter = [&wbwi, &dbopt](const ROCKSDB_NAMESPACE::Slice& key,
|
|
|
|
std::string* value) {
|
2016-11-06 10:25:39 +01:00
|
|
|
return wbwi->GetFromBatch(*dbopt, key, value);
|
|
|
|
};
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len);
|
2016-11-06 10:25:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: getFromBatch
|
|
|
|
* Signature: (JJ[BIJ)[B
|
|
|
|
*/
|
|
|
|
jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatch__JJ_3BIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdbopt_handle,
|
2016-11-06 10:25:39 +01:00
|
|
|
jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
|
|
|
auto* dbopt = reinterpret_cast<ROCKSDB_NAMESPACE::DBOptions*>(jdbopt_handle);
|
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
2016-11-06 10:25:39 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
auto getter = [&wbwi, &cf_handle, &dbopt](const ROCKSDB_NAMESPACE::Slice& key,
|
2018-04-13 02:55:14 +02:00
|
|
|
std::string* value) {
|
|
|
|
return wbwi->GetFromBatch(cf_handle, *dbopt, key, value);
|
|
|
|
};
|
2016-11-06 10:25:39 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len);
|
2016-11-06 10:25:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: getFromBatchAndDB
|
|
|
|
* Signature: (JJJ[BI)[B
|
|
|
|
*/
|
|
|
|
jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatchAndDB__JJJ_3BI(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdb_handle,
|
2016-11-06 10:25:39 +01:00
|
|
|
jlong jreadopt_handle, jbyteArray jkey, jint jkey_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
|
|
|
auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
|
|
|
|
auto* readopt =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(jreadopt_handle);
|
2016-11-06 10:25:39 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
auto getter = [&wbwi, &db, &readopt](const ROCKSDB_NAMESPACE::Slice& key,
|
2018-04-13 02:55:14 +02:00
|
|
|
std::string* value) {
|
|
|
|
return wbwi->GetFromBatchAndDB(db, *readopt, key, value);
|
|
|
|
};
|
2016-11-06 10:25:39 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len);
|
2016-11-06 10:25:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: getFromBatchAndDB
|
|
|
|
* Signature: (JJJ[BIJ)[B
|
|
|
|
*/
|
|
|
|
jbyteArray Java_org_rocksdb_WriteBatchWithIndex_getFromBatchAndDB__JJJ_3BIJ(
|
2018-04-13 02:55:14 +02:00
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong jwbwi_handle, jlong jdb_handle,
|
2016-11-06 10:25:39 +01:00
|
|
|
jlong jreadopt_handle, jbyteArray jkey, jint jkey_len, jlong jcf_handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(jwbwi_handle);
|
|
|
|
auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
|
|
|
|
auto* readopt =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ReadOptions*>(jreadopt_handle);
|
|
|
|
auto* cf_handle =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::ColumnFamilyHandle*>(jcf_handle);
|
|
|
|
|
|
|
|
auto getter = [&wbwi, &db, &cf_handle, &readopt](
|
|
|
|
const ROCKSDB_NAMESPACE::Slice& key, std::string* value) {
|
2018-04-13 02:55:14 +02:00
|
|
|
return wbwi->GetFromBatchAndDB(db, *readopt, cf_handle, key, value);
|
|
|
|
};
|
2016-11-06 10:25:39 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::JniUtil::v_op(getter, env, jkey, jkey_len);
|
2016-11-06 10:25:39 +01:00
|
|
|
}
|
|
|
|
|
2015-01-03 15:52:07 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WriteBatchWithIndex
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WriteBatchWithIndex_disposeInternal(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* wbwi =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WriteBatchWithIndex*>(handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
assert(wbwi != nullptr);
|
2015-01-03 15:52:07 +01:00
|
|
|
delete wbwi;
|
|
|
|
}
|
2015-01-03 16:23:24 +01:00
|
|
|
|
|
|
|
/* WBWIRocksIterator below */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_disposeInternal(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
assert(it != nullptr);
|
2015-01-03 16:23:24 +01:00
|
|
|
delete it;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: isValid0
|
|
|
|
* Signature: (J)Z
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jboolean Java_org_rocksdb_WBWIRocksIterator_isValid0(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Valid();
|
2015-01-03 16:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: seekToFirst0
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_seekToFirst0(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->SeekToFirst();
|
2015-01-03 16:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: seekToLast0
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_seekToLast0(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->SeekToLast();
|
2015-01-03 16:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: next0
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_next0(JNIEnv* /*env*/, jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Next();
|
2015-01-03 16:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: prev0
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_prev0(JNIEnv* /*env*/, jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle)->Prev();
|
2015-01-03 16:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: seek0
|
|
|
|
* Signature: (J[BI)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_seek0(JNIEnv* env, jobject /*jobj*/,
|
|
|
|
jlong handle, jbyteArray jtarget,
|
|
|
|
jint jtarget_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
2017-02-28 01:26:12 +01:00
|
|
|
jbyte* target = env->GetByteArrayElements(jtarget, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (target == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Slice target_slice(reinterpret_cast<char*>(target),
|
|
|
|
jtarget_len);
|
2015-01-03 16:23:24 +01:00
|
|
|
|
|
|
|
it->Seek(target_slice);
|
|
|
|
|
|
|
|
env->ReleaseByteArrayElements(jtarget, target, JNI_ABORT);
|
|
|
|
}
|
|
|
|
|
2020-02-11 23:45:15 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: seekDirect0
|
|
|
|
* Signature: (JLjava/nio/ByteBuffer;II)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_seekDirect0(
|
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong handle, jobject jtarget,
|
|
|
|
jint jtarget_off, jint jtarget_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
|
|
|
auto seek = [&it](ROCKSDB_NAMESPACE::Slice& target_slice) {
|
|
|
|
it->Seek(target_slice);
|
|
|
|
};
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::k_op_direct(seek, env, jtarget, jtarget_off,
|
|
|
|
jtarget_len);
|
2020-02-11 23:45:15 +01:00
|
|
|
}
|
|
|
|
|
2022-03-24 20:50:38 +01:00
|
|
|
/*
|
|
|
|
* This method supports fetching into indirect byte buffers;
|
|
|
|
* the Java wrapper extracts the byte[] and passes it here.
|
|
|
|
*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: seekByteArray0
|
|
|
|
* Signature: (J[BII)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_seekByteArray0(
|
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong handle, jbyteArray jtarget,
|
|
|
|
jint jtarget_off, jint jtarget_len) {
|
|
|
|
const std::unique_ptr<char[]> target(new char[jtarget_len]);
|
|
|
|
if (target == nullptr) {
|
|
|
|
jclass oom_class = env->FindClass("/lang/java/OutOfMemoryError");
|
|
|
|
env->ThrowNew(oom_class,
|
|
|
|
"Memory allocation failed in RocksDB JNI function");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
env->GetByteArrayRegion(jtarget, jtarget_off, jtarget_len,
|
|
|
|
reinterpret_cast<jbyte*>(target.get()));
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::Slice target_slice(target.get(), jtarget_len);
|
|
|
|
|
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
|
|
|
it->Seek(target_slice);
|
|
|
|
}
|
|
|
|
|
2017-09-12 19:41:48 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: seekForPrev0
|
|
|
|
* Signature: (J[BI)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_seekForPrev0(JNIEnv* env,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle,
|
|
|
|
jbyteArray jtarget,
|
|
|
|
jint jtarget_len) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
2017-09-12 19:41:48 +02:00
|
|
|
jbyte* target = env->GetByteArrayElements(jtarget, nullptr);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (target == nullptr) {
|
2017-09-12 19:41:48 +02:00
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Slice target_slice(reinterpret_cast<char*>(target),
|
|
|
|
jtarget_len);
|
2017-09-12 19:41:48 +02:00
|
|
|
|
|
|
|
it->SeekForPrev(target_slice);
|
|
|
|
|
|
|
|
env->ReleaseByteArrayElements(jtarget, target, JNI_ABORT);
|
|
|
|
}
|
|
|
|
|
2022-03-24 20:50:38 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: seekForPrevDirect0
|
|
|
|
* Signature: (JLjava/nio/ByteBuffer;II)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_seekForPrevDirect0(
|
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong handle, jobject jtarget,
|
|
|
|
jint jtarget_off, jint jtarget_len) {
|
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
|
|
|
auto seek_for_prev = [&it](ROCKSDB_NAMESPACE::Slice& target_slice) {
|
|
|
|
it->SeekForPrev(target_slice);
|
|
|
|
};
|
|
|
|
ROCKSDB_NAMESPACE::JniUtil::k_op_direct(seek_for_prev, env, jtarget,
|
|
|
|
jtarget_off, jtarget_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This method supports fetching into indirect byte buffers;
|
|
|
|
* the Java wrapper extracts the byte[] and passes it here.
|
|
|
|
*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: seekForPrevByteArray0
|
|
|
|
* Signature: (J[BII)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_seekForPrevByteArray0(
|
|
|
|
JNIEnv* env, jobject /*jobj*/, jlong handle, jbyteArray jtarget,
|
|
|
|
jint jtarget_off, jint jtarget_len) {
|
|
|
|
const std::unique_ptr<char[]> target(new char[jtarget_len]);
|
|
|
|
if (target == nullptr) {
|
|
|
|
jclass oom_class = env->FindClass("/lang/java/OutOfMemoryError");
|
|
|
|
env->ThrowNew(oom_class,
|
|
|
|
"Memory allocation failed in RocksDB JNI function");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
env->GetByteArrayRegion(jtarget, jtarget_off, jtarget_len,
|
|
|
|
reinterpret_cast<jbyte*>(target.get()));
|
|
|
|
|
|
|
|
ROCKSDB_NAMESPACE::Slice target_slice(target.get(), jtarget_len);
|
|
|
|
|
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
|
|
|
it->SeekForPrev(target_slice);
|
|
|
|
}
|
|
|
|
|
2015-01-03 16:23:24 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: status0
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_status0(JNIEnv* env, jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
|
|
|
ROCKSDB_NAMESPACE::Status s = it->status();
|
2015-01-03 16:23:24 +01:00
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
|
2015-01-03 16:23:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: entry1
|
2016-02-04 15:28:18 +01:00
|
|
|
* Signature: (J)[J
|
2015-01-03 16:23:24 +01:00
|
|
|
*/
|
2018-04-13 02:55:14 +02:00
|
|
|
jlongArray Java_org_rocksdb_WBWIRocksIterator_entry1(JNIEnv* env,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong handle) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* it = reinterpret_cast<ROCKSDB_NAMESPACE::WBWIIterator*>(handle);
|
|
|
|
const ROCKSDB_NAMESPACE::WriteEntry& we = it->Entry();
|
2015-07-02 08:22:03 +02:00
|
|
|
|
2016-02-04 15:28:18 +01:00
|
|
|
jlong results[3];
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
// set the type of the write entry
|
2020-02-20 21:07:53 +01:00
|
|
|
results[0] = ROCKSDB_NAMESPACE::WriteTypeJni::toJavaWriteType(we.type);
|
2016-02-04 15:28:18 +01:00
|
|
|
|
2018-04-13 02:55:14 +02:00
|
|
|
// NOTE: key_slice and value_slice will be freed by
|
|
|
|
// org.rocksdb.DirectSlice#close
|
2016-02-04 15:28:18 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* key_slice = new ROCKSDB_NAMESPACE::Slice(we.key.data(), we.key.size());
|
2022-03-01 18:02:15 +01:00
|
|
|
results[1] = GET_CPLUSPLUS_POINTER(key_slice);
|
2020-02-20 21:07:53 +01:00
|
|
|
if (we.type == ROCKSDB_NAMESPACE::kDeleteRecord ||
|
|
|
|
we.type == ROCKSDB_NAMESPACE::kSingleDeleteRecord ||
|
|
|
|
we.type == ROCKSDB_NAMESPACE::kLogDataRecord) {
|
2015-01-03 16:23:24 +01:00
|
|
|
// set native handle of value slice to null if no value available
|
2016-02-04 15:28:18 +01:00
|
|
|
results[2] = 0;
|
2015-01-03 16:23:24 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* value_slice =
|
|
|
|
new ROCKSDB_NAMESPACE::Slice(we.value.data(), we.value.size());
|
2022-03-01 18:02:15 +01:00
|
|
|
results[2] = GET_CPLUSPLUS_POINTER(value_slice);
|
2015-01-03 16:23:24 +01:00
|
|
|
}
|
2016-02-04 15:28:18 +01:00
|
|
|
|
|
|
|
jlongArray jresults = env->NewLongArray(3);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (jresults == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: OutOfMemoryError
|
2018-04-13 02:55:14 +02:00
|
|
|
if (results[2] != 0) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* value_slice =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::Slice*>(results[2]);
|
2017-02-28 01:26:12 +01:00
|
|
|
delete value_slice;
|
|
|
|
}
|
|
|
|
delete key_slice;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-04 15:28:18 +01:00
|
|
|
env->SetLongArrayRegion(jresults, 0, 3, results);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown: ArrayIndexOutOfBoundsException
|
|
|
|
env->DeleteLocalRef(jresults);
|
2018-04-13 02:55:14 +02:00
|
|
|
if (results[2] != 0) {
|
2020-02-20 21:07:53 +01:00
|
|
|
auto* value_slice =
|
|
|
|
reinterpret_cast<ROCKSDB_NAMESPACE::Slice*>(results[2]);
|
2017-02-28 01:26:12 +01:00
|
|
|
delete value_slice;
|
|
|
|
}
|
|
|
|
delete key_slice;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-02-04 15:28:18 +01:00
|
|
|
return jresults;
|
2015-01-03 16:23:24 +01:00
|
|
|
}
|
2020-04-17 00:49:52 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_WBWIRocksIterator
|
|
|
|
* Method: refresh0
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_WBWIRocksIterator_refresh0(JNIEnv* env) {
|
|
|
|
ROCKSDB_NAMESPACE::Status s = ROCKSDB_NAMESPACE::Status::NotSupported("Refresh() is not supported");
|
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|