Add support for PauseBackgroundWork and ContinueBackgroundWork to the Java API (#1087)

Closes https://github.com/facebook/rocksdb/issues/1071
main
Adam Retter 9 years ago committed by Yueh-Hsuan Chiang
parent 8f65feafc0
commit 4d02bfa3a6
  1. 36
      java/rocksjni/rocksjni.cc
  2. 19
      java/src/main/java/org/rocksdb/RocksDB.java
  3. 13
      java/src/test/java/org/rocksdb/RocksDBTest.java

@ -1484,6 +1484,42 @@ void Java_org_rocksdb_RocksDB_compactRange__J_3BI_3BIZIIJ(
jend, jend_len, jreduce_level, jtarget_level, jtarget_path_id);
}
//////////////////////////////////////////////////////////////////////////////
// rocksdb::DB::PauseBackgroundWork
/*
* Class: org_rocksdb_RocksDB
* Method: pauseBackgroundWork
* Signature: (J)V
*/
void Java_org_rocksdb_RocksDB_pauseBackgroundWork(
JNIEnv* env, jobject jobj, jlong jdb_handle) {
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
auto s = db->PauseBackgroundWork();
if (s.ok()) {
return;
}
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
}
//////////////////////////////////////////////////////////////////////////////
// rocksdb::DB::ContinueBackgroundWork
/*
* Class: org_rocksdb_RocksDB
* Method: continueBackgroundWork
* Signature: (J)V
*/
void Java_org_rocksdb_RocksDB_continueBackgroundWork(
JNIEnv* env, jobject jobj, jlong jdb_handle) {
auto* db = reinterpret_cast<rocksdb::DB*>(jdb_handle);
auto s = db->ContinueBackgroundWork();
if (s.ok()) {
return;
}
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
}
//////////////////////////////////////////////////////////////////////////////
// rocksdb::DB::GetLatestSequenceNumber

@ -1631,6 +1631,23 @@ public class RocksDB extends RocksObject {
columnFamilyHandle.nativeHandle_);
}
/**
* This function will wait until all currently running background processes
* finish. After it returns, no background process will be run until
* {@link #continueBackgroundWork()} is called
*/
public void pauseBackgroundWork() throws RocksDBException {
pauseBackgroundWork(nativeHandle_);
}
/**
* Resumes backround work which was suspended by
* previously calling {@link #pauseBackgroundWork()}
*/
public void continueBackgroundWork() throws RocksDBException {
continueBackgroundWork(nativeHandle_);
}
/**
* <p>The sequence number of the most recent transaction.</p>
*
@ -1876,6 +1893,8 @@ public class RocksDB extends RocksObject {
private native void compactRange(long handle, byte[] begin, int beginLen,
byte[] end, int endLen, boolean reduce_level, int target_level,
int target_path_id, long cfHandle) throws RocksDBException;
private native void pauseBackgroundWork(long handle) throws RocksDBException;
private native void continueBackgroundWork(long handle) throws RocksDBException;
private native long getLatestSequenceNumber(long handle);
private native void disableFileDeletions(long handle) throws RocksDBException;
private native void enableFileDeletions(long handle,

@ -637,6 +637,19 @@ public class RocksDBTest {
}
}
@Test
public void pauseContinueBackgroundWork() throws RocksDBException {
try (final Options options = new Options().setCreateIfMissing(true);
final RocksDB db = RocksDB.open(options,
dbFolder.getRoot().getAbsolutePath())
) {
db.pauseBackgroundWork();
db.continueBackgroundWork();
db.pauseBackgroundWork();
db.continueBackgroundWork();
}
}
@Test
public void enableDisableFileDeletions() throws RocksDBException {
try (final Options options = new Options().setCreateIfMissing(true);

Loading…
Cancel
Save