From ffac68367fb5c6fcc6fbd22c3555d227a2b77695 Mon Sep 17 00:00:00 2001 From: Oleksandr Anyshchenko Date: Thu, 14 Sep 2017 14:04:40 -0700 Subject: [PATCH] Added save points for transactions C API Summary: Added possibility to set save points in transactions and then rollback to them Closes https://github.com/facebook/rocksdb/pull/2876 Differential Revision: D5825829 Pulled By: yiwu-arbug fbshipit-source-id: 62168992340bbcddecdaea3baa2a678475d1429d --- db/c.cc | 8 ++++++++ db/c_test.c | 19 +++++++++++++++++++ include/rocksdb/c.h | 6 ++++++ 3 files changed, 33 insertions(+) diff --git a/db/c.cc b/db/c.cc index 76829cc09..65e79c01f 100644 --- a/db/c.cc +++ b/db/c.cc @@ -3340,6 +3340,14 @@ void rocksdb_transaction_rollback(rocksdb_transaction_t* txn, char** errptr) { SaveError(errptr, txn->rep->Rollback()); } +void rocksdb_transaction_set_savepoint(rocksdb_transaction_t* txn) { + txn->rep->SetSavePoint(); +} + +void rocksdb_transaction_rollback_to_savepoint(rocksdb_transaction_t* txn, char** errptr) { + SaveError(errptr, txn->rep->RollbackToSavePoint()); +} + void rocksdb_transaction_destroy(rocksdb_transaction_t* txn) { delete txn->rep; delete txn; diff --git a/db/c_test.c b/db/c_test.c index ecec090e0..594199cba 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -1463,6 +1463,25 @@ int main(int argc, char** argv) { CheckNoError(err); CheckTxnDBGet(txn_db, roptions, "bar", NULL); + // save point + rocksdb_transaction_put(txn, "foo1", 4, "hi1", 3, &err); + rocksdb_transaction_set_savepoint(txn); + CheckTxnGet(txn, roptions, "foo1", "hi1"); + rocksdb_transaction_put(txn, "foo2", 4, "hi2", 3, &err); + CheckTxnGet(txn, roptions, "foo2", "hi2"); + + // rollback to savepoint + rocksdb_transaction_rollback_to_savepoint(txn, &err); + CheckNoError(err); + CheckTxnGet(txn, roptions, "foo2", NULL); + CheckTxnGet(txn, roptions, "foo1", "hi1"); + CheckTxnDBGet(txn_db, roptions, "foo1", NULL); + CheckTxnDBGet(txn_db, roptions, "foo2", NULL); + rocksdb_transaction_commit(txn, &err); + CheckNoError(err); + CheckTxnDBGet(txn_db, roptions, "foo1", "hi1"); + CheckTxnDBGet(txn_db, roptions, "foo2", NULL); + // Column families. rocksdb_column_family_handle_t* cfh; cfh = rocksdb_transactiondb_create_column_family(txn_db, options, diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index d413d2eba..0b1dc3db4 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -1292,6 +1292,12 @@ extern ROCKSDB_LIBRARY_API void rocksdb_transaction_commit( extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback( rocksdb_transaction_t* txn, char** errptr); +extern ROCKSDB_LIBRARY_API void rocksdb_transaction_set_savepoint( + rocksdb_transaction_t* txn); + +extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback_to_savepoint( + rocksdb_transaction_t* txn, char** errptr); + extern ROCKSDB_LIBRARY_API void rocksdb_transaction_destroy( rocksdb_transaction_t* txn);