From faa8d32be0d73be2a6127539062728b6aa0347fc Mon Sep 17 00:00:00 2001
From: fyrz
Date: Thu, 20 Nov 2014 22:47:48 +0100
Subject: [PATCH] [RocksJava] Integrated changes from D29019.
---
java/org/rocksdb/BackupableDB.java | 6 ++--
java/org/rocksdb/BackupableDBOptions.java | 9 +++++-
java/org/rocksdb/RestoreBackupableDB.java | 6 ++--
.../rocksdb/test/BackupableDBOptionsTest.java | 4 +--
java/org/rocksdb/test/BackupableDBTest.java | 4 +--
java/rocksjni/backupablejni.cc | 29 +++++++------------
java/rocksjni/restorejni.cc | 29 +++++++------------
7 files changed, 40 insertions(+), 47 deletions(-)
diff --git a/java/org/rocksdb/BackupableDB.java b/java/org/rocksdb/BackupableDB.java
index 5c5de5fd3..a743d861e 100644
--- a/java/org/rocksdb/BackupableDB.java
+++ b/java/org/rocksdb/BackupableDB.java
@@ -103,9 +103,9 @@ public class BackupableDB extends RocksDB {
* is no corrupted backup the method will return an
* empty list.
*
- * @return list of backup ids as Integer.
+ * @return array of backup ids as int ids.
*/
- public List 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 getBackupInfo(long handle);
- private native List getCorruptedBackups(long handle);
+ private native int[] getCorruptedBackups(long handle);
private native void garbageCollect(long handle)
throws RocksDBException;
}
diff --git a/java/org/rocksdb/BackupableDBOptions.java b/java/org/rocksdb/BackupableDBOptions.java
index 18e2dfa11..ab532f282 100644
--- a/java/org/rocksdb/BackupableDBOptions.java
+++ b/java/org/rocksdb/BackupableDBOptions.java
@@ -5,6 +5,9 @@
package org.rocksdb;
+import java.io.File;
+import java.nio.file.Path;
+
/**
* 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);
}
diff --git a/java/org/rocksdb/RestoreBackupableDB.java b/java/org/rocksdb/RestoreBackupableDB.java
index e7890c278..e29628815 100644
--- a/java/org/rocksdb/RestoreBackupableDB.java
+++ b/java/org/rocksdb/RestoreBackupableDB.java
@@ -115,9 +115,9 @@ public class RestoreBackupableDB extends RocksObject {
* is no corrupted backup the method will return an
* empty list.
*
- * @return list of backup ids as Integer.
+ * @return array of backup ids as int ids.
*/
- public List 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 getBackupInfo(long handle);
- private native List getCorruptedBackups(long handle);
+ private native int[] getCorruptedBackups(long handle);
private native void garbageCollect(long handle)
throws RocksDBException;
private native void dispose(long nativeHandle);
diff --git a/java/org/rocksdb/test/BackupableDBOptionsTest.java b/java/org/rocksdb/test/BackupableDBOptionsTest.java
index 6be056986..b7bdc0011 100644
--- a/java/org/rocksdb/test/BackupableDBOptionsTest.java
+++ b/java/org/rocksdb/test/BackupableDBOptionsTest.java
@@ -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);
}
diff --git a/java/org/rocksdb/test/BackupableDBTest.java b/java/org/rocksdb/test/BackupableDBTest.java
index 0b5334607..3da519418 100644
--- a/java/org/rocksdb/test/BackupableDBTest.java
+++ b/java/org/rocksdb/test/BackupableDBTest.java
@@ -369,7 +369,7 @@ public class BackupableDBTest {
private List 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 = 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 = rdb.getBackupInfos();
diff --git a/java/rocksjni/backupablejni.cc b/java/rocksjni/backupablejni.cc
index 23de95407..83c641370 100644
--- a/java/rocksjni/backupablejni.cc
+++ b/java/rocksjni/backupablejni.cc
@@ -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 backup_ids;
reinterpret_cast(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::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, "", "(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;
}
/*
diff --git a/java/rocksjni/restorejni.cc b/java/rocksjni/restorejni.cc
index 99ffc4256..ad8749758 100644
--- a/java/rocksjni/restorejni.cc
+++ b/java/rocksjni/restorejni.cc
@@ -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 backup_ids;
reinterpret_cast(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::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, "", "(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;
}
/*