diff --git a/db/c.cc b/db/c.cc index e1af3836e6..68213e48c4 100644 --- a/db/c.cc +++ b/db/c.cc @@ -3363,6 +3363,16 @@ void rocksdb_transactiondb_put(rocksdb_transactiondb_t* txn_db, txn_db->rep->Put(options->rep, Slice(key, klen), Slice(val, vlen))); } +//Write batch into transaction db +void rocksdb_transactiondb_write( + rocksdb_transactiondb_t* db, + const rocksdb_writeoptions_t* options, + rocksdb_writebatch_t* batch, + char** errptr) { + SaveError(errptr, db->rep->Write(options->rep, &batch->rep)); +} + + // Delete a key inside a transaction void rocksdb_transaction_delete(rocksdb_transaction_t* txn, const char* key, size_t klen, char** errptr) { diff --git a/db/c_test.c b/db/c_test.c index 4bdf89bee5..209af13ac7 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -1365,6 +1365,17 @@ int main(int argc, char** argv) { CheckNoError(err); CheckTxnDBGet(txn_db, roptions, "foo", NULL); + // write batch into TransactionDB + rocksdb_writebatch_t* wb = rocksdb_writebatch_create(); + rocksdb_writebatch_put(wb, "foo", 3, "a", 1); + rocksdb_writebatch_clear(wb); + rocksdb_writebatch_put(wb, "bar", 3, "b", 1); + rocksdb_writebatch_put(wb, "box", 3, "c", 1); + rocksdb_writebatch_delete(wb, "bar", 3); + rocksdb_transactiondb_write(txn_db, woptions, wb, &err); + CheckTxnDBGet(txn_db, roptions, "box", "c"); + CheckNoError(err); + // begin a transaction txn = rocksdb_transaction_begin(txn_db, woptions, txn_options, NULL); // put diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index 2d33560390..3d3c175f91 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -1298,6 +1298,10 @@ extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_put( rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options, const char* key, size_t klen, const char* val, size_t vlen, char** errptr); +extern ROCKSDB_LIBRARY_API void rocksdb_transactiondb_write( + rocksdb_transactiondb_t* txn_db, const rocksdb_writeoptions_t* options, + rocksdb_writebatch_t *batch, char** errptr); + extern ROCKSDB_LIBRARY_API void rocksdb_transaction_delete( rocksdb_transaction_t* txn, const char* key, size_t klen, char** errptr);