From 01e3c30defeb61a436ede4878c1a908a9439937c Mon Sep 17 00:00:00 2001 From: Manuel Ung Date: Fri, 1 Jun 2018 14:57:55 -0700 Subject: [PATCH] Extend existing unit tests to run with WriteUnprepared as well Summary: As titled. I have not extended the Compatibility tests because the new WAL markers are still unimplemented. Closes https://github.com/facebook/rocksdb/pull/3941 Differential Revision: D8238394 Pulled By: lth fbshipit-source-id: 980e3d44837bbf2cfa64047f9738f559dfac4b1d --- CMakeLists.txt | 1 + Makefile | 5 ++++ TARGETS | 5 ++++ src.mk | 1 + .../pessimistic_transaction_db.cc | 4 ++- utilities/transactions/transaction_test.cc | 15 +++++++--- utilities/transactions/transaction_test.h | 6 ++-- .../write_unprepared_transaction_test.cc | 30 +++++++++++++++++++ 8 files changed, 60 insertions(+), 7 deletions(-) create mode 100644 utilities/transactions/write_unprepared_transaction_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 759c8ab0c..cadb0a8cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -959,6 +959,7 @@ if(WITH_TESTS) utilities/transactions/optimistic_transaction_test.cc utilities/transactions/transaction_test.cc utilities/transactions/write_prepared_transaction_test.cc + utilities/transactions/write_unprepared_transaction_test.cc utilities/ttl/ttl_test.cc utilities/write_batch_with_index/write_batch_with_index_test.cc ) diff --git a/Makefile b/Makefile index 5d0092d11..6882d41c0 100644 --- a/Makefile +++ b/Makefile @@ -518,6 +518,7 @@ TESTS = \ repair_test \ env_timed_test \ write_prepared_transaction_test \ + write_unprepared_transaction_test \ db_universal_compaction_test \ PARALLEL_TEST = \ @@ -537,6 +538,7 @@ PARALLEL_TEST = \ table_test \ transaction_test \ write_prepared_transaction_test \ + write_unprepared_transaction_test \ # options_settable_test doesn't pass with UBSAN as we use hack in the test ifdef COMPILE_WITH_UBSAN @@ -1474,6 +1476,9 @@ transaction_test: utilities/transactions/transaction_test.o $(LIBOBJECTS) $(TEST write_prepared_transaction_test: utilities/transactions/write_prepared_transaction_test.o $(LIBOBJECTS) $(TESTHARNESS) $(AM_LINK) +write_unprepared_transaction_test: utilities/transactions/write_unprepared_transaction_test.o $(LIBOBJECTS) $(TESTHARNESS) + $(AM_LINK) + sst_dump: tools/sst_dump.o $(LIBOBJECTS) $(AM_LINK) diff --git a/TARGETS b/TARGETS index 1abe9b8ff..d130f512b 100644 --- a/TARGETS +++ b/TARGETS @@ -1042,6 +1042,11 @@ ROCKS_TESTS = [ "utilities/transactions/write_prepared_transaction_test.cc", "parallel", ], + [ + "write_unprepared_transaction_test", + "utilities/transactions/write_unprepared_transaction_test.cc", + "parallel", + ], ] # Generate a test rule for each entry in ROCKS_TESTS diff --git a/src.mk b/src.mk index bfe4a1eb5..48958784d 100644 --- a/src.mk +++ b/src.mk @@ -397,6 +397,7 @@ MAIN_SOURCES = \ utilities/transactions/optimistic_transaction_test.cc \ utilities/transactions/transaction_test.cc \ utilities/transactions/write_prepared_transaction_test.cc \ + utilities/transactions/write_unprepared_transaction_test.cc \ utilities/ttl/ttl_test.cc \ utilities/write_batch_with_index/write_batch_with_index_test.cc \ diff --git a/utilities/transactions/pessimistic_transaction_db.cc b/utilities/transactions/pessimistic_transaction_db.cc index 9fc8a8c08..38ac6067c 100644 --- a/utilities/transactions/pessimistic_transaction_db.cc +++ b/utilities/transactions/pessimistic_transaction_db.cc @@ -217,7 +217,9 @@ Status TransactionDB::Open( DBOptions db_options_2pc = db_options; PrepareWrap(&db_options_2pc, &column_families_copy, &compaction_enabled_cf_indices); - const bool use_seq_per_batch = txn_db_options.write_policy == WRITE_PREPARED; + const bool use_seq_per_batch = + txn_db_options.write_policy == WRITE_PREPARED || + txn_db_options.write_policy == WRITE_UNPREPARED; s = DBImpl::Open(db_options_2pc, dbname, column_families_copy, handles, &db, use_seq_per_batch); if (s.ok()) { diff --git a/utilities/transactions/transaction_test.cc b/utilities/transactions/transaction_test.cc index e7bd682ca..85e8bc0fb 100644 --- a/utilities/transactions/transaction_test.cc +++ b/utilities/transactions/transaction_test.cc @@ -45,11 +45,14 @@ INSTANTIATE_TEST_CASE_P( ::testing::Values(std::make_tuple(false, false, WRITE_COMMITTED), std::make_tuple(false, true, WRITE_COMMITTED), std::make_tuple(false, false, WRITE_PREPARED), - std::make_tuple(false, true, WRITE_PREPARED))); + std::make_tuple(false, true, WRITE_PREPARED), + std::make_tuple(false, false, WRITE_UNPREPARED), + std::make_tuple(false, true, WRITE_UNPREPARED))); INSTANTIATE_TEST_CASE_P( StackableDBAsBaseDB, TransactionTest, ::testing::Values(std::make_tuple(true, true, WRITE_COMMITTED), - std::make_tuple(true, true, WRITE_PREPARED))); + std::make_tuple(true, true, WRITE_PREPARED), + std::make_tuple(true, true, WRITE_UNPREPARED))); // MySQLStyleTransactionTest takes far too long for valgrind to run. #ifndef ROCKSDB_VALGRIND_RUN @@ -62,7 +65,11 @@ INSTANTIATE_TEST_CASE_P( std::make_tuple(false, false, WRITE_PREPARED), std::make_tuple(false, true, WRITE_PREPARED), std::make_tuple(true, false, WRITE_PREPARED), - std::make_tuple(true, true, WRITE_PREPARED))); + std::make_tuple(true, true, WRITE_PREPARED), + std::make_tuple(false, false, WRITE_UNPREPARED), + std::make_tuple(false, true, WRITE_UNPREPARED), + std::make_tuple(true, false, WRITE_UNPREPARED), + std::make_tuple(true, true, WRITE_UNPREPARED))); #endif // ROCKSDB_VALGRIND_RUN TEST_P(TransactionTest, DoubleEmptyWrite) { @@ -1779,10 +1786,10 @@ TEST_P(TransactionTest, TwoPhaseLogRollingTest2) { ASSERT_EQ(cfh_a->cfd()->GetLogNumber(), db_impl->TEST_LogfileNumber()); break; case WRITE_PREPARED: + case WRITE_UNPREPARED: // This cf is not flushed yet and should ref the log that has its data ASSERT_EQ(cfh_a->cfd()->GetLogNumber(), prepare_log_no); break; - case WRITE_UNPREPARED: default: assert(false); } diff --git a/utilities/transactions/transaction_test.h b/utilities/transactions/transaction_test.h index d72454750..a4b363c51 100644 --- a/utilities/transactions/transaction_test.h +++ b/utilities/transactions/transaction_test.h @@ -144,7 +144,8 @@ class TransactionTestBase : public ::testing::Test { DB* root_db = nullptr; Options options_copy(options); const bool use_seq_per_batch = - txn_db_options.write_policy == WRITE_PREPARED; + txn_db_options.write_policy == WRITE_PREPARED || + txn_db_options.write_policy == WRITE_UNPREPARED; Status s = DBImpl::Open(options_copy, dbname, cfs, handles, &root_db, use_seq_per_batch); StackableDB* stackable_db = new StackableDB(root_db); @@ -173,7 +174,8 @@ class TransactionTestBase : public ::testing::Test { DB* root_db = nullptr; Options options_copy(options); const bool use_seq_per_batch = - txn_db_options.write_policy == WRITE_PREPARED; + txn_db_options.write_policy == WRITE_PREPARED || + txn_db_options.write_policy == WRITE_UNPREPARED; Status s = DBImpl::Open(options_copy, dbname, column_families, &handles, &root_db, use_seq_per_batch); StackableDB* stackable_db = new StackableDB(root_db); diff --git a/utilities/transactions/write_unprepared_transaction_test.cc b/utilities/transactions/write_unprepared_transaction_test.cc new file mode 100644 index 000000000..96fe9bac9 --- /dev/null +++ b/utilities/transactions/write_unprepared_transaction_test.cc @@ -0,0 +1,30 @@ +// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. +// This source code is licensed under both the GPLv2 (found in the +// COPYING file in the root directory) and Apache 2.0 License +// (found in the LICENSE.Apache file in the root directory). + +#ifndef ROCKSDB_LITE + +#ifndef __STDC_FORMAT_MACROS +#define __STDC_FORMAT_MACROS +#endif + +#include "utilities/transactions/transaction_test.h" + +namespace rocksdb {} // namespace rocksdb + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} + +#else +#include + +int main(int /*argc*/, char** /*argv*/) { + fprintf(stderr, + "SKIPPED as Transactions are not supported in ROCKSDB_LITE\n"); + return 0; +} + +#endif // ROCKSDB_LITE