提交 4d02bfa3 编写于 作者: A Adam Retter 提交者: Yueh-Hsuan Chiang

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

Closes https://github.com/facebook/rocksdb/issues/1071
上级 8f65feaf
......@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册