Removing code from portal.h for setting handle of RestoreOptions and RestoreBackupableDB

main
Ankit Gupta 11 years ago
parent 29eef1f87d
commit e87973cde1
  1. 5
      java/org/rocksdb/RestoreBackupableDB.java
  2. 5
      java/org/rocksdb/RestoreOptions.java
  3. 4
      java/org/rocksdb/test/BackupableDBTest.java
  4. 66
      java/rocksjni/portal.h
  5. 16
      java/rocksjni/restorejni.cc

@ -16,7 +16,7 @@ package org.rocksdb;
public class RestoreBackupableDB extends RocksObject {
public RestoreBackupableDB(BackupableDBOptions options) {
super();
newRestoreBackupableDB(options.nativeHandle_);
nativeHandle_ = newRestoreBackupableDB(options.nativeHandle_);
}
/**
@ -71,10 +71,11 @@ public class RestoreBackupableDB extends RocksObject {
@Override public synchronized void dispose() {
if (isInitialized()) {
dispose(nativeHandle_);
nativeHandle_ = 0;
}
}
private native void newRestoreBackupableDB(long options);
private native long newRestoreBackupableDB(long options);
private native void restoreDBFromBackup0(long nativeHandle, long backupId,
String dbDir, String walDir, long restoreOptions) throws RocksDBException;
private native void restoreDBFromLatestBackup0(long nativeHandle,

@ -20,7 +20,7 @@ package org.rocksdb;
public class RestoreOptions extends RocksObject {
public RestoreOptions(boolean keepLogFiles) {
super();
newRestoreOptions(keepLogFiles);
nativeHandle_ = newRestoreOptions(keepLogFiles);
}
/**
@ -30,9 +30,10 @@ public class RestoreOptions extends RocksObject {
@Override public synchronized void dispose() {
if (isInitialized()) {
dispose(nativeHandle_);
nativeHandle_ = 0;
}
}
private native void newRestoreOptions(boolean keepLogFiles);
private native long newRestoreOptions(boolean keepLogFiles);
private native void dispose(long handle);
}

@ -36,10 +36,12 @@ public class BackupableDBTest {
bdb.close();
// restore from backup
RestoreOptions ropt = new RestoreOptions(false);
RestoreBackupableDB rdb = new RestoreBackupableDB(bopt);
rdb.restoreDBFromLatestBackup(db_path, db_path,
new RestoreOptions(false));
ropt);
rdb.dispose();
ropt.dispose();
// verify that backed up data contains deleted record
bdb = BackupableDB.open(opt, bopt, db_path);

@ -251,72 +251,6 @@ 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 {
public:
// Get the java class id of org.rocksdb.Iteartor.

@ -20,12 +20,12 @@
/*
* Class: org_rocksdb_RestoreOptions
* Method: newRestoreOptions
* Signature: (Z)V
* Signature: (Z)J
*/
void Java_org_rocksdb_RestoreOptions_newRestoreOptions(JNIEnv* env,
jlong Java_org_rocksdb_RestoreOptions_newRestoreOptions(JNIEnv* env,
jobject jobj, jboolean keep_log_files) {
auto ropt = new rocksdb::RestoreOptions(keep_log_files);
rocksdb::RestoreOptionsJni::setHandle(env, jobj, ropt);
return reinterpret_cast<jlong>(ropt);
}
/*
@ -38,20 +38,18 @@ void Java_org_rocksdb_RestoreOptions_dispose(JNIEnv* env, jobject jobj,
auto ropt = reinterpret_cast<rocksdb::RestoreOptions*>(jhandle);
assert(ropt);
delete ropt;
rocksdb::RestoreOptionsJni::setHandle(env, jobj, nullptr);
}
/*
* Class: org_rocksdb_RestoreBackupableDB
* Method: newRestoreBackupableDB
* Signature: (J)V
* Signature: (J)J
*/
void Java_org_rocksdb_RestoreBackupableDB_newRestoreBackupableDB(JNIEnv* env,
jlong Java_org_rocksdb_RestoreBackupableDB_newRestoreBackupableDB(JNIEnv* env,
jobject jobj, jlong jopt_handle) {
auto opt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jopt_handle);
auto rdb = new rocksdb::RestoreBackupableDB(rocksdb::Env::Default(), *opt);
rocksdb::RestoreBackupableDBJni::setHandle(env, jobj, rdb);
return reinterpret_cast<jlong>(rdb);
}
/*
@ -144,6 +142,4 @@ void Java_org_rocksdb_RestoreBackupableDB_dispose(JNIEnv* env, jobject jobj,
auto ropt = reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle);
assert(ropt);
delete ropt;
rocksdb::RestoreBackupableDBJni::setHandle(env, jobj, nullptr);
}

Loading…
Cancel
Save