diff --git a/java/org/rocksdb/BackupableDB.java b/java/org/rocksdb/BackupableDB.java index 90d4a2a9a..108c4deb5 100644 --- a/java/org/rocksdb/BackupableDB.java +++ b/java/org/rocksdb/BackupableDB.java @@ -47,6 +47,15 @@ public class BackupableDB extends RocksDB { public void createNewBackup(boolean flushBeforeBackup) { createNewBackup(nativeHandle_, flushBeforeBackup); } + + /** + * Deletes old backups, keeping latest numBackupsToKeep alive. + * + * @param numBackupsToKeep Number of latest backups to keep. + */ + public void purgeOldBackups(int numBackupsToKeep) { + purgeOldBackups(nativeHandle_, numBackupsToKeep); + } /** @@ -77,4 +86,5 @@ public class BackupableDB extends RocksDB { protected native void open(long rocksDBHandle, long backupDBOptionsHandle); protected native void createNewBackup(long handle, boolean flag); + protected native void purgeOldBackups(long handle, int numBackupsToKeep); } diff --git a/java/rocksjni/backupablejni.cc b/java/rocksjni/backupablejni.cc index 8413d5ea2..2aa1d0b1d 100644 --- a/java/rocksjni/backupablejni.cc +++ b/java/rocksjni/backupablejni.cc @@ -40,7 +40,26 @@ void Java_org_rocksdb_BackupableDB_open( */ void Java_org_rocksdb_BackupableDB_createNewBackup( JNIEnv* env, jobject jbdb, jlong jhandle, jboolean jflag) { - reinterpret_cast(jhandle)->CreateNewBackup(jflag); + rocksdb::Status s = + reinterpret_cast(jhandle)->CreateNewBackup(jflag); + if (!s.ok()) { + rocksdb::RocksDBExceptionJni::ThrowNew(env, s); + } +} + +/* + * Class: org_rocksdb_BackupableDB + * Method: purgeOldBackups + * Signature: (JI)V + */ +void Java_org_rocksdb_BackupableDB_purgeOldBackups( + JNIEnv* env, jobject jbdb, jlong jhandle, jboolean jnumBackupsToKeep) { + rocksdb::Status s = + reinterpret_cast(jhandle)-> + PurgeOldBackups(jnumBackupsToKeep); + if (!s.ok()) { + rocksdb::RocksDBExceptionJni::ThrowNew(env, s); + } } ///////////////////////////////////////////////////////////////////////////