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