From 2210152947b5264c8d614bb1ea8fdfaad7101411 Mon Sep 17 00:00:00 2001 From: Andrew Kryczka Date: Mon, 4 Jun 2018 15:52:31 -0700 Subject: [PATCH] Fix singleton destruction order of PosixEnv and SyncPoint (#3951) Summary: Ensure the PosixEnv singleton is destroyed first since its destructor waits for background threads to all complete. This ensures background threads cannot hit sync points after the SyncPoint singleton is destroyed, which was previously possible. Closes https://github.com/facebook/rocksdb/pull/3951 Differential Revision: D8265295 Pulled By: ajkr fbshipit-source-id: 7738dd458c5d993a78377dd0420e82badada81ab --- env/env_posix.cc | 1 + util/sync_point.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/env/env_posix.cc b/env/env_posix.cc index e04eb5bf4..eac184f80 100644 --- a/env/env_posix.cc +++ b/env/env_posix.cc @@ -1057,6 +1057,7 @@ Env* Env::Default() { // the destructor of static PosixEnv will go first, then the // the singletons of ThreadLocalPtr. ThreadLocalPtr::InitSingletons(); + INIT_SYNC_POINT_SINGLETONS(); static PosixEnv default_env; return &default_env; } diff --git a/util/sync_point.h b/util/sync_point.h index c85be9a48..cb4b1e717 100644 --- a/util/sync_point.h +++ b/util/sync_point.h @@ -45,6 +45,7 @@ extern void TestKillRandom(std::string kill_point, int odds, #define TEST_SYNC_POINT(x) #define TEST_IDX_SYNC_POINT(x, index) #define TEST_SYNC_POINT_CALLBACK(x, y) +#define INIT_SYNC_POINT_SINGLETONS() #else namespace rocksdb { @@ -134,4 +135,6 @@ class SyncPoint { rocksdb::SyncPoint::GetInstance()->Process(x + std::to_string(index)) #define TEST_SYNC_POINT_CALLBACK(x, y) \ rocksdb::SyncPoint::GetInstance()->Process(x, y) +#define INIT_SYNC_POINT_SINGLETONS() \ + (void)rocksdb::SyncPoint::GetInstance(); #endif // NDEBUG