From 2da53b1e06655792569505796ee3f91bf9bcbfd3 Mon Sep 17 00:00:00 2001 From: Yueh-Hsuan Chiang Date: Thu, 14 Aug 2014 10:58:09 -0700 Subject: [PATCH] [Java] Add purgeOldBackups API Summary: 1. Check status of CreateNewBackup. If status is not OK, then throw. 2. Add purgeOldBackups API Test Plan: make test make sample Reviewers: haobo, sdong, zzbennett, swapnilghike, yhchiang Reviewed By: yhchiang Subscribers: leveldb Differential Revision: https://reviews.facebook.net/D21753 --- java/org/rocksdb/BackupableDB.java | 10 ++++++++++ java/rocksjni/backupablejni.cc | 21 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) 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); + } } ///////////////////////////////////////////////////////////////////////////