Add asserts in transaction example (#6055)

Summary:
The intention of the example for read committed is clearer with these added asserts.
Pull Request resolved: https://github.com/facebook/rocksdb/pull/6055

Test Plan: `cd examples && make transaction_example && ./transaction_example`

Differential Revision: D18621830

Pulled By: riversand963

fbshipit-source-id: a94b08c5958b589049409ee4fc4d6799e5cbef79
This commit is contained in:
Cheng Chang 2019-11-20 14:17:16 -08:00 committed by Facebook Github Bot
parent 3cd75736a7
commit c0983d0691

View File

@ -50,17 +50,33 @@ int main() {
// Read a key OUTSIDE this transaction. Does not affect txn.
s = txn_db->Get(read_options, "abc", &value);
assert(s.IsNotFound());
// Write a key OUTSIDE of this transaction.
// Does not affect txn since this is an unrelated key. If we wrote key 'abc'
// here, the transaction would fail to commit.
// Does not affect txn since this is an unrelated key.
s = txn_db->Put(write_options, "xyz", "zzz");
assert(s.ok());
// Write a key OUTSIDE of this transaction.
// Fail because the key conflicts with the key written in txn.
s = txn_db->Put(write_options, "abc", "def");
assert(s.subcode() == Status::kLockTimeout);
// Value for key "xyz" has been committed, can be read in txn.
s = txn->Get(read_options, "xyz", &value);
assert(s.ok());
assert(value == "zzz");
// Commit transaction
s = txn->Commit();
assert(s.ok());
delete txn;
// Value is committed, can be read now.
s = txn_db->Get(read_options, "abc", &value);
assert(s.ok());
assert(value == "def");
////////////////////////////////////////////////////////
//
// "Repeatable Read" (Snapshot Isolation) Example