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
This commit is contained in:
Andrew Kryczka 2018-06-04 15:52:31 -07:00 committed by Facebook Github Bot
parent ab2254bedf
commit 2210152947
2 changed files with 4 additions and 0 deletions

1
env/env_posix.cc vendored
View File

@ -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;
}

View File

@ -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