From e4ddf04d04f39b2e319ce30b1570a78d0bfa7173 Mon Sep 17 00:00:00 2001 From: Gregory Wlodarek Date: Thu, 11 May 2023 15:42:39 +0000 Subject: SERVER-77029 Set syncdelay in TestOplogTruncation before starting the checkpoint thread --- src/mongo/db/storage/checkpointer.cpp | 4 +++ .../wiredtiger/wiredtiger_kv_engine_test.cpp | 33 +++++++++------------- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/mongo/db/storage/checkpointer.cpp b/src/mongo/db/storage/checkpointer.cpp index 6b633075ae7..b3d249e1837 100644 --- a/src/mongo/db/storage/checkpointer.cpp +++ b/src/mongo/db/storage/checkpointer.cpp @@ -87,6 +87,10 @@ void Checkpointer::run() { // Wait for 'storageGlobalParams.syncdelay' seconds; or until either shutdown is // signaled or a checkpoint is triggered. + LOGV2_DEBUG(7702900, + 1, + "Checkpoint thread sleeping", + "duration"_attr = static_cast(storageGlobalParams.syncdelay)); _sleepCV.wait_for( lock, stdx::chrono::seconds(static_cast(storageGlobalParams.syncdelay)), diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp index 5f7da06d557..18f8fa87b96 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine_test.cpp @@ -282,29 +282,25 @@ TEST_F(WiredTigerKVEngineTest, TestOplogTruncation) { auto severityGuard = unittest::MinimumLoggedSeverityGuard{logv2::LogComponent::kStorage, logv2::LogSeverity::Debug(3)}; + // Set syncdelay before starting the checkpoint thread, otherwise it can observe the default + // checkpoint frequency of 60 seconds, causing the test to fail due to a 10 second timeout. + storageGlobalParams.syncdelay.store(1); + std::unique_ptr checkpointer = std::make_unique(); checkpointer->go(); + // If the test fails we want to ensure the checkpoint thread shuts down to avoid accessing the + // storage engine during shutdown. + ON_BLOCK_EXIT([&] { + checkpointer->shutdown({ErrorCodes::ShutdownInProgress, "Test finished"}); + }); + auto opCtxPtr = _makeOperationContext(); // The initial data timestamp has to be set to take stable checkpoints. The first stable // timestamp greater than this will also trigger a checkpoint. The following loop of the // CheckpointThread will observe the new `syncdelay` value. _helper.getWiredTigerKVEngine()->setInitialDataTimestamp(Timestamp(1, 1)); - - // Ignore data race on this variable when running with TSAN, this is only an issue in this - // unittest and not in mongod - []() -#if defined(__has_feature) -#if __has_feature(thread_sanitizer) - __attribute__((no_sanitize("thread"))) -#endif -#endif - { - storageGlobalParams.syncdelay = 1; - } - (); - // Simulate the callback that queries config.transactions for the oldest active transaction. boost::optional oldestActiveTxnTimestamp; AtomicWord callbackShouldFail{false}; @@ -344,10 +340,9 @@ TEST_F(WiredTigerKVEngineTest, TestOplogTruncation) { } LOGV2(22367, - "Expected the pinned oplog to advance. Expected value: {newPinned} Published value: " - "{engine_getOplogNeededForCrashRecovery}", - "newPinned"_attr = newPinned, - "engine_getOplogNeededForCrashRecovery"_attr = + "Expected the pinned oplog to advance.", + "expectedValue"_attr = newPinned, + "publishedValue"_attr = _helper.getWiredTigerKVEngine()->getOplogNeededForCrashRecovery()); FAIL(""); }; @@ -378,8 +373,6 @@ TEST_F(WiredTigerKVEngineTest, TestOplogTruncation) { _helper.getWiredTigerKVEngine()->setStableTimestamp(Timestamp(30, 1), false); callbackShouldFail.store(false); assertPinnedMovesSoon(Timestamp(40, 1)); - - checkpointer->shutdown({ErrorCodes::ShutdownInProgress, "Test finished"}); } TEST_F(WiredTigerKVEngineTest, IdentDrop) { -- cgit v1.2.1