2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2014-04-18 00:28:51 +00:00
|
|
|
// This source code is licensed under the BSD-style license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
//
|
|
|
|
// This file implements the "bridge" between Java and C++ and enables
|
2014-05-14 05:22:21 +00:00
|
|
|
// calling c++ rocksdb::BackupableDB and rocksdb::BackupableDBOptions methods
|
|
|
|
// from Java side.
|
2014-04-18 00:28:51 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <jni.h>
|
|
|
|
#include <string>
|
2014-10-26 22:23:06 +00:00
|
|
|
#include <vector>
|
2014-04-18 00:28:51 +00:00
|
|
|
|
|
|
|
#include "include/org_rocksdb_BackupableDBOptions.h"
|
|
|
|
#include "rocksjni/portal.h"
|
2014-07-23 18:15:14 +00:00
|
|
|
#include "rocksdb/utilities/backupable_db.h"
|
2014-04-18 00:28:51 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// BackupDBOptions
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: newBackupableDBOptions
|
2016-01-20 17:05:41 +00:00
|
|
|
* Signature: (Ljava/lang/String;)J
|
2014-04-18 00:28:51 +00:00
|
|
|
*/
|
2016-01-20 17:05:41 +00:00
|
|
|
jlong Java_org_rocksdb_BackupableDBOptions_newBackupableDBOptions(
|
|
|
|
JNIEnv* env, jclass jcls, jstring jpath) {
|
2017-02-28 00:26:12 +00:00
|
|
|
const char* cpath = env->GetStringUTFChars(jpath, nullptr);
|
|
|
|
if(cpath == nullptr) {
|
|
|
|
// exception thrown: OutOfMemoryError
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
auto* bopt = new rocksdb::BackupableDBOptions(cpath);
|
2014-04-18 00:28:51 +00:00
|
|
|
env->ReleaseStringUTFChars(jpath, cpath);
|
2016-01-20 17:05:41 +00:00
|
|
|
return reinterpret_cast<jlong>(bopt);
|
2014-04-18 00:28:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: backupDir
|
|
|
|
* Signature: (J)Ljava/lang/String;
|
|
|
|
*/
|
|
|
|
jstring Java_org_rocksdb_BackupableDBOptions_backupDir(
|
2014-11-07 13:38:21 +00:00
|
|
|
JNIEnv* env, jobject jopt, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-04-18 00:28:51 +00:00
|
|
|
return env->NewStringUTF(bopt->backup_dir.c_str());
|
|
|
|
}
|
|
|
|
|
2017-03-30 19:04:09 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setBackupEnv
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setBackupEnv(
|
|
|
|
JNIEnv* env, jobject jopt, jlong jhandle, jlong jrocks_env_handle) {
|
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
auto* rocks_env = reinterpret_cast<rocksdb::Env*>(jrocks_env_handle);
|
|
|
|
bopt->backup_env = rocks_env;
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:03:32 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setShareTableFiles
|
|
|
|
* Signature: (JZ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setShareTableFiles(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-15 22:03:32 +00:00
|
|
|
bopt->share_table_files = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: shareTableFiles
|
|
|
|
* Signature: (J)Z
|
|
|
|
*/
|
|
|
|
jboolean Java_org_rocksdb_BackupableDBOptions_shareTableFiles(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-15 22:03:32 +00:00
|
|
|
return bopt->share_table_files;
|
|
|
|
}
|
|
|
|
|
2017-03-30 19:04:09 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setInfoLog
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setInfoLog(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jlong jlogger_handle) {
|
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
auto* sptr_logger =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::LoggerJniCallback> *>(jhandle);
|
|
|
|
bopt->info_log = sptr_logger->get();
|
|
|
|
}
|
|
|
|
|
2014-11-15 22:03:32 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setSync
|
|
|
|
* Signature: (JZ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setSync(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-15 22:03:32 +00:00
|
|
|
bopt->sync = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: sync
|
|
|
|
* Signature: (J)Z
|
|
|
|
*/
|
|
|
|
jboolean Java_org_rocksdb_BackupableDBOptions_sync(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-15 22:03:32 +00:00
|
|
|
return bopt->sync;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-11-16 13:52:53 +00:00
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setDestroyOldData
|
|
|
|
* Signature: (JZ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setDestroyOldData(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
bopt->destroy_old_data = flag;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: destroyOldData
|
|
|
|
* Signature: (J)Z
|
|
|
|
*/
|
|
|
|
jboolean Java_org_rocksdb_BackupableDBOptions_destroyOldData(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
return bopt->destroy_old_data;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setBackupLogFiles
|
|
|
|
* Signature: (JZ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setBackupLogFiles(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
bopt->backup_log_files = flag;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: backupLogFiles
|
|
|
|
* Signature: (J)Z
|
|
|
|
*/
|
|
|
|
jboolean Java_org_rocksdb_BackupableDBOptions_backupLogFiles(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
return bopt->backup_log_files;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setBackupRateLimit
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setBackupRateLimit(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jlong jbackup_rate_limit) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
bopt->backup_rate_limit = jbackup_rate_limit;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: backupRateLimit
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_BackupableDBOptions_backupRateLimit(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
return bopt->backup_rate_limit;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2017-03-30 19:04:09 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setBackupRateLimiter
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setBackupRateLimiter(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jlong jrate_limiter_handle) {
|
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
auto* sptr_rate_limiter =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(jrate_limiter_handle);
|
|
|
|
bopt->backup_rate_limiter = *sptr_rate_limiter;
|
|
|
|
}
|
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setRestoreRateLimit
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setRestoreRateLimit(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jlong jrestore_rate_limit) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
bopt->restore_rate_limit = jrestore_rate_limit;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: restoreRateLimit
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_BackupableDBOptions_restoreRateLimit(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
return bopt->restore_rate_limit;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2017-03-30 19:04:09 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setRestoreRateLimiter
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setRestoreRateLimiter(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jlong jrate_limiter_handle) {
|
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
auto* sptr_rate_limiter =
|
|
|
|
reinterpret_cast<std::shared_ptr<rocksdb::RateLimiter> *>(jrate_limiter_handle);
|
|
|
|
bopt->restore_rate_limiter = *sptr_rate_limiter;
|
|
|
|
}
|
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setShareFilesWithChecksum
|
|
|
|
* Signature: (JZ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setShareFilesWithChecksum(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
bopt->share_files_with_checksum = flag;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2014-11-16 13:52:53 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: shareFilesWithChecksum
|
|
|
|
* Signature: (J)Z
|
|
|
|
*/
|
|
|
|
jboolean Java_org_rocksdb_BackupableDBOptions_shareFilesWithChecksum(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
2014-11-16 13:52:53 +00:00
|
|
|
return bopt->share_files_with_checksum;
|
|
|
|
}
|
2014-11-15 22:03:32 +00:00
|
|
|
|
2017-03-30 19:04:09 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setMaxBackgroundOperations
|
|
|
|
* Signature: (JI)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setMaxBackgroundOperations(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jint max_background_operations) {
|
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
bopt->max_background_operations =
|
|
|
|
static_cast<int>(max_background_operations);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: maxBackgroundOperations
|
|
|
|
* Signature: (J)I
|
|
|
|
*/
|
|
|
|
jint Java_org_rocksdb_BackupableDBOptions_maxBackgroundOperations(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
return static_cast<jint>(bopt->max_background_operations);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: setCallbackTriggerIntervalSize
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_setCallbackTriggerIntervalSize(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle,
|
|
|
|
jlong jcallback_trigger_interval_size) {
|
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
bopt->callback_trigger_interval_size =
|
|
|
|
static_cast<uint64_t>(jcallback_trigger_interval_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: callbackTriggerIntervalSize
|
|
|
|
* Signature: (J)J
|
|
|
|
*/
|
|
|
|
jlong Java_org_rocksdb_BackupableDBOptions_callbackTriggerIntervalSize(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
return static_cast<jlong>(bopt->callback_trigger_interval_size);
|
|
|
|
}
|
|
|
|
|
2014-04-18 00:28:51 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
[Java] Generalize dis-own native handle and refine dispose framework.
Summary:
1. Move disOwnNativeHandle() function from RocksDB to RocksObject
to allow other RocksObject to use disOwnNativeHandle() when its
ownership of native handle has been transferred.
2. RocksObject now has an abstract implementation of dispose(),
which does the following two things. First, it checks whether
both isOwningNativeHandle() and isInitialized() return true.
If so, it will call the protected abstract function dispose0(),
which all the subclasses of RocksObject should implement. Second,
it sets nativeHandle_ = 0. This redesign ensure all subclasses
of RocksObject have the same dispose behavior.
3. All subclasses of RocksObject now should implement dispose0()
instead of dispose(), and dispose0() will be called only when
isInitialized() returns true.
Test Plan:
make rocksdbjava
make jtest
Reviewers: dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett, haobo
Reviewed By: haobo
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D18801
2014-05-29 01:16:29 +00:00
|
|
|
* Method: disposeInternal
|
2014-04-18 00:28:51 +00:00
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
[Java] Generalize dis-own native handle and refine dispose framework.
Summary:
1. Move disOwnNativeHandle() function from RocksDB to RocksObject
to allow other RocksObject to use disOwnNativeHandle() when its
ownership of native handle has been transferred.
2. RocksObject now has an abstract implementation of dispose(),
which does the following two things. First, it checks whether
both isOwningNativeHandle() and isInitialized() return true.
If so, it will call the protected abstract function dispose0(),
which all the subclasses of RocksObject should implement. Second,
it sets nativeHandle_ = 0. This redesign ensure all subclasses
of RocksObject have the same dispose behavior.
3. All subclasses of RocksObject now should implement dispose0()
instead of dispose(), and dispose0() will be called only when
isInitialized() returns true.
Test Plan:
make rocksdbjava
make jtest
Reviewers: dhruba, sdong, ankgup87, rsumbaly, swapnilghike, zzbennett, haobo
Reviewed By: haobo
Subscribers: leveldb
Differential Revision: https://reviews.facebook.net/D18801
2014-05-29 01:16:29 +00:00
|
|
|
void Java_org_rocksdb_BackupableDBOptions_disposeInternal(
|
2014-04-18 00:28:51 +00:00
|
|
|
JNIEnv* env, jobject jopt, jlong jhandle) {
|
2017-02-28 00:26:12 +00:00
|
|
|
auto* bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
assert(bopt != nullptr);
|
2014-04-18 00:28:51 +00:00
|
|
|
delete bopt;
|
|
|
|
}
|