Skip to content

Commit

Permalink
[Java] Add purgeOldBackups API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
yhchiang committed Aug 14, 2014
1 parent 6c4c159 commit 2da53b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
10 changes: 10 additions & 0 deletions java/org/rocksdb/BackupableDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public static BackupableDB open(
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);
}


/**
Expand Down Expand Up @@ -77,4 +86,5 @@ protected BackupableDB() {

protected native void open(long rocksDBHandle, long backupDBOptionsHandle);
protected native void createNewBackup(long handle, boolean flag);
protected native void purgeOldBackups(long handle, int numBackupsToKeep);
}
21 changes: 20 additions & 1 deletion java/rocksjni/backupablejni.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<rocksdb::BackupableDB*>(jhandle)->CreateNewBackup(jflag);
rocksdb::Status s =
reinterpret_cast<rocksdb::BackupableDB*>(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<rocksdb::BackupableDB*>(jhandle)->
PurgeOldBackups(jnumBackupsToKeep);
if (!s.ok()) {
rocksdb::RocksDBExceptionJni::ThrowNew(env, s);
}
}

///////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 2da53b1

Please sign in to comment.