Replace member variable lambda with methods (#10924)

Summary:
In transaction unit tests, replace a few member variable lambdas with
non-static methods. It's easier for gdb to work with variables in methods than in lambdas.
(Seen similar things to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86675).

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10924

Test Plan: make check

Reviewed By: jay-zhuang

Differential Revision: D41072241

Pulled By: riversand963

fbshipit-source-id: e4fa491de573c4656225a86a75af926c1df827f6
main
Yanqin Jin 2 years ago committed by Facebook GitHub Bot
parent aa0a11e1b9
commit 75aca74017
  1. 12
      utilities/transactions/transaction_test.cc
  2. 51
      utilities/transactions/transaction_test.h
  3. 18
      utilities/transactions/write_prepared_transaction_test.cc

@ -5619,7 +5619,7 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) {
size_t branch = 0; size_t branch = 0;
auto seq = db_impl->GetLatestSequenceNumber(); auto seq = db_impl->GetLatestSequenceNumber();
exp_seq = seq; exp_seq = seq;
txn_t0(0); TestTxn0(0);
seq = db_impl->TEST_GetLastVisibleSequence(); seq = db_impl->TEST_GetLastVisibleSequence();
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);
@ -5637,11 +5637,11 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) {
} }
// Doing it twice might detect some bugs // Doing it twice might detect some bugs
txn_t0(1); TestTxn0(1);
seq = db_impl->TEST_GetLastVisibleSequence(); seq = db_impl->TEST_GetLastVisibleSequence();
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);
txn_t1(0); TestTxn1(0);
seq = db_impl->TEST_GetLastVisibleSequence(); seq = db_impl->TEST_GetLastVisibleSequence();
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);
@ -5658,7 +5658,7 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) {
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);
} }
txn_t3(0); TestTxn3(0);
seq = db_impl->TEST_GetLastVisibleSequence(); seq = db_impl->TEST_GetLastVisibleSequence();
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);
@ -5675,7 +5675,7 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) {
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);
} }
txn_t4(0); TestTxn4(0);
seq = db_impl->TEST_GetLastVisibleSequence(); seq = db_impl->TEST_GetLastVisibleSequence();
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);
@ -5693,7 +5693,7 @@ TEST_P(TransactionStressTest, SeqAdvanceTest) {
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);
} }
txn_t2(0); TestTxn2(0);
seq = db_impl->TEST_GetLastVisibleSequence(); seq = db_impl->TEST_GetLastVisibleSequence();
ASSERT_EQ(exp_seq, seq); ASSERT_EQ(exp_seq, seq);

@ -223,12 +223,10 @@ class TransactionTestBase : public ::testing::Test {
std::atomic<size_t> expected_commits = {0}; std::atomic<size_t> expected_commits = {0};
// Without Prepare, the commit does not write to WAL // Without Prepare, the commit does not write to WAL
std::atomic<size_t> with_empty_commits = {0}; std::atomic<size_t> with_empty_commits = {0};
std::function<void(size_t, Status)> txn_t0_with_status = [&](size_t index, void TestTxn0(size_t index) {
Status exp_s) {
// Test DB's internal txn. It involves no prepare phase nor a commit marker. // Test DB's internal txn. It involves no prepare phase nor a commit marker.
WriteOptions wopts; auto s = db->Put(WriteOptions(), "key" + std::to_string(index), "value");
auto s = db->Put(wopts, "key" + std::to_string(index), "value"); ASSERT_OK(s);
ASSERT_EQ(exp_s, s);
if (txn_db_options.write_policy == TxnDBWritePolicy::WRITE_COMMITTED) { if (txn_db_options.write_policy == TxnDBWritePolicy::WRITE_COMMITTED) {
// Consume one seq per key // Consume one seq per key
exp_seq++; exp_seq++;
@ -241,11 +239,9 @@ class TransactionTestBase : public ::testing::Test {
} }
} }
with_empty_commits++; with_empty_commits++;
}; }
std::function<void(size_t)> txn_t0 = [&](size_t index) {
return txn_t0_with_status(index, Status::OK()); void TestTxn1(size_t index) {
};
std::function<void(size_t)> txn_t1 = [&](size_t index) {
// Testing directly writing a write batch. Functionality-wise it is // Testing directly writing a write batch. Functionality-wise it is
// equivalent to commit without prepare. // equivalent to commit without prepare.
WriteBatch wb; WriteBatch wb;
@ -253,8 +249,7 @@ class TransactionTestBase : public ::testing::Test {
ASSERT_OK(wb.Put("k1" + istr, "v1")); ASSERT_OK(wb.Put("k1" + istr, "v1"));
ASSERT_OK(wb.Put("k2" + istr, "v2")); ASSERT_OK(wb.Put("k2" + istr, "v2"));
ASSERT_OK(wb.Put("k3" + istr, "v3")); ASSERT_OK(wb.Put("k3" + istr, "v3"));
WriteOptions wopts; auto s = db->Write(WriteOptions(), &wb);
auto s = db->Write(wopts, &wb);
if (txn_db_options.write_policy == TxnDBWritePolicy::WRITE_COMMITTED) { if (txn_db_options.write_policy == TxnDBWritePolicy::WRITE_COMMITTED) {
// Consume one seq per key // Consume one seq per key
exp_seq += 3; exp_seq += 3;
@ -268,12 +263,12 @@ class TransactionTestBase : public ::testing::Test {
} }
ASSERT_OK(s); ASSERT_OK(s);
with_empty_commits++; 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. // Commit without prepare. It should write to DB without a commit marker.
TransactionOptions txn_options; Transaction* txn =
WriteOptions write_options; db->BeginTransaction(WriteOptions(), TransactionOptions());
Transaction* txn = db->BeginTransaction(write_options, txn_options);
auto istr = std::to_string(index); auto istr = std::to_string(index);
ASSERT_OK(txn->SetName("xid" + istr)); ASSERT_OK(txn->SetName("xid" + istr));
ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar"))); ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar")));
@ -301,12 +296,12 @@ class TransactionTestBase : public ::testing::Test {
} }
delete txn; delete txn;
with_empty_commits++; 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. // A full 2pc txn that also involves a commit marker.
TransactionOptions txn_options; Transaction* txn =
WriteOptions write_options; db->BeginTransaction(WriteOptions(), TransactionOptions());
Transaction* txn = db->BeginTransaction(write_options, txn_options);
auto istr = std::to_string(index); auto istr = std::to_string(index);
ASSERT_OK(txn->SetName("xid" + istr)); ASSERT_OK(txn->SetName("xid" + istr));
ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar"))); ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar")));
@ -334,12 +329,12 @@ class TransactionTestBase : public ::testing::Test {
exp_seq++; exp_seq++;
} }
delete txn; 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. // A full 2pc txn that also involves a commit marker.
TransactionOptions txn_options; Transaction* txn =
WriteOptions write_options; db->BeginTransaction(WriteOptions(), TransactionOptions());
Transaction* txn = db->BeginTransaction(write_options, txn_options);
auto istr = std::to_string(index); auto istr = std::to_string(index);
ASSERT_OK(txn->SetName("xid" + istr)); ASSERT_OK(txn->SetName("xid" + istr));
ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar"))); ASSERT_OK(txn->Put(Slice("foo" + istr), Slice("bar")));
@ -375,7 +370,7 @@ class TransactionTestBase : public ::testing::Test {
} }
} }
delete txn; delete txn;
}; }
// Test that we can change write policy after a clean shutdown (which would // Test that we can change write policy after a clean shutdown (which would
// empty the WAL) // empty the WAL)

