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).
|
2014-10-23 17:19:38 +02:00
|
|
|
//
|
|
|
|
// This file implements the callback "bridge" between Java and C++ for
|
2020-02-20 21:07:53 +01:00
|
|
|
// ROCKSDB_NAMESPACE::Comparator.
|
2014-10-23 17:19:38 +02:00
|
|
|
|
|
|
|
#include "rocksjni/writebatchhandlerjnicallback.h"
|
|
|
|
#include "rocksjni/portal.h"
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2014-10-23 17:19:38 +02:00
|
|
|
WriteBatchHandlerJniCallback::WriteBatchHandlerJniCallback(
|
2014-11-05 19:56:45 +01:00
|
|
|
JNIEnv* env, jobject jWriteBatchHandler)
|
2017-10-12 20:06:51 +02:00
|
|
|
: JniCallback(env, jWriteBatchHandler), m_env(env) {
|
2014-10-23 17:19:38 +02:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jPutCfMethodId = WriteBatchHandlerJni::getPutCfMethodId(env);
|
|
|
|
if(m_jPutCfMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-23 17:19:38 +02:00
|
|
|
m_jPutMethodId = WriteBatchHandlerJni::getPutMethodId(env);
|
2017-02-28 01:26:12 +01:00
|
|
|
if(m_jPutMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jMergeCfMethodId = WriteBatchHandlerJni::getMergeCfMethodId(env);
|
|
|
|
if(m_jMergeCfMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-23 17:19:38 +02:00
|
|
|
m_jMergeMethodId = WriteBatchHandlerJni::getMergeMethodId(env);
|
2017-02-28 01:26:12 +01:00
|
|
|
if(m_jMergeMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jDeleteCfMethodId = WriteBatchHandlerJni::getDeleteCfMethodId(env);
|
|
|
|
if(m_jDeleteCfMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-23 17:19:38 +02:00
|
|
|
m_jDeleteMethodId = WriteBatchHandlerJni::getDeleteMethodId(env);
|
2017-02-28 01:26:12 +01:00
|
|
|
if(m_jDeleteMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jSingleDeleteCfMethodId =
|
|
|
|
WriteBatchHandlerJni::getSingleDeleteCfMethodId(env);
|
|
|
|
if(m_jSingleDeleteCfMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_jSingleDeleteMethodId = WriteBatchHandlerJni::getSingleDeleteMethodId(env);
|
|
|
|
if(m_jSingleDeleteMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_jDeleteRangeCfMethodId =
|
|
|
|
WriteBatchHandlerJni::getDeleteRangeCfMethodId(env);
|
|
|
|
if (m_jDeleteRangeCfMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-07 07:13:53 +01:00
|
|
|
m_jDeleteRangeMethodId = WriteBatchHandlerJni::getDeleteRangeMethodId(env);
|
|
|
|
if (m_jDeleteRangeMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-10-23 17:19:38 +02:00
|
|
|
m_jLogDataMethodId = WriteBatchHandlerJni::getLogDataMethodId(env);
|
2017-02-28 01:26:12 +01:00
|
|
|
if(m_jLogDataMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jPutBlobIndexCfMethodId =
|
|
|
|
WriteBatchHandlerJni::getPutBlobIndexCfMethodId(env);
|
|
|
|
if(m_jPutBlobIndexCfMethodId == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
2014-10-23 17:19:38 +02:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jMarkBeginPrepareMethodId =
|
|
|
|
WriteBatchHandlerJni::getMarkBeginPrepareMethodId(env);
|
|
|
|
if(m_jMarkBeginPrepareMethodId == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jMarkEndPrepareMethodId =
|
|
|
|
WriteBatchHandlerJni::getMarkEndPrepareMethodId(env);
|
|
|
|
if(m_jMarkEndPrepareMethodId == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
2014-11-05 19:56:45 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jMarkNoopMethodId = WriteBatchHandlerJni::getMarkNoopMethodId(env);
|
|
|
|
if(m_jMarkNoopMethodId == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
2021-12-10 20:03:39 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jMarkRollbackMethodId = WriteBatchHandlerJni::getMarkRollbackMethodId(env);
|
|
|
|
if(m_jMarkRollbackMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
2014-10-23 17:19:38 +02:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jMarkCommitMethodId = WriteBatchHandlerJni::getMarkCommitMethodId(env);
|
|
|
|
if(m_jMarkCommitMethodId == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-12-10 20:03:39 +01:00
|
|
|
m_jMarkCommitWithTimestampMethodId =
|
|
|
|
WriteBatchHandlerJni::getMarkCommitWithTimestampMethodId(env);
|
|
|
|
if (m_jMarkCommitWithTimestampMethodId == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jContinueMethodId = WriteBatchHandlerJni::getContinueMethodId(env);
|
|
|
|
if(m_jContinueMethodId == nullptr) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown
|
|
|
|
return;
|
|
|
|
}
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2014-11-05 19:56:45 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::PutCF(
|
|
|
|
uint32_t column_family_id, const Slice& key, const Slice& value) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto put = [this, column_family_id] (
|
|
|
|
jbyteArray j_key, jbyteArray j_value) {
|
|
|
|
m_env->CallVoidMethod(
|
2017-10-12 20:06:51 +02:00
|
|
|
m_jcallback_obj,
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jPutCfMethodId,
|
|
|
|
static_cast<jint>(column_family_id),
|
2014-11-05 19:56:45 +01:00
|
|
|
j_key,
|
|
|
|
j_value);
|
2018-03-03 00:33:08 +01:00
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::kv_op(key, value, put);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2014-11-05 19:56:45 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
void WriteBatchHandlerJniCallback::Put(const Slice& key, const Slice& value) {
|
|
|
|
auto put = [this] (
|
|
|
|
jbyteArray j_key, jbyteArray j_value) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jPutMethodId,
|
|
|
|
j_key,
|
|
|
|
j_value);
|
|
|
|
};
|
|
|
|
WriteBatchHandlerJniCallback::kv_op(key, value, put);
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::MergeCF(
|
|
|
|
uint32_t column_family_id, const Slice& key, const Slice& value) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto merge = [this, column_family_id] (
|
|
|
|
jbyteArray j_key, jbyteArray j_value) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jMergeCfMethodId,
|
|
|
|
static_cast<jint>(column_family_id),
|
|
|
|
j_key,
|
|
|
|
j_value);
|
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::kv_op(key, value, merge);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
2014-10-23 17:19:38 +02:00
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
void WriteBatchHandlerJniCallback::Merge(const Slice& key, const Slice& value) {
|
|
|
|
auto merge = [this] (
|
|
|
|
jbyteArray j_key, jbyteArray j_value) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jMergeMethodId,
|
|
|
|
j_key,
|
|
|
|
j_value);
|
|
|
|
};
|
|
|
|
WriteBatchHandlerJniCallback::kv_op(key, value, merge);
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::DeleteCF(
|
|
|
|
uint32_t column_family_id, const Slice& key) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto remove = [this, column_family_id] (jbyteArray j_key) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jDeleteCfMethodId,
|
|
|
|
static_cast<jint>(column_family_id),
|
|
|
|
j_key);
|
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::k_op(key, remove);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2014-11-05 19:56:45 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
void WriteBatchHandlerJniCallback::Delete(const Slice& key) {
|
|
|
|
auto remove = [this] (jbyteArray j_key) {
|
|
|
|
m_env->CallVoidMethod(
|
2017-10-12 20:06:51 +02:00
|
|
|
m_jcallback_obj,
|
2014-10-23 17:19:38 +02:00
|
|
|
m_jDeleteMethodId,
|
2014-11-05 19:56:45 +01:00
|
|
|
j_key);
|
2018-03-03 00:33:08 +01:00
|
|
|
};
|
|
|
|
WriteBatchHandlerJniCallback::k_op(key, remove);
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::SingleDeleteCF(
|
|
|
|
uint32_t column_family_id, const Slice& key) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto singleDelete = [this, column_family_id] (jbyteArray j_key) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jSingleDeleteCfMethodId,
|
|
|
|
static_cast<jint>(column_family_id),
|
|
|
|
j_key);
|
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::k_op(key, singleDelete);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2014-11-05 19:56:45 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
void WriteBatchHandlerJniCallback::SingleDelete(const Slice& key) {
|
|
|
|
auto singleDelete = [this] (jbyteArray j_key) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jSingleDeleteMethodId,
|
|
|
|
j_key);
|
|
|
|
};
|
|
|
|
WriteBatchHandlerJniCallback::k_op(key, singleDelete);
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::DeleteRangeCF(
|
|
|
|
uint32_t column_family_id, const Slice& beginKey, const Slice& endKey) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto deleteRange = [this, column_family_id] (
|
|
|
|
jbyteArray j_beginKey, jbyteArray j_endKey) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jDeleteRangeCfMethodId,
|
|
|
|
static_cast<jint>(column_family_id),
|
|
|
|
j_beginKey,
|
|
|
|
j_endKey);
|
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::kv_op(beginKey, endKey, deleteRange);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
2014-10-23 17:19:38 +02:00
|
|
|
}
|
|
|
|
|
2017-03-07 07:13:53 +01:00
|
|
|
void WriteBatchHandlerJniCallback::DeleteRange(const Slice& beginKey,
|
2018-03-03 00:33:08 +01:00
|
|
|
const Slice& endKey) {
|
|
|
|
auto deleteRange = [this] (
|
|
|
|
jbyteArray j_beginKey, jbyteArray j_endKey) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jDeleteRangeMethodId,
|
|
|
|
j_beginKey,
|
|
|
|
j_endKey);
|
|
|
|
};
|
|
|
|
WriteBatchHandlerJniCallback::kv_op(beginKey, endKey, deleteRange);
|
|
|
|
}
|
2017-03-07 07:13:53 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
void WriteBatchHandlerJniCallback::LogData(const Slice& blob) {
|
|
|
|
auto logData = [this] (jbyteArray j_blob) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jLogDataMethodId,
|
|
|
|
j_blob);
|
|
|
|
};
|
|
|
|
WriteBatchHandlerJniCallback::k_op(blob, logData);
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::PutBlobIndexCF(
|
|
|
|
uint32_t column_family_id, const Slice& key, const Slice& value) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto putBlobIndex = [this, column_family_id] (
|
|
|
|
jbyteArray j_key, jbyteArray j_value) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jPutBlobIndexCfMethodId,
|
|
|
|
static_cast<jint>(column_family_id),
|
|
|
|
j_key,
|
|
|
|
j_value);
|
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::kv_op(key, value, putBlobIndex);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-03-07 07:13:53 +01:00
|
|
|
}
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::MarkBeginPrepare(
|
|
|
|
bool unprepare) {
|
2018-09-05 22:41:09 +02:00
|
|
|
#ifndef DEBUG
|
|
|
|
(void) unprepare;
|
|
|
|
#else
|
2018-07-07 02:17:36 +02:00
|
|
|
assert(!unprepare);
|
2018-09-05 22:41:09 +02:00
|
|
|
#endif
|
2018-03-03 00:33:08 +01:00
|
|
|
m_env->CallVoidMethod(m_jcallback_obj, m_jMarkBeginPrepareMethodId);
|
2017-03-07 07:13:53 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
// check for Exception, in-particular RocksDBException
|
2017-03-07 07:13:53 +01:00
|
|
|
if (m_env->ExceptionCheck()) {
|
|
|
|
// exception thrown
|
2018-03-03 00:33:08 +01:00
|
|
|
jthrowable exception = m_env->ExceptionOccurred();
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::toCppStatus(m_env, exception);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status == nullptr) {
|
|
|
|
// unkown status or exception occurred extracting status
|
|
|
|
m_env->ExceptionDescribe();
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) probably need a
|
|
|
|
// better error code here
|
2018-03-03 00:33:08 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
m_env->ExceptionClear(); // clear the exception, as we have extracted the status
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-03-07 07:13:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK();
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2017-03-07 07:13:53 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::MarkEndPrepare(
|
|
|
|
const Slice& xid) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto markEndPrepare = [this] (
|
|
|
|
jbyteArray j_xid) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jMarkEndPrepareMethodId,
|
|
|
|
j_xid);
|
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::k_op(xid, markEndPrepare);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-03-07 07:13:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::MarkNoop(
|
|
|
|
bool empty_batch) {
|
2018-03-03 00:33:08 +01:00
|
|
|
m_env->CallVoidMethod(m_jcallback_obj, m_jMarkNoopMethodId, static_cast<jboolean>(empty_batch));
|
|
|
|
|
|
|
|
// check for Exception, in-particular RocksDBException
|
|
|
|
if (m_env->ExceptionCheck()) {
|
2017-02-28 01:26:12 +01:00
|
|
|
// exception thrown
|
2018-03-03 00:33:08 +01:00
|
|
|
jthrowable exception = m_env->ExceptionOccurred();
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::toCppStatus(m_env, exception);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status == nullptr) {
|
|
|
|
// unkown status or exception occurred extracting status
|
2017-02-28 01:26:12 +01:00
|
|
|
m_env->ExceptionDescribe();
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) probably need a
|
|
|
|
// better error code here
|
2018-03-03 00:33:08 +01:00
|
|
|
|
|
|
|
} else {
|
|
|
|
m_env->ExceptionClear(); // clear the exception, as we have extracted the status
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-05 19:56:45 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK();
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::MarkRollback(
|
|
|
|
const Slice& xid) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto markRollback = [this] (
|
|
|
|
jbyteArray j_xid) {
|
|
|
|
m_env->CallVoidMethod(
|
2017-10-12 20:06:51 +02:00
|
|
|
m_jcallback_obj,
|
2018-03-03 00:33:08 +01:00
|
|
|
m_jMarkRollbackMethodId,
|
|
|
|
j_xid);
|
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::k_op(xid, markRollback);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
2014-11-05 19:56:45 +01:00
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::MarkCommit(
|
|
|
|
const Slice& xid) {
|
2018-03-03 00:33:08 +01:00
|
|
|
auto markCommit = [this] (
|
|
|
|
jbyteArray j_xid) {
|
|
|
|
m_env->CallVoidMethod(
|
|
|
|
m_jcallback_obj,
|
|
|
|
m_jMarkCommitMethodId,
|
|
|
|
j_xid);
|
|
|
|
};
|
|
|
|
auto status = WriteBatchHandlerJniCallback::k_op(xid, markCommit);
|
|
|
|
if(status == nullptr) {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
2018-03-03 00:33:08 +01:00
|
|
|
} else {
|
2020-02-20 21:07:53 +01:00
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
2014-10-23 17:19:38 +02:00
|
|
|
}
|
|
|
|
|
2021-12-10 20:03:39 +01:00
|
|
|
ROCKSDB_NAMESPACE::Status WriteBatchHandlerJniCallback::MarkCommitWithTimestamp(
|
|
|
|
const Slice& xid, const Slice& ts) {
|
|
|
|
auto markCommitWithTimestamp = [this](jbyteArray j_xid, jbyteArray j_ts) {
|
|
|
|
m_env->CallVoidMethod(m_jcallback_obj, m_jMarkCommitWithTimestampMethodId,
|
|
|
|
j_xid, j_ts);
|
|
|
|
};
|
|
|
|
auto status =
|
|
|
|
WriteBatchHandlerJniCallback::kv_op(xid, ts, markCommitWithTimestamp);
|
|
|
|
if (status == nullptr) {
|
|
|
|
return ROCKSDB_NAMESPACE::Status::OK(); // TODO(AR) what to do if there is
|
|
|
|
// an Exception but we don't know
|
|
|
|
// the ROCKSDB_NAMESPACE::Status?
|
|
|
|
} else {
|
|
|
|
return ROCKSDB_NAMESPACE::Status(*status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-23 17:19:38 +02:00
|
|
|
bool WriteBatchHandlerJniCallback::Continue() {
|
2014-11-05 19:56:45 +01:00
|
|
|
jboolean jContinue = m_env->CallBooleanMethod(
|
2017-10-12 20:06:51 +02:00
|
|
|
m_jcallback_obj,
|
2014-10-23 17:19:38 +02:00
|
|
|
m_jContinueMethodId);
|
2017-02-28 01:26:12 +01:00
|
|
|
if(m_env->ExceptionCheck()) {
|
|
|
|
// exception thrown
|
|
|
|
m_env->ExceptionDescribe();
|
|
|
|
}
|
2014-10-23 17:19:38 +02:00
|
|
|
|
|
|
|
return static_cast<bool>(jContinue == JNI_TRUE);
|
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> WriteBatchHandlerJniCallback::kv_op(
|
|
|
|
const Slice& key, const Slice& value,
|
|
|
|
std::function<void(jbyteArray, jbyteArray)> kvFn) {
|
|
|
|
const jbyteArray j_key = JniUtil::copyBytes(m_env, key);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (j_key == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
if (m_env->ExceptionCheck()) {
|
|
|
|
m_env->ExceptionDescribe();
|
|
|
|
}
|
2017-02-28 01:26:12 +01:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
const jbyteArray j_value = JniUtil::copyBytes(m_env, value);
|
|
|
|
if (j_value == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
if (m_env->ExceptionCheck()) {
|
|
|
|
m_env->ExceptionDescribe();
|
|
|
|
}
|
|
|
|
if (j_key != nullptr) {
|
|
|
|
m_env->DeleteLocalRef(j_key);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
kvFn(j_key, j_value);
|
|
|
|
|
|
|
|
// check for Exception, in-particular RocksDBException
|
|
|
|
if (m_env->ExceptionCheck()) {
|
|
|
|
if (j_value != nullptr) {
|
|
|
|
m_env->DeleteLocalRef(j_value);
|
|
|
|
}
|
|
|
|
if (j_key != nullptr) {
|
|
|
|
m_env->DeleteLocalRef(j_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// exception thrown
|
|
|
|
jthrowable exception = m_env->ExceptionOccurred();
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::toCppStatus(m_env, exception);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status == nullptr) {
|
|
|
|
// unkown status or exception occurred extracting status
|
|
|
|
m_env->ExceptionDescribe();
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_env->ExceptionClear(); // clear the exception, as we have extracted the status
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j_value != nullptr) {
|
|
|
|
m_env->DeleteLocalRef(j_value);
|
|
|
|
}
|
|
|
|
if (j_key != nullptr) {
|
|
|
|
m_env->DeleteLocalRef(j_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// all OK
|
2020-02-20 21:07:53 +01:00
|
|
|
return std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::OK()));
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
|
|
|
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> WriteBatchHandlerJniCallback::k_op(
|
|
|
|
const Slice& key, std::function<void(jbyteArray)> kFn) {
|
|
|
|
const jbyteArray j_key = JniUtil::copyBytes(m_env, key);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (j_key == nullptr) {
|
|
|
|
// exception thrown
|
|
|
|
if (m_env->ExceptionCheck()) {
|
|
|
|
m_env->ExceptionDescribe();
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
kFn(j_key);
|
|
|
|
|
|
|
|
// check for Exception, in-particular RocksDBException
|
|
|
|
if (m_env->ExceptionCheck()) {
|
|
|
|
if (j_key != nullptr) {
|
|
|
|
m_env->DeleteLocalRef(j_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// exception thrown
|
|
|
|
jthrowable exception = m_env->ExceptionOccurred();
|
2020-02-20 21:07:53 +01:00
|
|
|
std::unique_ptr<ROCKSDB_NAMESPACE::Status> status =
|
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::toCppStatus(m_env, exception);
|
2018-03-03 00:33:08 +01:00
|
|
|
if (status == nullptr) {
|
|
|
|
// unkown status or exception occurred extracting status
|
|
|
|
m_env->ExceptionDescribe();
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_env->ExceptionClear(); // clear the exception, as we have extracted the status
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j_key != nullptr) {
|
|
|
|
m_env->DeleteLocalRef(j_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// all OK
|
2020-02-20 21:07:53 +01:00
|
|
|
return std::unique_ptr<ROCKSDB_NAMESPACE::Status>(
|
|
|
|
new ROCKSDB_NAMESPACE::Status(ROCKSDB_NAMESPACE::Status::OK()));
|
2014-10-23 17:19:38 +02:00
|
|
|
}
|
2020-02-20 21:07:53 +01:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|