From 8613ee2e942151b1c90d7d84d2436750c9f84959 Mon Sep 17 00:00:00 2001 From: Maysam Yabandeh Date: Thu, 12 Dec 2019 10:34:52 -0800 Subject: [PATCH] Enable all txn write policies in crash test (#6158) Summary: Currently the default txn write policy in crash tests is WRITE_PREPARED. The patch randomly picks the write policy at the start of the crash test. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6158 Test Plan: ``` make -j32 crash_test_with_txn ``` Differential Revision: D18946307 Pulled By: maysamyabandeh fbshipit-source-id: f77d7a94f99a08791ef9626da153d284bf521950 --- db_stress_tool/db_stress_common.h | 1 + db_stress_tool/db_stress_gflags.cc | 5 +++++ db_stress_tool/db_stress_test_base.cc | 5 +++-- include/rocksdb/utilities/transaction_db.h | 2 -- tools/db_crashtest.py | 2 ++ 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/db_stress_tool/db_stress_common.h b/db_stress_tool/db_stress_common.h index b66cce6df..f4991a4a1 100644 --- a/db_stress_tool/db_stress_common.h +++ b/db_stress_tool/db_stress_common.h @@ -161,6 +161,7 @@ DECLARE_int32(range_deletion_width); DECLARE_uint64(rate_limiter_bytes_per_sec); DECLARE_bool(rate_limit_bg_reads); DECLARE_bool(use_txn); +DECLARE_uint64(txn_write_policy); DECLARE_int32(backup_one_in); DECLARE_int32(checkpoint_one_in); DECLARE_int32(ingest_external_file_one_in); diff --git a/db_stress_tool/db_stress_gflags.cc b/db_stress_tool/db_stress_gflags.cc index 328426fb1..5036be4d5 100644 --- a/db_stress_tool/db_stress_gflags.cc +++ b/db_stress_tool/db_stress_gflags.cc @@ -371,6 +371,11 @@ DEFINE_bool(use_txn, false, "Use TransactionDB. Currently the default write policy is " "TxnDBWritePolicy::WRITE_PREPARED"); +DEFINE_uint64(txn_write_policy, 0, + "The transaction write policy. Default is " + "TxnDBWritePolicy::WRITE_COMMITTED. Note that this should not be " + "changed accross crashes."); + DEFINE_int32(backup_one_in, 0, "If non-zero, then CreateNewBackup() will be called once for " "every N operations on average. 0 indicates CreateNewBackup() " diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 07f3df74a..dd0e3b27a 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -1671,8 +1671,9 @@ void StressTest::Open() { } else { #ifndef ROCKSDB_LITE TransactionDBOptions txn_db_options; - // For the moment it is sufficient to test WRITE_PREPARED policy - txn_db_options.write_policy = TxnDBWritePolicy::WRITE_PREPARED; + assert(FLAGS_txn_write_policy <= TxnDBWritePolicy::WRITE_UNPREPARED); + txn_db_options.write_policy = + static_cast(FLAGS_txn_write_policy); s = TransactionDB::Open(options_, txn_db_options, FLAGS_db, cf_descriptors, &column_families_, &txn_db_); db_ = txn_db_; diff --git a/include/rocksdb/utilities/transaction_db.h b/include/rocksdb/utilities/transaction_db.h index 91a9cec28..d286370fb 100644 --- a/include/rocksdb/utilities/transaction_db.h +++ b/include/rocksdb/utilities/transaction_db.h @@ -25,9 +25,7 @@ class TransactionDBMutexFactory; enum TxnDBWritePolicy { WRITE_COMMITTED = 0, // write only the committed data - // TODO(myabandeh): Not implemented yet WRITE_PREPARED, // write data after the prepare phase of 2pc - // TODO(myabandeh): Not implemented yet WRITE_UNPREPARED // write data before the prepare phase of 2pc }; diff --git a/tools/db_crashtest.py b/tools/db_crashtest.py index e4bd145b1..d96e02b8e 100644 --- a/tools/db_crashtest.py +++ b/tools/db_crashtest.py @@ -159,6 +159,8 @@ cf_consistency_params = { txn_params = { "use_txn" : 1, + # Avoid lambda to set it once for the entire test + "txn_write_policy": random.randint(0, 2), "disable_wal": 0, # OpenReadOnly after checkpoint is not currnetly compatible with WritePrepared txns "checkpoint_one_in": 0,