Skip to content

Commit

Permalink
Add support for PauseBackgroundWork and ContinueBackgroundWork to the…
Browse files Browse the repository at this point in the history
… Java API (#1087)

Closes #1071
  • Loading branch information
adamretter authored and yhchiang committed May 6, 2016
1 parent 8f65fea commit 4d02bfa
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
36 changes: 36 additions & 0 deletions java/rocksjni/rocksjni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions java/src/main/java/org/rocksdb/RocksDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,23 @@ public void compactRange(final ColumnFamilyHandle columnFamilyHandle,
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>
*
Expand Down Expand Up @@ -1876,6 +1893,8 @@ private native void compactRange(long handle, boolean reduce_level,
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,
Expand Down
13 changes: 13 additions & 0 deletions java/src/test/java/org/rocksdb/RocksDBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ public void compactRangeToLevelColumnFamily()
}
}

@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);
Expand Down

0 comments on commit 4d02bfa

Please sign in to comment.