diff --git a/java/org/rocksdb/RocksDB.java b/java/org/rocksdb/RocksDB.java index 96032165ef3a1608064d01f199708e460117b384..ea38241964d327ca3a06416e38d20b9f3d284d74 100644 --- a/java/org/rocksdb/RocksDB.java +++ b/java/org/rocksdb/RocksDB.java @@ -1588,6 +1588,53 @@ public class RocksDB extends RocksObject { columnFamilyHandle.nativeHandle_); } + /** + *
The sequence number of the most recent transaction.
+ * + * @return sequence number of the most + * recent transaction. + */ + public long getLatestSequenceNumber() { + return getLatestSequenceNumber(nativeHandle_); + } + + /** + *Prevent file deletions. Compactions will continue to occur, + * but no obsolete files will be deleted. Calling this multiple + * times have the same effect as calling it once.
+ * + * @throws RocksDBException thrown if operation was not performed + * successfully. + */ + public void disableFileDeletions() throws RocksDBException { + disableFileDeletions(nativeHandle_); + } + + /** + *Allow compactions to delete obsolete files. + * If force == true, the call to EnableFileDeletions() + * will guarantee that file deletions are enabled after + * the call, even if DisableFileDeletions() was called + * multiple times before.
+ * + *If force == false, EnableFileDeletions will only + * enable file deletion after it's been called at least + * as many times as DisableFileDeletions(), enabling + * the two methods to be called by two threads + * concurrently without synchronization + * -- i.e., file deletions will be enabled only after both + * threads call EnableFileDeletions()
+ * + * @param force boolean value described above. + * + * @throws RocksDBException thrown if operation was not performed + * successfully. + */ + public void enableFileDeletions(boolean force) + throws RocksDBException { + enableFileDeletions(nativeHandle_, force); + } + /** *Returns an iterator that is positioned at a write-batch containing
* seq_number. If the sequence number is non existent, it returns an iterator
@@ -1753,6 +1800,11 @@ 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 long getLatestSequenceNumber(long handle);
+ private native void disableFileDeletions(long handle)
+ throws RocksDBException;
+ private native void enableFileDeletions(long handle,
+ boolean force) throws RocksDBException;
private native long getUpdatesSince(long handle, long sequenceNumber)
throws RocksDBException;
diff --git a/java/org/rocksdb/test/RocksDBTest.java b/java/org/rocksdb/test/RocksDBTest.java
index a6934b31068fdf149636cd3c32b9ba8f9381a891..15dde9856336acbdf1ed62d97e0a5c1a2697e06f 100644
--- a/java/org/rocksdb/test/RocksDBTest.java
+++ b/java/org/rocksdb/test/RocksDBTest.java
@@ -738,4 +738,25 @@ public class RocksDBTest {
}
}
}
+
+ @Test
+ public void enableDisableFileDeletions() throws RocksDBException {
+ RocksDB db = null;
+ Options options = null;
+ try {
+ options = new Options().setCreateIfMissing(true);
+ db = RocksDB.open(options, dbFolder.getRoot().getAbsolutePath());
+ db.disableFileDeletions();
+ db.enableFileDeletions(false);
+ db.disableFileDeletions();
+ db.enableFileDeletions(true);
+ } finally {
+ if (db != null) {
+ db.close();
+ }
+ if (options != null) {
+ options.dispose();
+ }
+ }
+ }
}
diff --git a/java/org/rocksdb/test/TransactionLogIteratorTest.java b/java/org/rocksdb/test/TransactionLogIteratorTest.java
index 2069e1200d37ffe5a46813bafb70682b4fe18ae9..4e1ee4dfdbef9ef1b068fda128e1f3607db7d60b 100644
--- a/java/org/rocksdb/test/TransactionLogIteratorTest.java
+++ b/java/org/rocksdb/test/TransactionLogIteratorTest.java
@@ -57,6 +57,9 @@ public class TransactionLogIteratorTest {
String.valueOf(i).getBytes());
}
db.flush(new FlushOptions().setWaitForFlush(true));
+
+ assertThat(db.getLatestSequenceNumber()).isEqualTo(250);
+
transactionLogIterator = db.getUpdatesSince(0);
assertThat(transactionLogIterator.isValid()).isTrue();
transactionLogIterator.status();
diff --git a/java/rocksjni/rocksjni.cc b/java/rocksjni/rocksjni.cc
index 9f5b9446e34ad55955d1d1c483bc242be1199779..148c6c7dcf9070f253e3bfcf55253a10371f42c8 100644
--- a/java/rocksjni/rocksjni.cc
+++ b/java/rocksjni/rocksjni.cc
@@ -1601,6 +1601,51 @@ void Java_org_rocksdb_RocksDB_compactRange__J_3BI_3BIZIIJ(
jend, jend_len, jreduce_level, jtarget_level, jtarget_path_id);
}
+//////////////////////////////////////////////////////////////////////////////
+// rocksdb::DB::GetLatestSequenceNumber
+
+/*
+ * Class: org_rocksdb_RocksDB
+ * Method: getLatestSequenceNumber
+ * Signature: (J)V
+ */
+jlong Java_org_rocksdb_RocksDB_getLatestSequenceNumber(JNIEnv* env,
+ jobject jdb, jlong jdb_handle) {
+ auto db = reinterpret_cast