From 7f3a0f5bc6f4aeb4a41265d3812671985e9e36ca Mon Sep 17 00:00:00 2001 From: sdong Date: Wed, 5 May 2021 16:40:45 -0700 Subject: [PATCH] db_stress: wait for compaction to finish after open with failure injection (#8270) Summary: When injecting in DB open, error can happen in background threads, causing DB open succeed, but DB is soon made read-only and subsequence writes will fail, which is not expected. To prevent it from happening, wait for compaction to finish before serving the traffic. If there is a failure, reopen. Pull Request resolved: https://github.com/facebook/rocksdb/pull/8270 Test Plan: Run the test. Reviewed By: ajkr Differential Revision: D28230537 fbshipit-source-id: e2e97888904f9b9bb50c35ccf95b88c2319ef5c3 --- db_stress_tool/db_stress_test_base.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/db_stress_tool/db_stress_test_base.cc b/db_stress_tool/db_stress_test_base.cc index 9cc602e8b..f5eb3c8dc 100644 --- a/db_stress_tool/db_stress_test_base.cc +++ b/db_stress_tool/db_stress_test_base.cc @@ -2468,6 +2468,16 @@ void StressTest::Open() { #ifndef NDEBUG if (ingest_meta_error) { fault_fs_guard->DisableMetadataWriteErrorInjection(); + if (s.ok()) { + // Ingested errors might happen in background compactions. We + // wait for all compactions to finish to make sure DB is in + // clean state before executing queries. + s = static_cast_with_check(db_->GetRootDB()) + ->TEST_WaitForCompact(true); + if (!s.ok()) { + delete db_; + } + } if (!s.ok()) { // After failure to opening a DB due to IO error, retry should // successfully open the DB with correct data if no IO error shows