Add more options to backupable DB

main
Ankit Gupta 11 years ago
parent 036e323f7a
commit cf0b773a29
  1. 3
      java/Makefile
  2. 11
      java/org/rocksdb/BackupableDBOptions.java
  3. 28
      java/org/rocksdb/test/BackupableDBTest.java
  4. 13
      java/rocksjni/backupablejni.cc
  5. 67
      java/rocksjni/portal.h
  6. 1
      util/hash_cuckoo_rep.cc

@ -1,4 +1,5 @@
NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.BackupableDB org.rocksdb.BackupableDBOptions org.rocksdb.Statistics org.rocksdb.RocksIterator org.rocksdb.VectorMemTableConfig org.rocksdb.SkipListMemTableConfig org.rocksdb.HashLinkedListMemTableConfig org.rocksdb.HashSkipListMemTableConfig org.rocksdb.PlainTableConfig org.rocksdb.ReadOptions org.rocksdb.Filter org.rocksdb.BloomFilter NATIVE_JAVA_CLASSES = org.rocksdb.RocksDB org.rocksdb.Options org.rocksdb.WriteBatch org.rocksdb.WriteBatchInternal org.rocksdb.WriteBatchTest org.rocksdb.WriteOptions org.rocksdb.BackupableDB org.rocksdb.BackupableDBOptions org.rocksdb.Statistics org.rocksdb.RocksIterator org.rocksdb.VectorMemTableConfig org.rocksdb.SkipListMemTableConfig org.rocksdb.HashLinkedListMemTableConfig org.rocksdb.HashSkipListMemTableConfig org.rocksdb.PlainTableConfig org.rocksdb.ReadOptions org.rocksdb.Filter org.rocksdb.BloomFilter org.rocksdb.RestoreOptions org.rocksdb.RestoreBackupableDB
NATIVE_INCLUDE = ./include NATIVE_INCLUDE = ./include
ROCKSDB_JAR = rocksdbjni.jar ROCKSDB_JAR = rocksdbjni.jar

