[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
|
* is no corrupted backup the method will return an
|
||||||
* empty list.</p>
|
* 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());
|
assert(isInitialized());
|
||||||
return getCorruptedBackups(nativeHandle_);
|
return getCorruptedBackups(nativeHandle_);
|
||||||
}
|
}
|
||||||
@ -160,7 +160,7 @@ public class BackupableDB extends RocksDB {
|
|||||||
private native void deleteBackup0(long nativeHandle, int backupId)
|
private native void deleteBackup0(long nativeHandle, int backupId)
|
||||||
throws RocksDBException;
|
throws RocksDBException;
|
||||||
protected native List<BackupInfo> getBackupInfo(long handle);
|
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)
|
private native void garbageCollect(long handle)
|
||||||
throws RocksDBException;
|
throws RocksDBException;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
package org.rocksdb;
|
package org.rocksdb;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>BackupableDBOptions to control the behavior of a backupable database.
|
* <p>BackupableDBOptions to control the behavior of a backupable database.
|
||||||
* It will be used during the creation of a {@link org.rocksdb.BackupableDB}.
|
* 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.
|
* @param path Where to keep the backup files. Has to be different than db name.
|
||||||
* Best to set this to {@code db name_ + "/backups"}
|
* Best to set this to {@code db name_ + "/backups"}
|
||||||
|
* @throws java.lang.IllegalArgumentException if illegal path is used.
|
||||||
*/
|
*/
|
||||||
public BackupableDBOptions(String path) {
|
public BackupableDBOptions(String path) {
|
||||||
super();
|
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);
|
newBackupableDBOptions(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,9 +115,9 @@ public class RestoreBackupableDB extends RocksObject {
|
|||||||
* is no corrupted backup the method will return an
|
* is no corrupted backup the method will return an
|
||||||
* empty list.</p>
|
* 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());
|
assert(isInitialized());
|
||||||
return getCorruptedBackups(nativeHandle_);
|
return getCorruptedBackups(nativeHandle_);
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ public class RestoreBackupableDB extends RocksObject {
|
|||||||
private native void deleteBackup0(long nativeHandle, int backupId)
|
private native void deleteBackup0(long nativeHandle, int backupId)
|
||||||
throws RocksDBException;
|
throws RocksDBException;
|
||||||
private native List<BackupInfo> getBackupInfo(long handle);
|
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)
|
private native void garbageCollect(long handle)
|
||||||
throws RocksDBException;
|
throws RocksDBException;
|
||||||
private native void dispose(long nativeHandle);
|
private native void dispose(long nativeHandle);
|
||||||
|
@ -17,7 +17,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
|
|
||||||
public class BackupableDBOptionsTest {
|
public class BackupableDBOptionsTest {
|
||||||
|
|
||||||
private final static String ARBITRARY_PATH = "/path";
|
private final static String ARBITRARY_PATH = "/tmp";
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static final RocksMemoryResource rocksMemoryResource =
|
public static final RocksMemoryResource rocksMemoryResource =
|
||||||
@ -164,7 +164,7 @@ public class BackupableDBOptionsTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void failBackupDirIsNull() {
|
public void failBackupDirIsNull() {
|
||||||
exception.expect(AssertionError.class);
|
exception.expect(IllegalArgumentException.class);
|
||||||
new BackupableDBOptions(null);
|
new BackupableDBOptions(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ public class BackupableDBTest {
|
|||||||
private List<BackupInfo> verifyNumberOfValidBackups(BackupableDB bdb,
|
private List<BackupInfo> verifyNumberOfValidBackups(BackupableDB bdb,
|
||||||
int expectedNumberOfBackups) throws RocksDBException {
|
int expectedNumberOfBackups) throws RocksDBException {
|
||||||
// Verify that backups exist
|
// Verify that backups exist
|
||||||
assertThat(bdb.getCorruptedBackups().size()).
|
assertThat(bdb.getCorruptedBackups().length).
|
||||||
isEqualTo(0);
|
isEqualTo(0);
|
||||||
bdb.garbageCollect();
|
bdb.garbageCollect();
|
||||||
List<BackupInfo> backupInfo = bdb.getBackupInfos();
|
List<BackupInfo> backupInfo = bdb.getBackupInfos();
|
||||||
@ -390,7 +390,7 @@ public class BackupableDBTest {
|
|||||||
RestoreBackupableDB rdb, int expectedNumberOfBackups)
|
RestoreBackupableDB rdb, int expectedNumberOfBackups)
|
||||||
throws RocksDBException {
|
throws RocksDBException {
|
||||||
// Verify that backups exist
|
// Verify that backups exist
|
||||||
assertThat(rdb.getCorruptedBackups().size()).
|
assertThat(rdb.getCorruptedBackups().length).
|
||||||
isEqualTo(0);
|
isEqualTo(0);
|
||||||
rdb.garbageCollect();
|
rdb.garbageCollect();
|
||||||
List<BackupInfo> backupInfo = rdb.getBackupInfos();
|
List<BackupInfo> backupInfo = rdb.getBackupInfos();
|
||||||
|
@ -95,32 +95,25 @@ jobject Java_org_rocksdb_BackupableDB_getBackupInfo(
|
|||||||
/*
|
/*
|
||||||
* Class: org_rocksdb_BackupableDB
|
* Class: org_rocksdb_BackupableDB
|
||||||
* Method: getCorruptedBackups
|
* 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) {
|
JNIEnv* env, jobject jbdb, jlong jhandle) {
|
||||||
std::vector<rocksdb::BackupID> backup_ids;
|
std::vector<rocksdb::BackupID> backup_ids;
|
||||||
reinterpret_cast<rocksdb::BackupableDB*>(jhandle)->
|
reinterpret_cast<rocksdb::BackupableDB*>(jhandle)->
|
||||||
GetCorruptedBackups(&backup_ids);
|
GetCorruptedBackups(&backup_ids);
|
||||||
|
// store backupids in int array
|
||||||
jclass jclazz = env->FindClass("java/util/ArrayList");
|
const int kIdSize = backup_ids.size();
|
||||||
jmethodID mid = rocksdb::ListJni::getArrayListConstructorMethodId(
|
int int_backup_ids[kIdSize];
|
||||||
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;
|
for (std::vector<rocksdb::BackupID>::size_type i = 0;
|
||||||
i != backup_ids.size(); i++) {
|
i != backup_ids.size(); i++) {
|
||||||
// convert BackupID to Integer
|
int_backup_ids[i] = backup_ids[i];
|
||||||
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;
|
// 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
|
* Class: org_rocksdb_RestoreBackupableDB
|
||||||
* Method: getCorruptedBackups
|
* 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) {
|
JNIEnv* env, jobject jbdb, jlong jhandle) {
|
||||||
std::vector<rocksdb::BackupID> backup_ids;
|
std::vector<rocksdb::BackupID> backup_ids;
|
||||||
reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle)->
|
reinterpret_cast<rocksdb::RestoreBackupableDB*>(jhandle)->
|
||||||
GetCorruptedBackups(&backup_ids);
|
GetCorruptedBackups(&backup_ids);
|
||||||
|
// store backupids in int array
|
||||||
jclass jclazz = env->FindClass("java/util/ArrayList");
|
const int kIdSize = backup_ids.size();
|
||||||
jmethodID mid = rocksdb::ListJni::getArrayListConstructorMethodId(
|
int int_backup_ids[kIdSize];
|
||||||
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;
|
for (std::vector<rocksdb::BackupID>::size_type i = 0;
|
||||||
i != backup_ids.size(); i++) {
|
i != backup_ids.size(); i++) {
|
||||||
// convert BackupID to Integer
|
int_backup_ids[i] = backup_ids[i];
|
||||||
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;
|
// 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