Skip to content

Commit f3b47a7

Browse files
committed
Add RocksDB.waitForCompact() method
1 parent ade6975 commit f3b47a7

2 files changed

Lines changed: 40 additions & 0 deletions

File tree

java/rocksjni/rocksjni.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3134,6 +3134,24 @@ void Java_org_rocksdb_RocksDB_syncWal(JNIEnv* env, jclass, jlong jdb_handle) {
31343134
}
31353135
}
31363136

3137+
/*
3138+
* Class: org_rocksdb_RocksDB
3139+
* Method: waitForCompact
3140+
* Signature: (JJ)V
3141+
*/
3142+
void Java_org_rocksdb_RocksDB_waitForCompact(
3143+
JNIEnv* env, jclass, jlong jdb_handle,
3144+
jlong jwait_for_compact_options_handle) {
3145+
auto* db = reinterpret_cast<ROCKSDB_NAMESPACE::DB*>(jdb_handle);
3146+
auto* wait_for_compact_options =
3147+
reinterpret_cast<ROCKSDB_NAMESPACE::WaitForCompactOptions*>(
3148+
jwait_for_compact_options_handle);
3149+
auto s = db->WaitForCompact(*wait_for_compact_options);
3150+
if (!s.ok()) {
3151+
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, s);
3152+
}
3153+
}
3154+
31373155
/*
31383156
* Class: org_rocksdb_RocksDB
31393157
* Method: getLatestSequenceNumber

java/src/main/java/org/rocksdb/RocksDB.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3839,6 +3839,18 @@ public void compactRange(
38393839
columnFamilyHandle == null ? 0 : columnFamilyHandle.nativeHandle_);
38403840
}
38413841

3842+
/**
3843+
* Wait for all pending flush and compaction jobs to complete.
3844+
* Warning: May block indefinitely if writes continue. Use timeout to prevent this.
3845+
*
3846+
* @param waitForCompactOptions controls timeout, flush inclusion, and abort behavior
3847+
* @throws RocksDBException if wait fails or DB is shutting down
3848+
*/
3849+
public void waitForCompact(final WaitForCompactOptions waitForCompactOptions)
3850+
throws RocksDBException {
3851+
waitForCompact(nativeHandle_, waitForCompactOptions.nativeHandle_);
3852+
}
3853+
38423854
/**
38433855
* ClipColumnFamily() will clip the entries in the CF according to the range
38443856
* [begin_key, end_key). Returns OK on success, and a non-OK status on error.
@@ -5049,6 +5061,16 @@ private static native void flush(final long handle, final long flushOptHandle,
50495061
private static native void flushWal(final long handle, final boolean sync)
50505062
throws RocksDBException;
50515063
private static native void syncWal(final long handle) throws RocksDBException;
5064+
private static native void waitForCompact(
5065+
final long handle, final long waitForCompactOptionsHandle) throws RocksDBException;
5066+
private static native String getDbSessionId(final long handle) throws RocksDBException;
5067+
private static native void lockWAL(final long handle) throws RocksDBException;
5068+
private static native void unlockWAL(final long handle) throws RocksDBException;
5069+
private static native void increaseFullHistoryTsLow(
5070+
final long handle, final long columnFamilyHandle, final byte[] tsLow)
5071+
throws RocksDBException;
5072+
private static native byte[] getFullHistoryTsLow(
5073+
final long handle, final long columnFamilyHandle) throws RocksDBException;
50525074
private static native long getLatestSequenceNumber(final long handle);
50535075
private static native void disableFileDeletions(long handle) throws RocksDBException;
50545076
private static native void enableFileDeletions(long handle) throws RocksDBException;

0 commit comments

Comments
 (0)