From f89dea4fec99b582626bf210f938e653e20d4dc7 Mon Sep 17 00:00:00 2001 From: Zhichao Cao Date: Fri, 20 Dec 2019 12:05:48 -0800 Subject: [PATCH] db_stress: Added the verification for GetLiveFiles, GetSortedWalFiles and GetCurrentWalFile (#6224) Summary: Add the verification in operateDB to verify GetLiveFiles, GetSortedWalFiles and GetCurrentWalFile. The test will be called every 1 out of N, N is decided by get_live_files_and_wal_files_one_i, whose default is 1000000. Pull Request resolved: https://github.com/facebook/rocksdb/pull/6224 Test Plan: pass db_stress default run. Differential Revision: D19183358 Pulled By: zhichao-cao fbshipit-source-id: 20073cf72ede77a3e0d3cf5f28304f1f605d2b1a --- db_stress_tool/db_stress_common.h | 1 + db_stress_tool/db_stress_gflags.cc | 5 ++++ db_stress_tool/db_stress_test_base.cc | 39 +++++++++++++++++++++++++++ db_stress_tool/db_stress_test_base.h | 4 ++- tools/db_crashtest.py | 1 + 5 files changed, 49 insertions(+), 1 deletion(-) diff --git a/db_stress_tool/db_stress_common.h b/db_stress_tool/db_stress_common.h index e13c874aa..ad187cb80 100644 --- a/db_stress_tool/db_stress_common.h +++ b/db_stress_tool/db_stress_common.h @@ -125,6 +125,7 @@ DECLARE_int32(universal_min_merge_width); DECLARE_int32(universal_max_merge_width); DECLARE_int32(universal_max_size_amplification_percent); DECLARE_int32(clear_column_family_one_in); +DECLARE_int32(get_live_files_and_wal_files_one_in); DECLARE_int32(set_options_one_in); DECLARE_int32(set_in_place_one_in); DECLARE_int64(cache_size); diff --git a/db_stress_tool/db_stress_gflags.cc b/db_stress_tool/db_stress_gflags.cc index d776f60b1..c104cd64d 100644 --- a/db_stress_tool/db_stress_gflags.cc +++ b/db_stress_tool/db_stress_gflags.cc @@ -239,6 +239,11 @@ DEFINE_int32(clear_column_family_one_in, 1000000, "it again. If N == 0, never drop/create column families. " "When test_batches_snapshots is true, this flag has no effect"); +DEFINE_int32(get_live_files_and_wal_files_one_in, 1000000, + "With a chance of 1/N, call GetLiveFiles, GetSortedWalFiles " + "and GetCurrentWalFile to verify if it returns correctly. If " + "N == 0, never call the three interfaces."); + DEFINE_int32(set_options_one_in, 0, "With a chance of 1/N, change some random options"); diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 7ce45b46b..55a705e86 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -581,6 +581,19 @@ void StressTest::OperateDb(ThreadState* thread) { } } +#ifndef ROCKSDB_LITE + // Every 1 in N verify the one of the following: 1) GetLiveFiles + // 2) GetSortedWalFiles 3) GetCurrentWalFile. Each time, randomly select + // one of them to run the test. + if (thread->rand.OneInOpt(FLAGS_get_live_files_and_wal_files_one_in)) { + Status status = VerifyGetLiveAndWalFiles(thread); + if (!status.ok()) { + VerificationAbort(shared, "VerifyGetLiveAndWalFiles status not OK", + status); + } + } +#endif // !ROCKSDB_LITE + if (thread->rand.OneInOpt(FLAGS_pause_background_one_in)) { Status status = TestPauseBackground(thread); if (!status.ok()) { @@ -890,6 +903,32 @@ Status StressTest::TestIterate(ThreadState* thread, return s; } +#ifndef ROCKSDB_LITE +// Test the return status of GetLiveFiles, GetSortedWalFiles, and +// GetCurrentWalFile. Each time, randomly select one of them to run +// and return the status. +Status StressTest::VerifyGetLiveAndWalFiles(ThreadState* thread) { + int case_num = thread->rand.Uniform(3); + if (case_num == 0) { + std::vector live_file; + uint64_t manifest_size; + return db_->GetLiveFiles(live_file, &manifest_size); + } + + if (case_num == 1) { + VectorLogPtr log_ptr; + return db_->GetSortedWalFiles(log_ptr); + } + + if (case_num == 2) { + std::unique_ptr cur_wal_file; + return db_->GetCurrentWalFile(&cur_wal_file); + } + assert(false); + return Status::Corruption("Undefined case happens!"); +} +#endif // !ROCKSDB_LITE + // Compare the two iterator, iter and cmp_iter are in the same position, // unless iter might be made invalidate or undefined because of // upper or lower bounds, or prefix extractor. diff --git a/db_stress_tool/db_stress_test_base.h b/db_stress_tool/db_stress_test_base.h index c46e53657..886732454 100644 --- a/db_stress_tool/db_stress_test_base.h +++ b/db_stress_tool/db_stress_test_base.h @@ -173,7 +173,9 @@ class StressTest { const std::string& keystr, uint64_t i); Status MaybeReleaseSnapshots(ThreadState* thread, uint64_t i); - +#ifndef ROCKSDB_LITE + Status VerifyGetLiveAndWalFiles(ThreadState* thread); +#endif // !ROCKSDB_LITE void VerificationAbort(SharedState* shared, std::string msg, Status s) const; void VerificationAbort(SharedState* shared, std::string msg, int cf, diff --git a/tools/db_crashtest.py b/tools/db_crashtest.py index 413650035..c1f653fb1 100644 --- a/tools/db_crashtest.py +++ b/tools/db_crashtest.py @@ -46,6 +46,7 @@ default_params = { "enable_pipelined_write": lambda: random.randint(0, 1), "expected_values_path": expected_values_file.name, "flush_one_in": 1000000, + "get_live_files_and_wal_files_one_in": 1000000, # Temporarily disable hash index "index_type": lambda: random.choice([0,2]), "max_background_compactions": 20,