2016-02-10 00:12:00 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2014-05-14 07:20:58 +02: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-19 07:40:48 +02:00
|
|
|
// calling c++ rocksdb::RestoreBackupableDB and rocksdb::RestoreOptions methods
|
2014-05-14 07:20:58 +02:00
|
|
|
// from Java side.
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <jni.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "include/org_rocksdb_RestoreOptions.h"
|
|
|
|
#include "include/org_rocksdb_RestoreBackupableDB.h"
|
|
|
|
#include "rocksjni/portal.h"
|
2014-07-23 20:15:14 +02:00
|
|
|
#include "rocksdb/utilities/backupable_db.h"
|
2014-05-14 07:20:58 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreOptions
|
|
|
|
* Method: newRestoreOptions
|
2014-05-19 07:40:48 +02:00
|
|
|
* Signature: (Z)J
|
2014-05-14 07:20:58 +02:00
|
|
|
*/
|
2014-05-19 07:40:48 +02:00
|
|
|
jlong Java_org_rocksdb_RestoreOptions_newRestoreOptions(JNIEnv* env,
|
2016-01-20 18:05:41 +01:00
|
|
|
jclass jcls, jboolean keep_log_files) {
|
2014-05-14 07:20:58 +02:00
|
|
|
auto ropt = new rocksdb::RestoreOptions(keep_log_files);
|
2014-05-19 07:40:48 +02:00
|
|
|
return reinterpret_cast<jlong>(ropt);
|
2014-05-14 07:20:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreOptions
|
2016-01-20 18:05:41 +01:00
|
|
|
* Method: disposeInternal
|
2014-05-14 07:20:58 +02:00
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2016-01-20 18:05:41 +01:00
|
|
|
void Java_org_rocksdb_RestoreOptions_disposeInternal(JNIEnv* env, jobject jobj,
|
2014-05-14 07:20:58 +02:00
|
|
|
jlong jhandle) {
|
|
|
|
auto ropt = reinterpret_cast<rocksdb::RestoreOptions*>(jhandle);
|
|
|
|
assert(ropt);
|
|
|
|
delete ropt;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
|
|
|
* Method: newRestoreBackupableDB
|
2014-05-19 07:40:48 +02:00
|
|
|
* Signature: (J)J
|
2014-05-14 07:20:58 +02:00
|
|
|
*/
|
2014-05-19 07:40:48 +02:00
|
|
|
jlong Java_org_rocksdb_RestoreBackupableDB_newRestoreBackupableDB(JNIEnv* env,
|
2016-01-20 18:05:41 +01:00
|
|
|
jclass jcls, jlong jopt_handle) {
|
|
|
|
auto* opt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jopt_handle);
|
2014-05-14 07:20:58 +02:00
|
|
|
auto rdb = new rocksdb::RestoreBackupableDB(rocksdb::Env::Default(), *opt);
|
2014-05-19 07:40:48 +02:00
|
|
|
return reinterpret_cast<jlong>(rdb);
|
2014-05-14 07:20:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
|
|
|
* Method: restoreDBFromBackup0
|
|
|
|
* Signature: (JJLjava/lang/String;Ljava/lang/String;J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RestoreBackupableDB_restoreDBFromBackup0(JNIEnv* env,
|
|
|
|
jobject jobj, jlong jhandle, jlong jbackup_id, jstring jdb_dir,
|
|
|
|
jstring jwal_dir, jlong jopt_handle) {
|
|
|
|
auto opt = reinterpret_cast<rocksdb::RestoreOptions*>(jopt_handle);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-05-14 07:20:58 +02:00
|
|
|
const char* cdb_dir = env->GetStringUTFChars(jdb_dir, 0);
|
|
|
|
const char* cwal_dir = env->GetStringUTFChars(jwal_dir, 0);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-05-14 07:20:58 +02:00
|
|
|
auto rdb = reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle);
|
2014-11-11 22:47:22 +01:00
|
|
|
rocksdb::Status s = rdb->RestoreDBFromBackup(
|
|
|
|
static_cast<rocksdb::BackupID>(jbackup_id), cdb_dir, cwal_dir, *opt);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-05-14 07:20:58 +02:00
|
|
|
env->ReleaseStringUTFChars(jdb_dir, cdb_dir);
|
|
|
|
env->ReleaseStringUTFChars(jwal_dir, cwal_dir);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-10-09 23:16:41 +02:00
|
|
|
if (!s.ok()) {
|
2014-05-14 07:20:58 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
|
|
|
* Method: restoreDBFromLatestBackup0
|
|
|
|
* Signature: (JLjava/lang/String;Ljava/lang/String;J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RestoreBackupableDB_restoreDBFromLatestBackup0(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle, jstring jdb_dir, jstring jwal_dir,
|
|
|
|
jlong jopt_handle) {
|
|
|
|
auto opt = reinterpret_cast<rocksdb::RestoreOptions*>(jopt_handle);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-05-14 07:20:58 +02:00
|
|
|
const char* cdb_dir = env->GetStringUTFChars(jdb_dir, 0);
|
|
|
|
const char* cwal_dir = env->GetStringUTFChars(jwal_dir, 0);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-05-14 07:20:58 +02:00
|
|
|
auto rdb = reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle);
|
|
|
|
rocksdb::Status s =
|
|
|
|
rdb->RestoreDBFromLatestBackup(cdb_dir, cwal_dir, *opt);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-05-14 07:20:58 +02:00
|
|
|
env->ReleaseStringUTFChars(jdb_dir, cdb_dir);
|
|
|
|
env->ReleaseStringUTFChars(jwal_dir, cwal_dir);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-10-09 23:16:41 +02:00
|
|
|
if (!s.ok()) {
|
2014-05-14 07:20:58 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
|
|
|
* Method: purgeOldBackups0
|
|
|
|
* Signature: (JI)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RestoreBackupableDB_purgeOldBackups0(JNIEnv* env,
|
|
|
|
jobject jobj, jlong jhandle, jint jnum_backups_to_keep) {
|
|
|
|
auto rdb = reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle);
|
|
|
|
rocksdb::Status s = rdb->PurgeOldBackups(jnum_backups_to_keep);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-10-09 23:16:41 +02:00
|
|
|
if (!s.ok()) {
|
2014-05-14 07:20:58 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
|
|
|
* Method: deleteBackup0
|
2014-10-28 18:42:30 +01:00
|
|
|
* Signature: (JI)V
|
2014-05-14 07:20:58 +02:00
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RestoreBackupableDB_deleteBackup0(JNIEnv* env,
|
2014-10-28 18:42:30 +01:00
|
|
|
jobject jobj, jlong jhandle, jint jbackup_id) {
|
2014-05-14 07:20:58 +02:00
|
|
|
auto rdb = reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle);
|
|
|
|
rocksdb::Status s = rdb->DeleteBackup(jbackup_id);
|
2014-05-19 07:40:48 +02:00
|
|
|
|
2014-10-09 23:16:41 +02:00
|
|
|
if (!s.ok()) {
|
2014-05-14 07:20:58 +02:00
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-26 23:23:06 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
|
|
|
* Method: getBackupInfo
|
|
|
|
* Signature: (J)Ljava/util/List;
|
|
|
|
*/
|
|
|
|
jobject Java_org_rocksdb_RestoreBackupableDB_getBackupInfo(
|
|
|
|
JNIEnv* env, jobject jbdb, jlong jhandle) {
|
|
|
|
std::vector<rocksdb::BackupInfo> backup_infos;
|
|
|
|
reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle)->
|
|
|
|
GetBackupInfo(&backup_infos);
|
|
|
|
return rocksdb::BackupInfoListJni::getBackupInfo(env,
|
|
|
|
backup_infos);
|
|
|
|
}
|
|
|
|
|
2014-11-15 23:42:03 +01:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
|
|
|
* Method: getCorruptedBackups
|
2014-11-20 22:47:48 +01:00
|
|
|
* Signature: (J)[I;
|
2014-11-15 23:42:03 +01:00
|
|
|
*/
|
2014-11-20 22:47:48 +01:00
|
|
|
jintArray Java_org_rocksdb_RestoreBackupableDB_getCorruptedBackups(
|
2014-11-15 23:42:03 +01:00
|
|
|
JNIEnv* env, jobject jbdb, jlong jhandle) {
|
|
|
|
std::vector<rocksdb::BackupID> backup_ids;
|
|
|
|
reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle)->
|
|
|
|
GetCorruptedBackups(&backup_ids);
|
2014-11-20 22:47:48 +01:00
|
|
|
// store backupids in int array
|
2016-01-28 15:44:31 +01:00
|
|
|
std::vector<jint> int_backup_ids(backup_ids.begin(), backup_ids.end());
|
2014-11-20 22:47:48 +01:00
|
|
|
// Store ints in java array
|
|
|
|
jintArray ret_backup_ids;
|
2014-11-26 20:51:50 +01:00
|
|
|
// Its ok to loose precision here (64->32)
|
2016-01-28 15:44:31 +01:00
|
|
|
jsize ret_backup_ids_size = static_cast<jsize>(backup_ids.size());
|
2014-11-26 20:51:50 +01:00
|
|
|
ret_backup_ids = env->NewIntArray(ret_backup_ids_size);
|
|
|
|
env->SetIntArrayRegion(ret_backup_ids, 0, ret_backup_ids_size,
|
2016-01-28 15:44:31 +01:00
|
|
|
int_backup_ids.data());
|
2014-11-20 22:47:48 +01:00
|
|
|
return ret_backup_ids;
|
2014-11-15 23:42:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
|
|
|
* Method: garbageCollect
|
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
|
|
|
void Java_org_rocksdb_RestoreBackupableDB_garbageCollect(
|
|
|
|
JNIEnv* env, jobject jobj, jlong jhandle) {
|
|
|
|
auto db = reinterpret_cast<rocksdb::RestoreBackupableDB*>(
|
|
|
|
jhandle);
|
|
|
|
rocksdb::Status s = db->GarbageCollect();
|
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-14 07:20:58 +02:00
|
|
|
/*
|
|
|
|
* Class: org_rocksdb_RestoreBackupableDB
|
2016-01-20 18:05:41 +01:00
|
|
|
* Method: disposeInternal
|
2014-05-14 07:20:58 +02:00
|
|
|
* Signature: (J)V
|
|
|
|
*/
|
2016-01-20 18:05:41 +01:00
|
|
|
void Java_org_rocksdb_RestoreBackupableDB_disposeInternal(JNIEnv* env,
|
|
|
|
jobject jobj, jlong jhandle) {
|
2014-05-14 07:20:58 +02:00
|
|
|
auto ropt = reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle);
|
|
|
|
assert(ropt);
|
|
|
|
delete ropt;
|
2014-05-14 07:34:29 +02:00
|
|
|
}
|