std::atomic<size_t> expected_commits = {0};
// Without Prepare, the commit does not write to WAL
std::atomic<size_t> with_empty_commits = {0};
- std::function<void(size_t, Status)> txn_t0_with_status = [&](size_t index,
- Status exp_s) {
+ void TestTxn0(size_t index) {
// Test DB's internal txn. It involves no prepare phase nor a commit marker.
- WriteOptions wopts;
- auto s = db->Put(wopts, "key" + std::to_string(index), "value");
- ASSERT_EQ(exp_s, s);
+ auto s = db->Put(WriteOptions(), "key" + std::to_string(index), "value");
+ ASSERT_OK(s);
if (txn_db_options.write_policy == TxnDBWritePolicy::WRITE_COMMITTED) {
// Consume one seq per key
exp_seq++;
}
}
with_empty_commits++;
- };
- std::function<void(size_t)> txn_t0 = [&](size_t index) {
- return txn_t0_with_status(index, Status::OK());
- };
- std::function<void(size_t)> txn_t1 = [&](size_t index) {
+ }
+
+ void TestTxn1(size_t index) {
// Testing directly writing a write batch. Functionality-wise it is
// equivalent to commit without prepare.
WriteBatch wb;
ASSERT_OK(wb.Put("k1" + istr, "v1"));
ASSERT_OK(wb.Put("k2" + istr, "v2"));
ASSERT_OK(wb.Put("k3" + istr, "v3"));
- WriteOptions wopts;
- auto s = db->Write(wopts, &wb);
+ auto s = db->Write(WriteOptions(), &wb);
if (txn_db_options.write_policy == TxnDBWritePolicy::WRITE_COMMITTED) {
// Consume one seq per key
exp_seq += 3;
}
ASSERT_OK(s);
with_empty_commits++;
- };
- std::function<void(size_t)> txn_t2 = [&](size_t index) {
+ }
+
+ void TestTxn2(size_t index) {
// Commit without prepare. It should write to DB without a commit marker.
- TransactionOptions txn_options;
- WriteOptions write_options;
- Transaction* txn = db->BeginTransaction(write_options, txn_options);
+ Transaction* txn =
+ db->BeginTransaction(WriteOptions(), TransactionOptions());
auto istr = std::to_string(index);
ASSERT_OK(txn->SetName("xid" + istr));
ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar")));
}
delete txn;
with_empty_commits++;
- };
- std::function<void(size_t)> txn_t3 = [&](size_t index) {
+ }
+
+ void TestTxn3(size_t index) {
// A full 2pc txn that also involves a commit marker.
- TransactionOptions txn_options;
- WriteOptions write_options;
- Transaction* txn = db->BeginTransaction(write_options, txn_options);
+ Transaction* txn =
+ db->BeginTransaction(WriteOptions(), TransactionOptions());
auto istr = std::to_string(index);
ASSERT_OK(txn->SetName("xid" + istr));
ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar")));
exp_seq++;
}
delete txn;
- };
- std::function<void(size_t)> txn_t4 = [&](size_t index) {
+ }
+
+ void TestTxn4(size_t index) {
// A full 2pc txn that also involves a commit marker.
- TransactionOptions txn_options;
- WriteOptions write_options;
- Transaction* txn = db->BeginTransaction(write_options, txn_options);
+ Transaction* txn =
+ db->BeginTransaction(WriteOptions(), TransactionOptions());
auto istr = std::to_string(index);
ASSERT_OK(txn->SetName("xid" + istr));
ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar")));
}
}
delete txn;
- };
+ }
// Test that we can change write policy after a clean shutdown (which would
// empty the WAL)
size_t d = (n % base[bi + 1]) / base[bi];
switch (d) {
case 0:
- threads.emplace_back(txn_t0, bi);
+ threads.emplace_back(&TransactionTestBase::TestTxn0, this, bi);
break;
case 1:
- threads.emplace_back(txn_t1, bi);
+ threads.emplace_back(&TransactionTestBase::TestTxn1, this, bi);
break;
case 2:
- threads.emplace_back(txn_t2, bi);
+ threads.emplace_back(&TransactionTestBase::TestTxn2, this, bi);
break;
case 3:
- threads.emplace_back(txn_t3, bi);
+ threads.emplace_back(&TransactionTestBase::TestTxn3, this, bi);
break;
case 4:
- threads.emplace_back(txn_t3, bi);
+ threads.emplace_back(&TransactionTestBase::TestTxn3, this, bi);
break;
default:
FAIL();
ASSERT_OK(ReOpen());
WritePreparedTxnDB* wp_db = dynamic_cast<WritePreparedTxnDB*>(db);
- txn_t0(0);
+ TestTxn0(0);
TransactionOptions txn_options;
WriteOptions write_options;
ASSERT_OK(s);
auto prep_seq_0 = txn0->GetId();
- txn_t1(0);
+ TestTxn1(0);
index++;
Transaction* txn1 = db->BeginTransaction(write_options, txn_options);
ASSERT_OK(s);
auto prep_seq_1 = txn1->GetId();
- txn_t2(0);
+ TestTxn2(0);
ReadOptions ropt;
PinnableSlice pinnable_val;
ASSERT_TRUE(s.IsNotFound());
pinnable_val.Reset();
- txn_t3(0);
+ TestTxn3(0);
// Test that a recovered txns will be properly marked committed for the next
// recovery