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
This commit is contained in:
Oleksandr Anyshchenko 2017-09-14 14:04:40 -07:00 committed by Facebook Github Bot
parent 9a970c81af
commit ffac68367f
3 changed files with 33 additions and 0 deletions

View File

@ -3340,6 +3340,14 @@ void rocksdb_transaction_rollback(rocksdb_transaction_t* txn, char** errptr) {
SaveError(errptr, txn->rep->Rollback()); 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) { void rocksdb_transaction_destroy(rocksdb_transaction_t* txn) {
delete txn->rep; delete txn->rep;
delete txn; delete txn;

View File

@ -1463,6 +1463,25 @@ int main(int argc, char** argv) {
CheckNoError(err); CheckNoError(err);
CheckTxnDBGet(txn_db, roptions, "bar", NULL); 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. // Column families.
rocksdb_column_family_handle_t* cfh; rocksdb_column_family_handle_t* cfh;
cfh = rocksdb_transactiondb_create_column_family(txn_db, options, cfh = rocksdb_transactiondb_create_column_family(txn_db, options,

View File

@ -1292,6 +1292,12 @@ extern ROCKSDB_LIBRARY_API void rocksdb_transaction_commit(
extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback( extern ROCKSDB_LIBRARY_API void rocksdb_transaction_rollback(
rocksdb_transaction_t* txn, char** errptr); 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( extern ROCKSDB_LIBRARY_API void rocksdb_transaction_destroy(
rocksdb_transaction_t* txn); rocksdb_transaction_t* txn);