2018-04-07 04:22:37 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
|
|
// 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).
|
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ and enables
|
2020-02-20 20:07:53 +00:00
|
|
|
// calling C++ ROCKSDB_NAMESPACE::SstFileManager methods
|
2018-04-07 04:22:37 +00:00
|
|
|
// from Java side.
|
|
|
|
|
2022-03-01 17:02:15 +00:00
|
|
|
#include "rocksdb/sst_file_manager.h"
|
|
|
|
|
2018-04-07 04:22:37 +00:00
|
|
|
#include <jni.h>
|
2022-03-01 17:02:15 +00:00
|
|
|
|
2018-04-07 04:22:37 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include "include/org_rocksdb_SstFileManager.h"
|
2022-03-01 17:02:15 +00:00
|
|
|
#include "rocksjni/cplusplus_to_java_convert.h"
|
2018-04-07 04:22:37 +00:00
|
|
|
#include "rocksjni/portal.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: newSstFileManager
|
|
|
|
* Signature: (JJJDJ)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_SstFileManager_newSstFileManager(
|
2018-04-13 00:55:14 +00:00
|
|
|
JNIEnv* jnienv, jclass /*jcls*/, jlong jenv_handle, jlong jlogger_handle,
|
2018-04-07 04:22:37 +00:00
|
|
|
jlong jrate_bytes, jdouble jmax_trash_db_ratio,
|
|
|
|
jlong jmax_delete_chunk_bytes) {
|
2020-02-20 20:07:53 +00:00
|
|
|
auto* env = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jenv_handle);
|
|
|
|
ROCKSDB_NAMESPACE::Status s;
|
|
|
|
ROCKSDB_NAMESPACE::SstFileManager* sst_file_manager = nullptr;
|
2018-04-07 04:22:37 +00:00
|
|
|
|
|
|
|
if (jlogger_handle != 0) {
|
|
|
|
auto* sptr_logger =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::Logger>*>(
|
|
|
|
jlogger_handle);
|
|
|
|
sst_file_manager = ROCKSDB_NAMESPACE::NewSstFileManager(
|
2018-04-13 00:55:14 +00:00
|
|
|
env, *sptr_logger, "", jrate_bytes, true, &s, jmax_trash_db_ratio,
|
2018-04-07 04:22:37 +00:00
|
|
|
jmax_delete_chunk_bytes);
|
|
|
|
} else {
|
2020-02-20 20:07:53 +00:00
|
|
|
sst_file_manager = ROCKSDB_NAMESPACE::NewSstFileManager(
|
|
|
|
env, nullptr, "", jrate_bytes, true, &s, jmax_trash_db_ratio,
|
|
|
|
jmax_delete_chunk_bytes);
|
2018-04-07 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
if (sst_file_manager != nullptr) {
|
2018-04-13 00:55:14 +00:00
|
|
|
delete sst_file_manager;
|
2018-04-07 04:22:37 +00:00
|
|
|
}
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(jnienv, s);
|
2018-04-07 04:22:37 +00:00
|
|
|
}
|
2018-04-13 00:55:14 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
new std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>(sst_file_manager);
|
2018-04-07 04:22:37 +00:00
|
|
|
|
2022-03-01 17:02:15 +00:00
|
|
|
return GET_CPLUSPLUS_POINTER(sptr_sst_file_manager);
|
2018-04-07 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: setMaxAllowedSpaceUsage
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_SstFileManager_setMaxAllowedSpaceUsage(
|
2018-04-13 00:55:14 +00:00
|
|
|
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
|
|
|
|
jlong jmax_allowed_space) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
sptr_sst_file_manager->get()->SetMaxAllowedSpaceUsage(jmax_allowed_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: setCompactionBufferSize
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_SstFileManager_setCompactionBufferSize(
|
2018-04-13 00:55:14 +00:00
|
|
|
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle,
|
|
|
|
jlong jcompaction_buffer_size) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-13 00:55:14 +00:00
|
|
|
sptr_sst_file_manager->get()->SetCompactionBufferSize(
|
|
|
|
jcompaction_buffer_size);
|
2018-04-07 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: isMaxAllowedSpaceReached
|
|
|
|
* Signature: (J)Z
|
|
|
|
*/
|
|
|
|
jboolean Java_org_rocksdb_SstFileManager_isMaxAllowedSpaceReached(
|
2018-04-13 00:55:14 +00:00
|
|
|
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
return sptr_sst_file_manager->get()->IsMaxAllowedSpaceReached();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: isMaxAllowedSpaceReachedIncludingCompactions
|
|
|
|
* Signature: (J)Z
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
jboolean
|
|
|
|
Java_org_rocksdb_SstFileManager_isMaxAllowedSpaceReachedIncludingCompactions(
|
|
|
|
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-13 00:55:14 +00:00
|
|
|
return sptr_sst_file_manager->get()
|
|
|
|
->IsMaxAllowedSpaceReachedIncludingCompactions();
|
2018-04-07 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: getTotalSize
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
jlong Java_org_rocksdb_SstFileManager_getTotalSize(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
return sptr_sst_file_manager->get()->GetTotalSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: getTrackedFiles
|
|
|
|
* Signature: (J)Ljava/util/Map;
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
jobject Java_org_rocksdb_SstFileManager_getTrackedFiles(JNIEnv* env,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
auto tracked_files = sptr_sst_file_manager->get()->GetTrackedFiles();
|
2018-04-13 00:55:14 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
// TODO(AR) could refactor to share code with
|
|
|
|
// ROCKSDB_NAMESPACE::HashMapJni::fromCppMap(env, tracked_files);
|
2019-02-22 22:36:38 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
const jobject jtracked_files = ROCKSDB_NAMESPACE::HashMapJni::construct(
|
2018-04-13 00:55:14 +00:00
|
|
|
env, static_cast<uint32_t>(tracked_files.size()));
|
2018-04-07 04:22:37 +00:00
|
|
|
if (jtracked_files == nullptr) {
|
2018-04-13 00:55:14 +00:00
|
|
|
// exception occurred
|
|
|
|
return nullptr;
|
2018-04-07 04:22:37 +00:00
|
|
|
}
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
const ROCKSDB_NAMESPACE::HashMapJni::FnMapKV<const std::string,
|
|
|
|
const uint64_t, jobject, jobject>
|
2018-04-13 00:55:14 +00:00
|
|
|
fn_map_kv =
|
2018-07-09 22:17:38 +00:00
|
|
|
[env](const std::pair<const std::string, const uint64_t>& pair) {
|
2018-04-13 00:55:14 +00:00
|
|
|
const jstring jtracked_file_path =
|
|
|
|
env->NewStringUTF(pair.first.c_str());
|
|
|
|
if (jtracked_file_path == nullptr) {
|
2018-04-07 04:22:37 +00:00
|
|
|
// an error occurred
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
2018-04-13 00:55:14 +00:00
|
|
|
}
|
|
|
|
const jobject jtracked_file_size =
|
2020-02-20 20:07:53 +00:00
|
|
|
ROCKSDB_NAMESPACE::LongJni::valueOf(env, pair.second);
|
2018-04-13 00:55:14 +00:00
|
|
|
if (jtracked_file_size == nullptr) {
|
|
|
|
// an error occurred
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(nullptr);
|
|
|
|
}
|
|
|
|
return std::unique_ptr<std::pair<jobject, jobject>>(
|
|
|
|
new std::pair<jobject, jobject>(jtracked_file_path,
|
|
|
|
jtracked_file_size));
|
|
|
|
};
|
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
if (!ROCKSDB_NAMESPACE::HashMapJni::putAll(env, jtracked_files,
|
|
|
|
tracked_files.begin(),
|
|
|
|
tracked_files.end(), fn_map_kv)) {
|
2018-04-07 04:22:37 +00:00
|
|
|
// exception occcurred
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return jtracked_files;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: getDeleteRateBytesPerSecond
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_SstFileManager_getDeleteRateBytesPerSecond(
|
2018-04-13 00:55:14 +00:00
|
|
|
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
return sptr_sst_file_manager->get()->GetDeleteRateBytesPerSecond();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: setDeleteRateBytesPerSecond
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_SstFileManager_setDeleteRateBytesPerSecond(
|
2018-04-13 00:55:14 +00:00
|
|
|
JNIEnv* /*env*/, jobject /*jobj*/, jlong jhandle, jlong jdelete_rate) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
sptr_sst_file_manager->get()->SetDeleteRateBytesPerSecond(jdelete_rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: getMaxTrashDBRatio
|
|
|
|
* Signature: (J)D
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
jdouble Java_org_rocksdb_SstFileManager_getMaxTrashDBRatio(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
return sptr_sst_file_manager->get()->GetMaxTrashDBRatio();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: setMaxTrashDBRatio
|
|
|
|
* Signature: (JD)V
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
void Java_org_rocksdb_SstFileManager_setMaxTrashDBRatio(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle,
|
|
|
|
jdouble jratio) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
sptr_sst_file_manager->get()->SetMaxTrashDBRatio(jratio);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_SstFileManager
|
|
|
|
* Method: disposeInternal
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2018-04-13 00:55:14 +00:00
|
|
|
void Java_org_rocksdb_SstFileManager_disposeInternal(JNIEnv* /*env*/,
|
|
|
|
jobject /*jobj*/,
|
|
|
|
jlong jhandle) {
|
2018-04-07 04:22:37 +00:00
|
|
|
auto* sptr_sst_file_manager =
|
2020-02-20 20:07:53 +00:00
|
|
|
reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::SstFileManager>*>(
|
|
|
|
jhandle);
|
2018-04-07 04:22:37 +00:00
|
|
|
delete sptr_sst_file_manager;
|
|
|
|
}
|