[RocksJava] Integrated changes from D29019.
This commit is contained in:
parent
3d78c7a8cf
commit
faa8d32be0
@ -103,9 +103,9 @@ public class BackupableDB extends RocksDB {
|
||||
* is no corrupted backup the method will return an
|
||||
* empty list.</p>
|
||||
*
|
||||
* @return list of backup ids as Integer.
|
||||
* @return array of backup ids as int ids.
|
||||
*/
|
||||
public List<Integer> getCorruptedBackups() {
|
||||
public int[] getCorruptedBackups() {
|
||||
assert(isInitialized());
|
||||
return getCorruptedBackups(nativeHandle_);
|
||||
}
|
||||
@ -160,7 +160,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 int[] getCorruptedBackups(long handle);
|
||||
private native void garbageCollect(long handle)
|
||||
throws RocksDBException;
|
||||
}
|
||||
|
@ -5,6 +5,9 @@
|
||||
|
||||
package org.rocksdb;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
/**
|
||||
* <p>BackupableDBOptions to control the behavior of a backupable database.
|
||||
* It will be used during the creation of a {@link org.rocksdb.BackupableDB}.
|
||||
@ -21,10 +24,14 @@ public class BackupableDBOptions extends RocksObject {
|
||||
*
|
||||
* @param path Where to keep the backup files. Has to be different than db name.
|
||||
* Best to set this to {@code db name_ + "/backups"}
|
||||
* @throws java.lang.IllegalArgumentException if illegal path is used.
|
||||
*/
|
||||
public BackupableDBOptions(String path) {
|
||||
super();
|
||||
assert(path != null);
|
||||
File backupPath = path == null ? null : new File(path);
|
||||
if (backupPath == null || !backupPath.isDirectory() || !backupPath.canWrite()) {
|
||||
throw new IllegalArgumentException("Illegal path provided.");
|
||||
}
|
||||
newBackupableDBOptions(path);
|
||||
}
|
||||
|
||||
|
@ -115,9 +115,9 @@ public class RestoreBackupableDB extends RocksObject {
|
||||
* is no corrupted backup the method will return an
|
||||
* empty list.</p>
|
||||
*
|
||||
* @return list of backup ids as Integer.
|
||||
* @return array of backup ids as int ids.
|
||||
*/
|
||||
public List<Integer> getCorruptedBackups() {
|
||||
public int[] getCorruptedBackups() {
|
||||
assert(isInitialized());
|
||||
return getCorruptedBackups(nativeHandle_);
|
||||
}
|
||||
@ -155,7 +155,7 @@ public class RestoreBackupableDB extends RocksObject {
|
||||
private native void deleteBackup0(long nativeHandle, int backupId)
|
||||
throws RocksDBException;
|
||||
private native List<BackupInfo> getBackupInfo(long handle);
|
||||
private native List<Integer> getCorruptedBackups(long handle);
|
||||
private native int[] getCorruptedBackups(long handle);
|
||||
private native void garbageCollect(long handle)
|
||||
throws RocksDBException;
|
||||
private native void dispose(long nativeHandle);
|
||||
|
@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BackupableDBOptionsTest {
|
||||
|
||||
private final static String ARBITRARY_PATH = "/path";
|
||||
private final static String ARBITRARY_PATH = "/tmp";
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
@ -164,7 +164,7 @@ public class BackupableDBOptionsTest {
|
||||
|
||||
@Test
|
||||
public void failBackupDirIsNull() {
|
||||
exception.expect(AssertionError.class);
|
||||
exception.expect(IllegalArgumentException.class);
|
||||
new BackupableDBOptions(null);
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ public class BackupableDBTest {
|
||||
private List<BackupInfo> verifyNumberOfValidBackups(BackupableDB bdb,
|
||||
int expectedNumberOfBackups) throws RocksDBException {
|
||||
// Verify that backups exist
|
||||
assertThat(bdb.getCorruptedBackups().size()).
|
||||
assertThat(bdb.getCorruptedBackups().length).
|
||||
isEqualTo(0);
|
||||
bdb.garbageCollect();
|
||||
List<BackupInfo> backupInfo = bdb.getBackupInfos();
|
||||
@ -390,7 +390,7 @@ public class BackupableDBTest {
|
||||
RestoreBackupableDB rdb, int expectedNumberOfBackups)
|
||||
throws RocksDBException {
|
||||
// Verify that backups exist
|
||||
assertThat(rdb.getCorruptedBackups().size()).
|
||||
assertThat(rdb.getCorruptedBackups().length).
|
||||
isEqualTo(0);
|
||||
rdb.garbageCollect();
|
||||
List<BackupInfo> backupInfo = rdb.getBackupInfos();
|
||||
|
@ -95,32 +95,25 @@ jobject Java_org_rocksdb_BackupableDB_getBackupInfo(
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDB
|
||||
* Method: getCorruptedBackups
|
||||
* Signature: (J)Ljava/util/List;
|
||||
* Signature: (J)[I;
|
||||
*/
|
||||
jobject Java_org_rocksdb_BackupableDB_getCorruptedBackups(
|
||||
jintArray 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
|
||||
// store backupids in int array
|
||||
const int kIdSize = backup_ids.size();
|
||||
int int_backup_ids[kIdSize];
|
||||
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);
|
||||
int_backup_ids[i] = backup_ids[i];
|
||||
}
|
||||
return jbackup_id_handle_list;
|
||||
// Store ints in java array
|
||||
jintArray ret_backup_ids;
|
||||
ret_backup_ids = env->NewIntArray(kIdSize);
|
||||
env->SetIntArrayRegion(ret_backup_ids, 0, kIdSize, int_backup_ids);
|
||||
return ret_backup_ids;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -148,32 +148,25 @@ jobject Java_org_rocksdb_RestoreBackupableDB_getBackupInfo(
|
||||
/*
|
||||
* Class: org_rocksdb_RestoreBackupableDB
|
||||
* Method: getCorruptedBackups
|
||||
* Signature: (J)Ljava/util/List;
|
||||
* Signature: (J)[I;
|
||||
*/
|
||||
jobject Java_org_rocksdb_RestoreBackupableDB_getCorruptedBackups(
|
||||
jintArray 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
|
||||
// store backupids in int array
|
||||
const int kIdSize = backup_ids.size();
|
||||
int int_backup_ids[kIdSize];
|
||||
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);
|
||||
int_backup_ids[i] = backup_ids[i];
|
||||
}
|
||||
return jbackup_id_handle_list;
|
||||
// Store ints in java array
|
||||
jintArray ret_backup_ids;
|
||||
ret_backup_ids = env->NewIntArray(kIdSize);
|
||||
env->SetIntArrayRegion(ret_backup_ids, 0, kIdSize, int_backup_ids);
|
||||
return ret_backup_ids;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user