[RocksJava] Backupable/Restorable DB update 3.8.0

- GarbageCollectMethod() available.
- GetCorruptedBackups() available.
main
fyrz 10 years ago
parent 9972f969ee
commit 24fdc47416
  1. 26
      java/org/rocksdb/BackupableDB.java
  2. 28
      java/org/rocksdb/RestoreBackupableDB.java
  3. 6
      java/org/rocksdb/test/BackupableDBTest.java
  4. 46
      java/rocksjni/backupablejni.cc
  5. 47
      java/rocksjni/restorejni.cc

@ -92,6 +92,29 @@ public class BackupableDB extends RocksDB {
return getBackupInfo(nativeHandle_);
}
/**
* <p>Returns a list of corrupted backup ids. If there
* is no corrupted backup the method will return an
* empty list.</p>
*
* @return list of backup ids as Integer.
*/
public List<Integer> getCorruptedBackups() {
return getCorruptedBackups(nativeHandle_);
}
/**
* <p>Will delete all the files we don't need anymore. It will
* do the full scan of the files/ directory and delete all the
* files that are not referenced.</p>
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/
public void garbageCollect() throws RocksDBException {
garbageCollect(nativeHandle_);
}
/**
* Close the BackupableDB instance and release resource.
*
@ -126,4 +149,7 @@ public class BackupableDB extends RocksDB {
private native void deleteBackup0(long nativeHandle, int backupId)
throws RocksDBException;
protected native List<BackupInfo> getBackupInfo(long handle);
private native List<Integer> getCorruptedBackups(long handle);
private native void garbageCollect(long handle)
throws RocksDBException;
}

@ -101,6 +101,29 @@ public class RestoreBackupableDB extends RocksObject {
return getBackupInfo(nativeHandle_);
}
/**
* <p>Returns a list of corrupted backup ids. If there
* is no corrupted backup the method will return an
* empty list.</p>
*
* @return list of backup ids as Integer.
*/
public List<Integer> getCorruptedBackups() {
return getCorruptedBackups(nativeHandle_);
}
/**
* <p>Will delete all the files we don't need anymore. It will
* do the full scan of the files/ directory and delete all the
* files that are not referenced.</p>
*
* @throws RocksDBException thrown if error happens in underlying
* native library.
*/
public void garbageCollect() throws RocksDBException {
garbageCollect(nativeHandle_);
}
/**
* Release the memory allocated for the current instance
* in the c++ side.
@ -121,6 +144,9 @@ public class RestoreBackupableDB extends RocksObject {
throws RocksDBException;
private native void deleteBackup0(long nativeHandle, int backupId)
throws RocksDBException;
protected native List<BackupInfo> getBackupInfo(long handle);
private native List<BackupInfo> getBackupInfo(long handle);
private native List<Integer> getCorruptedBackups(long handle);
private native void garbageCollect(long handle)
throws RocksDBException;
private native void dispose(long nativeHandle);
}

@ -56,6 +56,9 @@ public class BackupableDBTest {
isEqualTo(0);
bdb.createNewBackup(true);
assertThat(bdb.getCorruptedBackups().size()).
isEqualTo(0);
bdb.garbageCollect();
backupInfos = bdb.getBackupInfos();
assertThat(backupInfos.size()).
isEqualTo(1);
@ -102,6 +105,9 @@ public class BackupableDBTest {
ropt);
// do nothing because there is only one backup
rdb.purgeOldBackups(1);
rdb.garbageCollect();
assertThat(rdb.getCorruptedBackups().size()).
isEqualTo(0);
restoreInfos = rdb.getBackupInfos();
assertThat(restoreInfos.size()).
isEqualTo(1);

@ -92,6 +92,52 @@ jobject Java_org_rocksdb_BackupableDB_getBackupInfo(
backup_infos);
}
/*
* Class: org_rocksdb_BackupableDB
* Method: getCorruptedBackups
* Signature: (J)Ljava/util/List;
*/
jobject Java_org_rocksdb_BackupableDB_getCorruptedBackups(
JNIEnv* env, jobject jbdb, jlong jhandle) {
std::vector<rocksdb::BackupID> backup_ids;
reinterpret_cast<rocksdb::BackupableDB*>(jhandle)->
GetCorruptedBackups(&backup_ids);
jclass jclazz = env->FindClass("java/util/ArrayList");
jmethodID mid = rocksdb::ListJni::getArrayListConstructorMethodId(
env, jclazz);
jobject jbackup_id_handle_list = env->NewObject(jclazz, mid,
backup_ids.size());
// insert in java list
for (std::vector<rocksdb::BackupID>::size_type i = 0;
i != backup_ids.size(); i++) {
// convert BackupID to Integer
jclass jIntClazz = env->FindClass("java/lang/Integer");
jmethodID midLong = env->GetMethodID(jIntClazz, "<init>", "(I)V");
jobject obj = env->NewObject(jIntClazz, midLong,
(backup_ids[i]));
// add Integer to List
env->CallBooleanMethod(jbackup_id_handle_list,
rocksdb::ListJni::getListAddMethodId(env), obj);
}
return jbackup_id_handle_list;
}
/*
* Class: org_rocksdb_BackupableDB
* Method: garbageCollect
* Signature: (J)V
*/
void Java_org_rocksdb_BackupableDB_garbageCollect(JNIEnv* env,
jobject jobj, jlong jhandle) {
auto db = reinterpret_cast<rocksdb::BackupableDB*>(jhandle);
rocksdb::Status s = db->GarbageCollect();
if (!s.ok()) {
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
}
}
///////////////////////////////////////////////////////////////////////////
// BackupDBOptions

@ -145,6 +145,53 @@ jobject Java_org_rocksdb_RestoreBackupableDB_getBackupInfo(
backup_infos);
}
/*
* Class: org_rocksdb_RestoreBackupableDB
* Method: getCorruptedBackups
* Signature: (J)Ljava/util/List;
*/
jobject Java_org_rocksdb_RestoreBackupableDB_getCorruptedBackups(
JNIEnv* env, jobject jbdb, jlong jhandle) {
std::vector<rocksdb::BackupID> backup_ids;
reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle)->
GetCorruptedBackups(&backup_ids);
jclass jclazz = env->FindClass("java/util/ArrayList");
jmethodID mid = rocksdb::ListJni::getArrayListConstructorMethodId(
env, jclazz);
jobject jbackup_id_handle_list = env->NewObject(jclazz, mid,
backup_ids.size());
// insert in java list
for (std::vector<rocksdb::BackupID>::size_type i = 0;
i != backup_ids.size(); i++) {
// convert BackupID to Integer
jclass jIntClazz = env->FindClass("java/lang/Integer");
jmethodID midLong = env->GetMethodID(jIntClazz, "<init>", "(I)V");
jobject obj = env->NewObject(jIntClazz, midLong,
(backup_ids[i]));
// add Integer to List
env->CallBooleanMethod(jbackup_id_handle_list,
rocksdb::ListJni::getListAddMethodId(env), obj);
}
return jbackup_id_handle_list;
}
/*
* 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);
}
}
/*
* Class: org_rocksdb_RestoreBackupableDB
* Method: dispose

Loading…
Cancel
Save