From 1da4b88dd5a49ef9821bd476980226b39859e793 Mon Sep 17 00:00:00 2001 From: Yuchen Kou Date: Tue, 1 Sep 2026 14:27:12 +0800 Subject: [PATCH] [Store] Fix snapshot test eviction race --- .../snapshot/master_service_test_for_snapshot_base.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/mooncake-store/tests/ha/snapshot/master_service_test_for_snapshot_base.h b/mooncake-store/tests/ha/snapshot/master_service_test_for_snapshot_base.h index 48659096c4..d0bd912094 100644 --- a/mooncake-store/tests/ha/snapshot/master_service_test_for_snapshot_base.h +++ b/mooncake-store/tests/ha/snapshot/master_service_test_for_snapshot_base.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -165,6 +166,8 @@ class MasterServiceSnapshotTestBase : public ::testing::Test { // private members static tl::expected CallPersistState( MasterService* service, const std::string& snapshot_id) { + std::unique_lock snapshot_lock( + service->snapshot_mutex_); // If snapshot_manager_ exists, use it; otherwise create a temporary one if (service->snapshot_manager_) { return service->snapshot_manager_->PersistState(snapshot_id); @@ -827,6 +830,15 @@ class MasterServiceSnapshotTestBase : public ::testing::Test { << "Use 'service_.reset(new MasterService(...))' instead of " "'std::unique_ptr service_(...)'"; + // Freeze the original service before snapshot/restore validation. The + // eviction worker can otherwise mutate replica metadata while the + // snapshot is being serialized, making the post-restore comparison + // compare two different points in time. + service_->eviction_running_ = false; + if (service_->eviction_thread_.joinable()) { + service_->eviction_thread_.join(); + } + // Some test configs may not enable snapshot/restore, so the backend // is not created in the constructor. We create it here for TearDown // validation.