@ -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)