From 4d02bfa3a6af32b6ed69e790dd1485433a8fba18 Mon Sep 17 00:00:00 2001 From: Adam Retter Date: Fri, 6 May 2016 18:04:13 -0400 Subject: [PATCH] Add support for PauseBackgroundWork and ContinueBackgroundWork to the Java API (#1087) Closes https://github.com/facebook/rocksdb/issues/1071 --- java/rocksjni/rocksjni.cc | 36 +++++++++++++++++++ java/src/main/java/org/rocksdb/RocksDB.java | 19 ++++++++++ .../test/java/org/rocksdb/RocksDBTest.java | 13 +++++++ 3 files changed, 68 insertions(+) diff --git a/java/rocksjni/rocksjni.cc b/java/rocksjni/rocksjni.cc index c0c73ae2d24..8e93f09a4b5 100644 --- a/java/rocksjni/rocksjni.cc +++ b/java/rocksjni/rocksjni.cc @@ -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(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(jdb_handle); + auto s = db->ContinueBackgroundWork(); + if (s.ok()) { + return; + } + rocksdb::RocksDBExceptionJni::ThrowNew(env, s); +} + ////////////////////////////////////////////////////////////////////////////// // rocksdb::DB::GetLatestSequenceNumber diff --git a/java/src/main/java/org/rocksdb/RocksDB.java b/java/src/main/java/org/rocksdb/RocksDB.java index ba5e18b47fc..dd04ce3f5f1 100644 --- a/java/src/main/java/org/rocksdb/RocksDB.java +++ b/java/src/main/java/org/rocksdb/RocksDB.java @@ -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_); + } + /** *

The sequence number of the most recent transaction.

* @@ -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, diff --git a/java/src/test/java/org/rocksdb/RocksDBTest.java b/java/src/test/java/org/rocksdb/RocksDBTest.java index ceac69f5fab..2a31d826f3b 100644 --- a/java/src/test/java/org/rocksdb/RocksDBTest.java +++ b/java/src/test/java/org/rocksdb/RocksDBTest.java @@ -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);