@ -13,9 +13,12 @@ package org.rocksdb;
* become out-of-scope to release the allocated memory in c++. * become out-of-scope to release the allocated memory in c++.
*/ */
public class BackupableDBOptions extends RocksObject { public class BackupableDBOptions extends RocksObject {
public BackupableDBOptions(String path) { public BackupableDBOptions(String path, boolean shareTableFiles, boolean sync,
boolean destroyOldData, boolean backupLogFiles, long backupRateLimit,
long restoreRateLimit) {
super(); super();
newBackupableDBOptions(path); newBackupableDBOptions(path, shareTableFiles, sync, destroyOldData,
backupLogFiles, backupRateLimit, restoreRateLimit);
} }
/** /**
@ -38,7 +41,9 @@ public class BackupableDBOptions extends RocksObject {
} }
} }
private native void newBackupableDBOptions(String path); private native void newBackupableDBOptions(String path,
boolean shareTableFiles, boolean sync, boolean destroyOldData,
boolean backupLogFiles, long backupRateLimit, long restoreRateLimit);
private native String backupDir(long handle); private native String backupDir(long handle);
private native void dispose(long handle); private native void dispose(long handle);
} }

@ -18,15 +18,35 @@ public class BackupableDBTest {
Options opt = new Options(); Options opt = new Options();
opt.setCreateIfMissing(true); opt.setCreateIfMissing(true);
BackupableDBOptions bopt = new BackupableDBOptions(backup_path); BackupableDBOptions bopt = new BackupableDBOptions(backup_path, false,
true, false, true, 0, 0);
BackupableDB bdb = null; BackupableDB bdb = null;
try { try {
bdb = BackupableDB.open(opt, bopt, db_path); bdb = BackupableDB.open(opt, bopt, db_path);
bdb.put("hello".getBytes(), "BackupableDB".getBytes());
bdb.put("abc".getBytes(), "def".getBytes());
bdb.put("ghi".getBytes(), "jkl".getBytes());
bdb.createNewBackup(true); bdb.createNewBackup(true);
byte[] value = bdb.get("hello".getBytes());
assert(new String(value).equals("BackupableDB")); // delete record after backup
bdb.remove("abc".getBytes());
byte[] value = bdb.get("abc".getBytes());
assert(value == null);
bdb.close();
// restore from backup
RestoreBackupableDB rdb = new RestoreBackupableDB(bopt);
rdb.restoreDBFromLatestBackup(db_path, db_path,
new RestoreOptions(false));
rdb.dispose();
// verify that backed up data contains deleted record
bdb = BackupableDB.open(opt, bopt, db_path);
value = bdb.get("abc".getBytes());
assert(new String(value).equals("def"));
System.out.println("Backup and restore test passed");
} catch (RocksDBException e) { } catch (RocksDBException e) {
System.err.format("[ERROR]: %s%n", e); System.err.format("[ERROR]: %s%n", e);
e.printStackTrace(); e.printStackTrace();

@ -4,7 +4,8 @@
// of patent rights can be found in the PATENTS file in the same directory. // 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 // This file implements the "bridge" between Java and C++ and enables
// calling c++ rocksdb::DB methods from Java side. // calling c++ rocksdb::BackupableDB and rocksdb::BackupableDBOptions methods
// from Java side.
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -51,9 +52,15 @@ void Java_org_rocksdb_BackupableDB_createNewBackup(
* Signature: (Ljava/lang/String;)V * Signature: (Ljava/lang/String;)V
*/ */
void Java_org_rocksdb_BackupableDBOptions_newBackupableDBOptions( void Java_org_rocksdb_BackupableDBOptions_newBackupableDBOptions(
JNIEnv* env, jobject jobj, jstring jpath) { 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) {
const char* cpath = env->GetStringUTFChars(jpath, 0); const char* cpath = env->GetStringUTFChars(jpath, 0);
auto bopt = new rocksdb::BackupableDBOptions(cpath);
auto bopt = new rocksdb::BackupableDBOptions(cpath, nullptr,
jshare_table_files, nullptr, jsync, jdestroy_old_data, jbackup_log_files,
jbackup_rate_limit, jrestore_rate_limit);
env->ReleaseStringUTFChars(jpath, cpath); env->ReleaseStringUTFChars(jpath, cpath);
rocksdb::BackupableDBOptionsJni::setHandle(env, jobj, bopt); rocksdb::BackupableDBOptionsJni::setHandle(env, jobj, bopt);

@ -217,6 +217,7 @@ class HistogramDataJni {
return mid; return mid;
} }
}; };
class BackupableDBOptionsJni { class BackupableDBOptionsJni {
public: public:
// Get the java class id of org.rocksdb.BackupableDBOptions. // Get the java class id of org.rocksdb.BackupableDBOptions.
@ -250,6 +251,72 @@ class BackupableDBOptionsJni {
} }
}; };
class RestoreOptionsJni {
public:
// Get the java class id of org.rocksdb.RestoreOptions.
static jclass getJClass(JNIEnv* env) {
static jclass jclazz = env->FindClass("org/rocksdb/RestoreOptions");
assert(jclazz != nullptr);
return jclazz;
}
// Get the field id of the member variable of org.rocksdb.RestoreOptions
// that stores the pointer to rocksdb::RestoreOptions
static jfieldID getHandleFieldID(JNIEnv* env) {
static jfieldID fid = env->GetFieldID(
getJClass(env), "nativeHandle_", "J");
assert(fid != nullptr);
return fid;
}
// Get the pointer to rocksdb::RestoreOptions
static rocksdb::RestoreOptions* getHandle(JNIEnv* env, jobject jobj) {
return reinterpret_cast<rocksdb::RestoreOptions*>(
env->GetLongField(jobj, getHandleFieldID(env)));
}
// Pass the rocksdb::RestoreOptions pointer to the java side.
static void setHandle(
JNIEnv* env, jobject jobj, rocksdb::RestoreOptions* op) {
env->SetLongField(
jobj, getHandleFieldID(env),
reinterpret_cast<jlong>(op));
}
};
class RestoreBackupableDBJni {
public:
// Get the java class id of org.rocksdb.RestoreBackupableDB.
static jclass getJClass(JNIEnv* env) {
static jclass jclazz = env->FindClass("org/rocksdb/RestoreBackupableDB");
assert(jclazz != nullptr);
return jclazz;
}
// Get the field id of the member variable of org.rocksdb.RestoreBackupableDB
// that stores the pointer to rocksdb::RestoreBackupableDB
static jfieldID getHandleFieldID(JNIEnv* env) {
static jfieldID fid = env->GetFieldID(
getJClass(env), "nativeHandle_", "J");
assert(fid != nullptr);
return fid;
}
// Get the pointer to rocksdb::RestoreBackupableDB
static rocksdb::RestoreBackupableDB* getHandle(JNIEnv* env, jobject jobj) {
return reinterpret_cast<rocksdb::RestoreBackupableDB*>(
env->GetLongField(jobj, getHandleFieldID(env)));
}
// Pass the rocksdb::RestoreBackupableDB pointer to the java side.
static void setHandle(
JNIEnv* env, jobject jobj, rocksdb::RestoreBackupableDB* op) {
env->SetLongField(
jobj, getHandleFieldID(env),
reinterpret_cast<jlong>(op));
}
};
class IteratorJni { class IteratorJni {
public: public:
// Get the java class id of org.rocksdb.Iteartor. // Get the java class id of org.rocksdb.Iteartor.

@ -1,4 +1,3 @@
// Copyright (c) 2014, Facebook, Inc. All rights reserved. // Copyright (c) 2014, Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the // 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 // LICENSE file in the root directory of this source tree. An additional grant

Loading…
Cancel
Save