From 7e98e8a9a5a069cc6885608a20e576a89262438f Mon Sep 17 00:00:00 2001 From: Andrew Chang Date: Wed, 8 Jan 2025 15:40:06 -0800 Subject: [PATCH] Add test_follower flag to crash test --- db_stress_tool/db_stress_common.h | 2 ++ db_stress_tool/db_stress_gflags.cc | 7 +++++++ db_stress_tool/db_stress_stat.cc | 1 + db_stress_tool/db_stress_stat.h | 1 + db_stress_tool/db_stress_test_base.cc | 4 ++++ db_stress_tool/db_stress_tool.cc | 16 ++++++++++++++++ 6 files changed, 31 insertions(+) diff --git a/db_stress_tool/db_stress_common.h b/db_stress_tool/db_stress_common.h index 0c1ef4e11369..d51dd3ab63da 100644 --- a/db_stress_tool/db_stress_common.h +++ b/db_stress_tool/db_stress_common.h @@ -176,7 +176,9 @@ DECLARE_int32(index_type); DECLARE_int32(data_block_index_type); DECLARE_string(db); DECLARE_string(secondaries_base); +DECLARE_string(followers_base); DECLARE_bool(test_secondary); +DECLARE_bool(test_follower); DECLARE_string(expected_values_dir); DECLARE_bool(verify_checksum); DECLARE_bool(mmap_read); diff --git a/db_stress_tool/db_stress_gflags.cc b/db_stress_tool/db_stress_gflags.cc index 1859e6940fb9..42147fb1e10a 100644 --- a/db_stress_tool/db_stress_gflags.cc +++ b/db_stress_tool/db_stress_gflags.cc @@ -618,10 +618,17 @@ DEFINE_string(db, "", "Use the db with the following name."); DEFINE_string(secondaries_base, "", "Use this path as the base path for secondary instances."); +DEFINE_string(followers_base, "", + "Use this path as the base path for follower instances."); + DEFINE_bool(test_secondary, false, "If true, start an additional secondary instance which can be used " "for verification."); +DEFINE_bool(test_follower, false, + "If true, start an additional follower instance which can be used " + "for verification."); + DEFINE_string( expected_values_dir, "", "Dir where files containing info about the latest/historical values will " diff --git a/db_stress_tool/db_stress_stat.cc b/db_stress_tool/db_stress_stat.cc index 6a7883a52ac7..c2e8d127e03f 100644 --- a/db_stress_tool/db_stress_stat.cc +++ b/db_stress_tool/db_stress_stat.cc @@ -11,6 +11,7 @@ namespace ROCKSDB_NAMESPACE { std::shared_ptr dbstats; std::shared_ptr dbstats_secondaries; +std::shared_ptr dbstats_followers; } // namespace ROCKSDB_NAMESPACE diff --git a/db_stress_tool/db_stress_stat.h b/db_stress_tool/db_stress_stat.h index 5b38c6e2bb5d..0eb2463f6fda 100644 --- a/db_stress_tool/db_stress_stat.h +++ b/db_stress_tool/db_stress_stat.h @@ -25,6 +25,7 @@ namespace ROCKSDB_NAMESPACE { // Database statistics extern std::shared_ptr dbstats; extern std::shared_ptr dbstats_secondaries; +extern std::shared_ptr dbstats_followers; class Stats { private: diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 3e4e719a7625..1a5b482cecd0 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -645,6 +645,10 @@ void StressTest::PrintStatistics() { fprintf(stdout, "Secondary instances STATISTICS:\n%s\n", dbstats_secondaries->ToString().c_str()); } + if (dbstats_followers) { + fprintf(stdout, "Follower instances STATISTICS:\n%s\n", + dbstats_followers->ToString().c_str()); + } } // Currently PreloadDb has to be single-threaded. diff --git a/db_stress_tool/db_stress_tool.cc b/db_stress_tool/db_stress_tool.cc index ca43b699c8f9..55b8530b7f6b 100644 --- a/db_stress_tool/db_stress_tool.cc +++ b/db_stress_tool/db_stress_tool.cc @@ -58,6 +58,9 @@ int db_stress_tool(int argc, char** argv) { if (FLAGS_test_secondary) { dbstats_secondaries = ROCKSDB_NAMESPACE::CreateDBStatistics(); } + if (FLAGS_test_follower) { + dbstats_followers = ROCKSDB_NAMESPACE::CreateDBStatistics(); + } } compression_type_e = StringToCompressionType(FLAGS_compression_type.c_str()); bottommost_compression_type_e = @@ -231,6 +234,19 @@ int db_stress_tool(int argc, char** argv) { FLAGS_secondaries_base = default_secondaries_path; } + if (FLAGS_test_follower && FLAGS_followers_base.empty()) { + std::string default_followers_path; + db_stress_env->GetTestDirectory(&default_followers_path); + default_followers_path += "/dbstress_followers"; + s = db_stress_env->CreateDirIfMissing(default_followers_path); + if (!s.ok()) { + fprintf(stderr, "Failed to create directory %s: %s\n", + default_followers_path.c_str(), s.ToString().c_str()); + exit(1); + } + FLAGS_followers_base = default_followers_path; + } + if (FLAGS_best_efforts_recovery && !(FLAGS_skip_verifydb && FLAGS_disable_wal)) { fprintf(stderr,