[RocksJava] BackupableDBOptions alginment + 3.8
- Updated the BackupableDBOptions functionality to 3.8.0. - Aligned Options implementation with remaining source code. - Invented test-case.
This commit is contained in:
parent
fbc42a0933
commit
9972f969ee
@ -47,7 +47,8 @@ ifeq ($(PLATFORM), OS_MACOSX)
|
||||
ROCKSDB_JAR = rocksdbjni-$(ROCKSDB_MAJOR).$(ROCKSDB_MINOR).$(ROCKSDB_PATCH)-osx.jar
|
||||
endif
|
||||
|
||||
JAVA_TESTS = org.rocksdb.test.BackupableDBTest\
|
||||
JAVA_TESTS = org.rocksdb.test.BackupableDBOptionsTest\
|
||||
org.rocksdb.test.BackupableDBTest\
|
||||
org.rocksdb.test.BlockBasedTableConfigTest\
|
||||
org.rocksdb.test.ColumnFamilyOptionsTest\
|
||||
org.rocksdb.test.ColumnFamilyTest\
|
||||
|
@ -6,56 +6,30 @@
|
||||
package org.rocksdb;
|
||||
|
||||
/**
|
||||
* 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}.
|
||||
*
|
||||
* Note that dispose() must be called before an Options instance
|
||||
* become out-of-scope to release the allocated memory in c++.
|
||||
* </p>
|
||||
* <p>Note that dispose() must be called before an Options instance
|
||||
* become out-of-scope to release the allocated memory in c++.</p>
|
||||
*
|
||||
* @see org.rocksdb.BackupableDB
|
||||
*/
|
||||
public class BackupableDBOptions extends RocksObject {
|
||||
|
||||
/**
|
||||
* BackupableDBOptions constructor
|
||||
* <p>BackupableDBOptions constructor.</p>
|
||||
*
|
||||
* @param path Where to keep the backup files. Has to be different than db name.
|
||||
* Best to set this to {@code db name_ + "/backups"}
|
||||
* @param shareTableFiles If {@code share_table_files == true}, backup will assume
|
||||
* that table files with same name have the same contents. This enables incremental
|
||||
* backups and avoids unnecessary data copies. If {@code share_table_files == false},
|
||||
* each backup will be on its own and will not share any data with other backups.
|
||||
* Default: true
|
||||
* @param sync If {@code sync == true}, we can guarantee you'll get consistent backup
|
||||
* even on a machine crash/reboot. Backup process is slower with sync enabled.
|
||||
* If {@code sync == false}, we don't guarantee anything on machine reboot.
|
||||
* However,chances are some of the backups are consistent.
|
||||
* Default: true
|
||||
* @param destroyOldData If true, it will delete whatever backups there are already.
|
||||
* Default: false
|
||||
* @param backupLogFiles If false, we won't backup log files. This option can be
|
||||
* useful for backing up in-memory databases where log file are persisted,but table
|
||||
* files are in memory.
|
||||
* Default: true
|
||||
* @param backupRateLimit Max bytes that can be transferred in a second during backup.
|
||||
* If 0 or negative, then go as fast as you can. Default: 0
|
||||
* @param restoreRateLimit Max bytes that can be transferred in a second during restore.
|
||||
* If 0 or negative, then go as fast as you can. Default: 0
|
||||
* Best to set this to {@code db name_ + "/backups"}
|
||||
*/
|
||||
public BackupableDBOptions(String path, boolean shareTableFiles, boolean sync,
|
||||
boolean destroyOldData, boolean backupLogFiles, long backupRateLimit,
|
||||
long restoreRateLimit) {
|
||||
public BackupableDBOptions(String path) {
|
||||
super();
|
||||
|
||||
backupRateLimit = (backupRateLimit <= 0) ? 0 : backupRateLimit;
|
||||
restoreRateLimit = (restoreRateLimit <= 0) ? 0 : restoreRateLimit;
|
||||
|
||||
newBackupableDBOptions(path, shareTableFiles, sync, destroyOldData,
|
||||
backupLogFiles, backupRateLimit, restoreRateLimit);
|
||||
assert(path != null);
|
||||
newBackupableDBOptions(path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the BackupableDB directory.
|
||||
* <p>Returns the path to the BackupableDB directory.</p>
|
||||
*
|
||||
* @return the path to the BackupableDB directory.
|
||||
*/
|
||||
@ -64,18 +38,227 @@ public class BackupableDBOptions extends RocksObject {
|
||||
return backupDir(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Share table files between backups.</p>
|
||||
*
|
||||
* @param shareTableFiles If {@code share_table_files == true}, backup will assume
|
||||
* that table files with same name have the same contents. This enables incremental
|
||||
* backups and avoids unnecessary data copies. If {@code share_table_files == false},
|
||||
* each backup will be on its own and will not share any data with other backups.
|
||||
*
|
||||
* <p>Default: true</p>
|
||||
*
|
||||
* @return instance of current BackupableDBOptions.
|
||||
*/
|
||||
public BackupableDBOptions setShareTableFiles(boolean shareTableFiles) {
|
||||
assert(isInitialized());
|
||||
setShareTableFiles(nativeHandle_, shareTableFiles);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Share table files between backups.</p>
|
||||
*
|
||||
* @return boolean value indicating if SST files will be shared between
|
||||
* backups.
|
||||
*/
|
||||
public boolean shareTableFiles() {
|
||||
assert(isInitialized());
|
||||
return shareTableFiles(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Set synchronous backups.</p>
|
||||
*
|
||||
* @param sync If {@code sync == true}, we can guarantee you'll get consistent backup
|
||||
* even on a machine crash/reboot. Backup process is slower with sync enabled.
|
||||
* If {@code sync == false}, we don't guarantee anything on machine reboot.
|
||||
* However,chances are some of the backups are consistent.
|
||||
*
|
||||
* <p>Default: true</p>
|
||||
*
|
||||
* @return instance of current BackupableDBOptions.
|
||||
*/
|
||||
public BackupableDBOptions setSync(boolean sync) {
|
||||
assert(isInitialized());
|
||||
setSync(nativeHandle_, sync);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Are synchronous backups activated.</p>
|
||||
*
|
||||
* @return boolean value if synchronous backups are configured.
|
||||
*/
|
||||
public boolean sync() {
|
||||
assert(isInitialized());
|
||||
return sync(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Set if old data will be destroyed.</p>
|
||||
*
|
||||
* @param destroyOldData If true, it will delete whatever backups there are already.
|
||||
*
|
||||
* <p>Default: false</p>
|
||||
*
|
||||
* @return instance of current BackupableDBOptions.
|
||||
*/
|
||||
public BackupableDBOptions setDestroyOldData(boolean destroyOldData) {
|
||||
assert(isInitialized());
|
||||
setDestroyOldData(nativeHandle_, destroyOldData);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Returns if old data will be destroyed will performing new backups.</p>
|
||||
*
|
||||
* @return boolean value indicating if old data will be destroyed.
|
||||
*/
|
||||
public boolean destroyOldData() {
|
||||
assert(isInitialized());
|
||||
return destroyOldData(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Set if log files shall be persisted.</p>
|
||||
*
|
||||
* @param backupLogFiles If false, we won't backup log files. This option can be
|
||||
* useful for backing up in-memory databases where log file are persisted,but table
|
||||
* files are in memory.
|
||||
*
|
||||
* <p>Default: true</p>
|
||||
*
|
||||
* @return instance of current BackupableDBOptions.
|
||||
*/
|
||||
public BackupableDBOptions setBackupLogFiles(boolean backupLogFiles) {
|
||||
assert(isInitialized());
|
||||
setBackupLogFiles(nativeHandle_, backupLogFiles);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Return information if log files shall be persisted.</p>
|
||||
*
|
||||
* @return boolean value indicating if log files will be persisted.
|
||||
*/
|
||||
public boolean backupLogFiles() {
|
||||
assert(isInitialized());
|
||||
return backupLogFiles(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Set backup rate limit.</p>
|
||||
*
|
||||
* @param backupRateLimit Max bytes that can be transferred in a second during backup.
|
||||
* If 0 or negative, then go as fast as you can.
|
||||
*
|
||||
* <p>Default: 0</p>
|
||||
*
|
||||
* @return instance of current BackupableDBOptions.
|
||||
*/
|
||||
public BackupableDBOptions setBackupRateLimit(long backupRateLimit) {
|
||||
assert(isInitialized());
|
||||
backupRateLimit = (backupRateLimit <= 0) ? 0 : backupRateLimit;
|
||||
setBackupRateLimit(nativeHandle_, backupRateLimit);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Return backup rate limit which described the max bytes that can be transferred in a
|
||||
* second during backup.</p>
|
||||
*
|
||||
* @return numerical value describing the backup transfer limit in bytes per second.
|
||||
*/
|
||||
public long backupRateLimit() {
|
||||
assert(isInitialized());
|
||||
return backupRateLimit(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Set restore rate limit.</p>
|
||||
*
|
||||
* @param restoreRateLimit Max bytes that can be transferred in a second during restore.
|
||||
* If 0 or negative, then go as fast as you can.
|
||||
*
|
||||
* <p>Default: 0</p>
|
||||
*
|
||||
* @return instance of current BackupableDBOptions.
|
||||
*/
|
||||
public BackupableDBOptions setRestoreRateLimit(long restoreRateLimit) {
|
||||
assert(isInitialized());
|
||||
restoreRateLimit = (restoreRateLimit <= 0) ? 0 : restoreRateLimit;
|
||||
setRestoreRateLimit(nativeHandle_, restoreRateLimit);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Return restore rate limit which described the max bytes that can be transferred in a
|
||||
* second during restore.</p>
|
||||
*
|
||||
* @return numerical value describing the restore transfer limit in bytes per second.
|
||||
*/
|
||||
public long restoreRateLimit() {
|
||||
assert(isInitialized());
|
||||
return restoreRateLimit(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Only used if share_table_files is set to true. If true, will consider that
|
||||
* backups can come from different databases, hence a sst is not uniquely
|
||||
* identified by its name, but by the triple (file name, crc32, file length)</p>
|
||||
*
|
||||
* @param shareFilesWithChecksum boolean value indicating if SST files are stored
|
||||
* using the triple (file name, crc32, file length) and not its name.
|
||||
*
|
||||
* <p>Note: this is an experimental option, and you'll need to set it manually
|
||||
* turn it on only if you know what you're doing*</p>
|
||||
*
|
||||
* <p>Default: false</p>
|
||||
*
|
||||
* @return instance of current BackupableDBOptions.
|
||||
*/
|
||||
public BackupableDBOptions setShareFilesWithChecksum(
|
||||
boolean shareFilesWithChecksum) {
|
||||
assert(isInitialized());
|
||||
setShareFilesWithChecksum(nativeHandle_, shareFilesWithChecksum);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Return of share files with checksum is active.</p>
|
||||
*
|
||||
* @return boolean value indicating if share files with checksum
|
||||
* is active.
|
||||
*/
|
||||
public boolean shareFilesWithChecksum() {
|
||||
assert(isInitialized());
|
||||
return shareFilesWithChecksum(nativeHandle_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Release the memory allocated for the current instance
|
||||
* in the c++ side.
|
||||
*/
|
||||
@Override protected void disposeInternal() {
|
||||
assert(isInitialized());
|
||||
disposeInternal(nativeHandle_);
|
||||
}
|
||||
|
||||
private native void newBackupableDBOptions(String path,
|
||||
boolean shareTableFiles, boolean sync, boolean destroyOldData,
|
||||
boolean backupLogFiles, long backupRateLimit, long restoreRateLimit);
|
||||
private native void newBackupableDBOptions(String path);
|
||||
private native String backupDir(long handle);
|
||||
private native void setShareTableFiles(long handle, boolean flag);
|
||||
private native boolean shareTableFiles(long handle);
|
||||
private native void setSync(long handle, boolean flag);
|
||||
private native boolean sync(long handle);
|
||||
private native void setDestroyOldData(long handle, boolean flag);
|
||||
private native boolean destroyOldData(long handle);
|
||||
private native void setBackupLogFiles(long handle, boolean flag);
|
||||
private native boolean backupLogFiles(long handle);
|
||||
private native void setBackupRateLimit(long handle, long rateLimit);
|
||||
private native long backupRateLimit(long handle);
|
||||
private native void setRestoreRateLimit(long handle, long rateLimit);
|
||||
private native long restoreRateLimit(long handle);
|
||||
private native void setShareFilesWithChecksum(long handle, boolean flag);
|
||||
private native boolean shareFilesWithChecksum(long handle);
|
||||
private native void disposeInternal(long handle);
|
||||
}
|
||||
|
284
java/org/rocksdb/test/BackupableDBOptionsTest.java
Normal file
284
java/org/rocksdb/test/BackupableDBOptionsTest.java
Normal file
@ -0,0 +1,284 @@
|
||||
// Copyright (c) 2014, Facebook, Inc. All rights reserved.
|
||||
// This source code is licensed under the BSD-style license found in the
|
||||
// LICENSE file in the root directory of this source tree. An additional grant
|
||||
// of patent rights can be found in the PATENTS file in the same directory.
|
||||
|
||||
package org.rocksdb.test;
|
||||
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.rocksdb.BackupableDBOptions;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class BackupableDBOptionsTest {
|
||||
|
||||
private final static String ARBITRARY_PATH = "/path";
|
||||
|
||||
@ClassRule
|
||||
public static final RocksMemoryResource rocksMemoryResource =
|
||||
new RocksMemoryResource();
|
||||
|
||||
@Rule
|
||||
public ExpectedException exception = ExpectedException.none();
|
||||
|
||||
public static final Random rand = PlatformRandomHelper.
|
||||
getPlatformSpecificRandomFactory();
|
||||
|
||||
@Test
|
||||
public void backupDir() {
|
||||
BackupableDBOptions backupableDBOptions = null;
|
||||
try {
|
||||
backupableDBOptions = new BackupableDBOptions(ARBITRARY_PATH);
|
||||
assertThat(backupableDBOptions.backupDir()).
|
||||
isEqualTo(ARBITRARY_PATH);
|
||||
} finally {
|
||||
if (backupableDBOptions != null) {
|
||||
backupableDBOptions.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shareTableFiles() {
|
||||
BackupableDBOptions backupableDBOptions = null;
|
||||
try {
|
||||
backupableDBOptions = new BackupableDBOptions(ARBITRARY_PATH);
|
||||
boolean value = rand.nextBoolean();
|
||||
backupableDBOptions.setShareTableFiles(value);
|
||||
assertThat(backupableDBOptions.shareTableFiles()).
|
||||
isEqualTo(value);
|
||||
} finally {
|
||||
if (backupableDBOptions != null) {
|
||||
backupableDBOptions.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sync() {
|
||||
BackupableDBOptions backupableDBOptions = null;
|
||||
try {
|
||||
backupableDBOptions = new BackupableDBOptions(ARBITRARY_PATH);
|
||||
boolean value = rand.nextBoolean();
|
||||
backupableDBOptions.setSync(value);
|
||||
assertThat(backupableDBOptions.sync()).isEqualTo(value);
|
||||
} finally {
|
||||
if (backupableDBOptions != null) {
|
||||
backupableDBOptions.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroyOldData() {
|
||||
BackupableDBOptions backupableDBOptions = null;
|
||||
try {
|
||||
backupableDBOptions = new BackupableDBOptions(ARBITRARY_PATH);
|
||||
boolean value = rand.nextBoolean();
|
||||
backupableDBOptions.setDestroyOldData(value);
|
||||
assertThat(backupableDBOptions.destroyOldData()).
|
||||
isEqualTo(value);
|
||||
} finally {
|
||||
if (backupableDBOptions != null) {
|
||||
backupableDBOptions.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backupLogFiles() {
|
||||
BackupableDBOptions backupableDBOptions = null;
|
||||
try {
|
||||
backupableDBOptions = new BackupableDBOptions(ARBITRARY_PATH);
|
||||
boolean value = rand.nextBoolean();
|
||||
backupableDBOptions.setBackupLogFiles(value);
|
||||
assertThat(backupableDBOptions.backupLogFiles()).
|
||||
isEqualTo(value);
|
||||
} finally {
|
||||
if (backupableDBOptions != null) {
|
||||
backupableDBOptions.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backupRateLimit() {
|
||||
BackupableDBOptions backupableDBOptions = null;
|
||||
try {
|
||||
backupableDBOptions = new BackupableDBOptions(ARBITRARY_PATH);
|
||||
long value = Math.abs(rand.nextLong());
|
||||
backupableDBOptions.setBackupRateLimit(value);
|
||||
assertThat(backupableDBOptions.backupRateLimit()).
|
||||
isEqualTo(value);
|
||||
// negative will be mapped to 0
|
||||
backupableDBOptions.setBackupRateLimit(-1);
|
||||
assertThat(backupableDBOptions.backupRateLimit()).
|
||||
isEqualTo(0);
|
||||
} finally {
|
||||
if (backupableDBOptions != null) {
|
||||
backupableDBOptions.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoreRateLimit() {
|
||||
BackupableDBOptions backupableDBOptions = null;
|
||||
try {
|
||||
backupableDBOptions = new BackupableDBOptions(ARBITRARY_PATH);
|
||||
long value = Math.abs(rand.nextLong());
|
||||
backupableDBOptions.setRestoreRateLimit(value);
|
||||
assertThat(backupableDBOptions.restoreRateLimit()).
|
||||
isEqualTo(value);
|
||||
// negative will be mapped to 0
|
||||
backupableDBOptions.setRestoreRateLimit(-1);
|
||||
assertThat(backupableDBOptions.restoreRateLimit()).
|
||||
isEqualTo(0);
|
||||
} finally {
|
||||
if (backupableDBOptions != null) {
|
||||
backupableDBOptions.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shareFilesWithChecksum() {
|
||||
BackupableDBOptions backupableDBOptions = null;
|
||||
try {
|
||||
backupableDBOptions = new BackupableDBOptions(ARBITRARY_PATH);
|
||||
boolean value = rand.nextBoolean();
|
||||
backupableDBOptions.setShareFilesWithChecksum(value);
|
||||
assertThat(backupableDBOptions.shareFilesWithChecksum()).
|
||||
isEqualTo(value);
|
||||
} finally {
|
||||
if (backupableDBOptions != null) {
|
||||
backupableDBOptions.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failBackupDirIsNull() {
|
||||
exception.expect(AssertionError.class);
|
||||
new BackupableDBOptions(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failBackupDirIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.backupDir();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failSetShareTableFilesIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.setShareTableFiles(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failShareTableFilesIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.shareTableFiles();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failSetSyncIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.setSync(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failSyncIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.sync();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failSetDestroyOldDataIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.setDestroyOldData(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failDestroyOldDataIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.destroyOldData();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failSetBackupLogFilesIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.setBackupLogFiles(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failBackupLogFilesIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.backupLogFiles();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failSetBackupRateLimitIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.setBackupRateLimit(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failBackupRateLimitIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.backupRateLimit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failSetRestoreRateLimitIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.setRestoreRateLimit(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failRestoreRateLimitIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.restoreRateLimit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failSetShareFilesWithChecksumIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.setShareFilesWithChecksum(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failShareFilesWithChecksumIfDisposed(){
|
||||
BackupableDBOptions options = setupUninitializedBackupableDBOptions(
|
||||
exception);
|
||||
options.shareFilesWithChecksum();
|
||||
}
|
||||
|
||||
private BackupableDBOptions setupUninitializedBackupableDBOptions(
|
||||
ExpectedException exception) {
|
||||
BackupableDBOptions backupableDBOptions =
|
||||
new BackupableDBOptions(ARBITRARY_PATH);
|
||||
backupableDBOptions.dispose();
|
||||
exception.expect(AssertionError.class);
|
||||
return backupableDBOptions;
|
||||
}
|
||||
}
|
@ -39,8 +39,7 @@ public class BackupableDBTest {
|
||||
opt.setCreateIfMissing(true);
|
||||
|
||||
bopt = new BackupableDBOptions(
|
||||
backupFolder.getRoot().getAbsolutePath(), false,
|
||||
true, false, true, 0, 0);
|
||||
backupFolder.getRoot().getAbsolutePath());
|
||||
assertThat(bopt.backupDir()).isEqualTo(
|
||||
backupFolder.getRoot().getAbsolutePath());
|
||||
|
||||
|
@ -101,20 +101,10 @@ jobject Java_org_rocksdb_BackupableDB_getBackupInfo(
|
||||
* Signature: (Ljava/lang/String;)V
|
||||
*/
|
||||
void Java_org_rocksdb_BackupableDBOptions_newBackupableDBOptions(
|
||||
JNIEnv* env, jobject jobj, jstring jpath, jboolean jshare_table_files,
|
||||
jboolean jsync, jboolean jdestroy_old_data, jboolean jbackup_log_files,
|
||||
jlong jbackup_rate_limit, jlong jrestore_rate_limit) {
|
||||
jbackup_rate_limit = (jbackup_rate_limit <= 0) ? 0 : jbackup_rate_limit;
|
||||
jrestore_rate_limit = (jrestore_rate_limit <= 0) ? 0 : jrestore_rate_limit;
|
||||
|
||||
JNIEnv* env, jobject jobj, jstring jpath) {
|
||||
const char* cpath = env->GetStringUTFChars(jpath, 0);
|
||||
|
||||
auto bopt = new rocksdb::BackupableDBOptions(cpath, nullptr,
|
||||
jshare_table_files, nullptr, jsync, jdestroy_old_data, jbackup_log_files,
|
||||
jbackup_rate_limit, jrestore_rate_limit);
|
||||
|
||||
auto bopt = new rocksdb::BackupableDBOptions(cpath);
|
||||
env->ReleaseStringUTFChars(jpath, cpath);
|
||||
|
||||
rocksdb::BackupableDBOptionsJni::setHandle(env, jobj, bopt);
|
||||
}
|
||||
|
||||
@ -129,6 +119,160 @@ jstring Java_org_rocksdb_BackupableDBOptions_backupDir(
|
||||
return env->NewStringUTF(bopt->backup_dir.c_str());
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: setShareTableFiles
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
void Java_org_rocksdb_BackupableDBOptions_setShareTableFiles(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
bopt->share_table_files = flag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: shareTableFiles
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_BackupableDBOptions_shareTableFiles(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
return bopt->share_table_files;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: setSync
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
void Java_org_rocksdb_BackupableDBOptions_setSync(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
bopt->sync = flag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: sync
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_BackupableDBOptions_sync(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
return bopt->sync;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: setDestroyOldData
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
void Java_org_rocksdb_BackupableDBOptions_setDestroyOldData(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
bopt->destroy_old_data = flag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: destroyOldData
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_BackupableDBOptions_destroyOldData(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
return bopt->destroy_old_data;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: setBackupLogFiles
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
void Java_org_rocksdb_BackupableDBOptions_setBackupLogFiles(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
bopt->backup_log_files = flag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: backupLogFiles
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_BackupableDBOptions_backupLogFiles(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
return bopt->backup_log_files;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: setBackupRateLimit
|
||||
* Signature: (JJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_BackupableDBOptions_setBackupRateLimit(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jlong jbackup_rate_limit) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
bopt->backup_rate_limit = jbackup_rate_limit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: backupRateLimit
|
||||
* Signature: (J)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_BackupableDBOptions_backupRateLimit(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
return bopt->backup_rate_limit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: setRestoreRateLimit
|
||||
* Signature: (JJ)V
|
||||
*/
|
||||
void Java_org_rocksdb_BackupableDBOptions_setRestoreRateLimit(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jlong jrestore_rate_limit) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
bopt->restore_rate_limit = jrestore_rate_limit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: restoreRateLimit
|
||||
* Signature: (J)J
|
||||
*/
|
||||
jlong Java_org_rocksdb_BackupableDBOptions_restoreRateLimit(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
return bopt->restore_rate_limit;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: setShareFilesWithChecksum
|
||||
* Signature: (JZ)V
|
||||
*/
|
||||
void Java_org_rocksdb_BackupableDBOptions_setShareFilesWithChecksum(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle, jboolean flag) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
bopt->share_files_with_checksum = flag;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: shareFilesWithChecksum
|
||||
* Signature: (J)Z
|
||||
*/
|
||||
jboolean Java_org_rocksdb_BackupableDBOptions_shareFilesWithChecksum(
|
||||
JNIEnv* env, jobject jobj, jlong jhandle) {
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
return bopt->share_files_with_checksum;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_rocksdb_BackupableDBOptions
|
||||
* Method: disposeInternal
|
||||
@ -139,6 +283,5 @@ void Java_org_rocksdb_BackupableDBOptions_disposeInternal(
|
||||
auto bopt = reinterpret_cast<rocksdb::BackupableDBOptions*>(jhandle);
|
||||
assert(bopt);
|
||||
delete bopt;
|
||||
|
||||
rocksdb::BackupableDBOptionsJni::setHandle(env, jopt, nullptr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user