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
|
|
|
|
// rocksdb::Comparator.
|
|
|
|
|
|
|
|
#include "rocksjni/writebatchhandlerjnicallback.h"
|
|
|
|
#include "rocksjni/portal.h"
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
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;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::PutCF(uint32_t column_family_id,
|
|
|
|
const Slice& key, const Slice& value) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::MergeCF(uint32_t column_family_id,
|
|
|
|
const Slice& key, const Slice& value) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::DeleteCF(uint32_t column_family_id,
|
|
|
|
const Slice& key) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::SingleDeleteCF(uint32_t column_family_id,
|
|
|
|
const Slice& key) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::DeleteRangeCF(uint32_t column_family_id,
|
|
|
|
const Slice& beginKey, const Slice& endKey) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::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);
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::PutBlobIndexCF(uint32_t column_family_id,
|
|
|
|
const Slice& key, const Slice& value) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::Status(*status);
|
2017-03-07 07:13:53 +01:00
|
|
|
}
|
2018-03-03 00:33:08 +01:00
|
|
|
}
|
|
|
|
|
2018-07-07 02:17:36 +02:00
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::MarkBeginPrepare(bool unprepare) {
|
|
|
|
assert(!unprepare);
|
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();
|
|
|
|
std::unique_ptr<rocksdb::Status> status = rocksdb::RocksDBExceptionJni::toCppStatus(m_env, exception);
|
|
|
|
if (status == nullptr) {
|
|
|
|
// unkown status or exception occurred extracting status
|
|
|
|
m_env->ExceptionDescribe();
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) probably need a better error code here
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_env->ExceptionClear(); // clear the exception, as we have extracted the status
|
|
|
|
return rocksdb::Status(*status);
|
2017-03-07 07:13:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
return rocksdb::Status::OK();
|
|
|
|
}
|
2017-03-07 07:13:53 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::MarkEndPrepare(const Slice& xid) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::Status(*status);
|
2017-03-07 07:13:53 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::MarkNoop(bool empty_batch) {
|
|
|
|
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();
|
|
|
|
std::unique_ptr<rocksdb::Status> status = rocksdb::RocksDBExceptionJni::toCppStatus(m_env, exception);
|
|
|
|
if (status == nullptr) {
|
|
|
|
// unkown status or exception occurred extracting status
|
2017-02-28 01:26:12 +01:00
|
|
|
m_env->ExceptionDescribe();
|
2018-03-03 00:33:08 +01:00
|
|
|
return rocksdb::Status::OK(); // TODO(AR) probably need a better error code here
|
|
|
|
|
|
|
|
} else {
|
|
|
|
m_env->ExceptionClear(); // clear the exception, as we have extracted the status
|
|
|
|
return rocksdb::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-05 19:56:45 +01:00
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
return rocksdb::Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::MarkRollback(const Slice& xid) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::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
|
|
|
rocksdb::Status WriteBatchHandlerJniCallback::MarkCommit(const Slice& xid) {
|
|
|
|
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) {
|
|
|
|
return rocksdb::Status::OK(); // TODO(AR) what to do if there is an Exception but we don't know the rocksdb::Status?
|
|
|
|
} else {
|
|
|
|
return rocksdb::Status(*status);
|
2017-02-28 01:26:12 +01:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
2018-03-03 00:33:08 +01:00
|
|
|
std::unique_ptr<rocksdb::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);
|
|
|
|
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();
|
|
|
|
std::unique_ptr<rocksdb::Status> status = rocksdb::RocksDBExceptionJni::toCppStatus(m_env, exception);
|
|
|
|
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
|
|
|
|
return std::unique_ptr<rocksdb::Status>(new rocksdb::Status(rocksdb::Status::OK()));
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<rocksdb::Status> WriteBatchHandlerJniCallback::k_op(const Slice& key, std::function<void(jbyteArray)> kFn) {
|
|
|
|
const jbyteArray j_key = JniUtil::copyBytes(m_env, key);
|
|
|
|
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();
|
|
|
|
std::unique_ptr<rocksdb::Status> status = rocksdb::RocksDBExceptionJni::toCppStatus(m_env, exception);
|
|
|
|
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
|
|
|
|
return std::unique_ptr<rocksdb::Status>(new rocksdb::Status(rocksdb::Status::OK()));
|
2014-10-23 17:19:38 +02:00
|
|
|
}
|
|
|
|
} // namespace rocksdb
|