@ -1714,19 +1714,19 @@ TEST_P(SeqAdvanceConcurrentTest, SeqAdvanceConcurrent) {
size_t d = (n % base[bi + 1]) / base[bi]; size_t d = (n % base[bi + 1]) / base[bi];
switch (d) { switch (d) {
case 0: case 0:
threads.emplace_back(txn_t0, bi); threads.emplace_back(&TransactionTestBase::TestTxn0, this, bi);
break; break;
case 1: case 1:
threads.emplace_back(txn_t1, bi); threads.emplace_back(&TransactionTestBase::TestTxn1, this, bi);
break; break;
case 2: case 2:
threads.emplace_back(txn_t2, bi); threads.emplace_back(&TransactionTestBase::TestTxn2, this, bi);
break; break;
case 3: case 3:
threads.emplace_back(txn_t3, bi); threads.emplace_back(&TransactionTestBase::TestTxn3, this, bi);
break; break;
case 4: case 4:
threads.emplace_back(txn_t3, bi); threads.emplace_back(&TransactionTestBase::TestTxn3, this, bi);
break; break;
default: default:
FAIL(); FAIL();
@ -1794,7 +1794,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecovery) {
ASSERT_OK(ReOpen()); ASSERT_OK(ReOpen());
WritePreparedTxnDB* wp_db = dynamic_cast<WritePreparedTxnDB*>(db); WritePreparedTxnDB* wp_db = dynamic_cast<WritePreparedTxnDB*>(db);
txn_t0(0); TestTxn0(0);
TransactionOptions txn_options; TransactionOptions txn_options;
WriteOptions write_options; WriteOptions write_options;
@ -1809,7 +1809,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecovery) {
ASSERT_OK(s); ASSERT_OK(s);
auto prep_seq_0 = txn0->GetId(); auto prep_seq_0 = txn0->GetId();
txn_t1(0); TestTxn1(0);
index++; index++;
Transaction* txn1 = db->BeginTransaction(write_options, txn_options); Transaction* txn1 = db->BeginTransaction(write_options, txn_options);
@ -1822,7 +1822,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecovery) {
ASSERT_OK(s); ASSERT_OK(s);
auto prep_seq_1 = txn1->GetId(); auto prep_seq_1 = txn1->GetId();
txn_t2(0); TestTxn2(0);
ReadOptions ropt; ReadOptions ropt;
PinnableSlice pinnable_val; PinnableSlice pinnable_val;
@ -1858,7 +1858,7 @@ TEST_P(WritePreparedTransactionTest, BasicRecovery) {
ASSERT_TRUE(s.IsNotFound()); ASSERT_TRUE(s.IsNotFound());
pinnable_val.Reset(); pinnable_val.Reset();
txn_t3(0); TestTxn3(0);
// Test that a recovered txns will be properly marked committed for the next // Test that a recovered txns will be properly marked committed for the next
// recovery // recovery

Loading…
Cancel
Save