2014-04-18 00:28:51 +00:00
|
|
|
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
|
|
|
// 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_BackupableDB.h"
|
|
|
|
#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
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDB
|
|
|
|
* Method: open
|
|
|
|
* Signature: (JJ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDB_open(
|
|
|
|
JNIEnv* env, jobject jbdb, jlong jdb_handle, jlong jopt_handle) {
|
|
|
|
auto db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
|
|
|
|
auto opt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jopt_handle);
|
|
|
|
auto bdb = new rocksdb::BackupableDB(db, *opt);
|
|
|
|
|
|
|
|
// as BackupableDB extends RocksDB on the java side, we can reuse
|
|
|
|
// the RocksDB portal here.
|
|
|
|
rocksdb::RocksDBJni::setHandle(env, jbdb, bdb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDB
|
|
|
|
* Method: createNewBackup
|
|
|
|
* Signature: (JZ)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDB_createNewBackup(
|
|
|
|
JNIEnv* env, jobject jbdb, jlong jhandle, jboolean jflag) {
|
2014-08-14 17:58:09 +00:00
|
|
|
rocksdb::Status s =
|
|
|
|
reinterpret_cast<rocksdb::BackupableDB*>(jhandle)->CreateNewBackup(jflag);
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDB
|
|
|
|
* Method: purgeOldBackups
|
|
|
|
* Signature: (JI)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDB_purgeOldBackups(
|
2014-10-26 22:23:06 +00:00
|
|
|
JNIEnv* env, jobject jbdb, jlong jhandle, jint jnumBackupsToKeep) {
|
2014-08-14 17:58:09 +00:00
|
|
|
rocksdb::Status s =
|
|
|
|
reinterpret_cast<rocksdb::BackupableDB*>(jhandle)->
|
|
|
|
PurgeOldBackups(jnumBackupsToKeep);
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
2014-04-18 00:28:51 +00:00
|
|
|
}
|
|
|
|
|
2014-10-26 22:23:06 +00:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDB
|
|
|
|
* Method: deleteBackup0
|
2014-10-28 17:42:30 +00:00
|
|
|
* Signature: (JI)V
|
2014-10-26 22:23:06 +00:00
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDB_deleteBackup0(JNIEnv* env,
|
2014-10-28 17:42:30 +00:00
|
|
|
jobject jobj, jlong jhandle, jint jbackup_id) {
|
2014-10-26 22:23:06 +00:00
|
|
|
auto rdb = reinterpret_cast<rocksdb::BackupableDB*>(jhandle);
|
|
|
|
rocksdb::Status s = rdb->DeleteBackup(jbackup_id);
|
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDB
|
|
|
|
* Method: getBackupInfo
|
|
|
|
* Signature: (J)Ljava/util/List;
|
|
|
|
*/
|
|
|
|
jobject Java_org_rocksdb_BackupableDB_getBackupInfo(
|
|
|
|
JNIEnv* env, jobject jbdb, jlong jhandle) {
|
|
|
|
std::vector<rocksdb::BackupInfo> backup_infos;
|
|
|
|
reinterpret_cast<rocksdb::BackupableDB*>(jhandle)->
|
|
|
|
GetBackupInfo(&backup_infos);
|
|
|
|
return rocksdb::BackupInfoListJni::getBackupInfo(env,
|
|
|
|
backup_infos);
|
|
|
|
}
|
|
|
|
|
2014-04-18 00:28:51 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
// BackupDBOptions
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_BackupableDBOptions
|
|
|
|
* Method: newBackupableDBOptions
|
|
|
|
* Signature: (Ljava/lang/String;)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_BackupableDBOptions_newBackupableDBOptions(
|
2014-05-14 05:22:21 +00:00
|
|
|
JNIEnv* env, jobject jobj, jstring jpath, jboolean jshare_table_files,
|
|
|
|
jboolean jsync, jboolean jdestroy_old_data, jboolean jbackup_log_files,
|
|
|
|
jlong jbackup_rate_limit, jlong jrestore_rate_limit) {
|
2014-05-21 14:54:22 +00:00
|
|
|
jbackup_rate_limit = (jbackup_rate_limit <= 0) ? 0 : jbackup_rate_limit;
|
|
|
|
jrestore_rate_limit = (jrestore_rate_limit <= 0) ? 0 : jrestore_rate_limit;
|
|
|
|
|
2014-04-18 00:28:51 +00:00
|
|
|
const char* cpath = env->GetStringUTFChars(jpath, 0);
|
2014-05-14 05:22:21 +00:00
|
|
|
|
|
|
|
auto bopt = new rocksdb::BackupableDBOptions(cpath, nullptr,
|
|
|
|
jshare_table_files, nullptr, jsync, jdestroy_old_data, jbackup_log_files,
|
|
|
|
jbackup_rate_limit, jrestore_rate_limit);
|
|
|
|
|
2014-04-18 00:28:51 +00:00
|
|
|
env->ReleaseStringUTFChars(jpath, cpath);
|
|
|
|
|
|
|
|
rocksdb::BackupableDBOptionsJni::setHandle(env, jobj, bopt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
2014-04-18 00:28:51 +00:00
|
|
|
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
return env->NewStringUTF(bopt->backup_dir.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
|
|
|
assert(bopt);
|
|
|
|
delete bopt;
|
|
|
|
|
|
|
|
rocksdb::BackupableDBOptionsJni::setHandle(env, jopt, nullptr);
|
|
|
|
}
|