mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 10:25:47 +02:00
chore: change Namespaces to be a global pointer (#4032)
* chore: change Namespaces to be a global pointer Before the namespaces object was defined globally. However it has non-trivial d'tor that is being called after main exits. It's quite dangerous to have global non-POD objects being defined globally. For example, if we used LOG(INFO) inside the Clear function , that would crash dragonfly on exit. Ths PR changes it to be a global pointer. --------- Signed-off-by: Roman Gershman <roman@dragonflydb.io>
This commit is contained in:
parent
9366c67464
commit
be96e6cf99
22 changed files with 76 additions and 71 deletions
|
@ -103,7 +103,10 @@ EngineShardSet* shard_set = nullptr;
|
|||
|
||||
void EngineShardSet::Init(uint32_t sz, std::function<void()> shard_handler) {
|
||||
CHECK_EQ(0u, size());
|
||||
CHECK(namespaces == nullptr);
|
||||
|
||||
shards_.reset(new EngineShard*[sz]);
|
||||
|
||||
size_ = sz;
|
||||
size_t max_shard_file_size = GetTieredFileLimit(sz);
|
||||
pp_->AwaitFiberOnAll([this](uint32_t index, ProactorBase* pb) {
|
||||
|
@ -112,7 +115,8 @@ void EngineShardSet::Init(uint32_t sz, std::function<void()> shard_handler) {
|
|||
}
|
||||
});
|
||||
|
||||
namespaces.Init();
|
||||
// The order is important here. We must initialize namespaces after shards_.
|
||||
namespaces = new Namespaces();
|
||||
|
||||
pp_->AwaitFiberOnAll([&](uint32_t index, ProactorBase* pb) {
|
||||
if (index < size_) {
|
||||
|
@ -139,7 +143,13 @@ void EngineShardSet::PreShutdown() {
|
|||
}
|
||||
|
||||
void EngineShardSet::Shutdown() {
|
||||
// Calling Namespaces::Clear before destroying engine shards, because it accesses them
|
||||
// internally.
|
||||
namespaces->Clear();
|
||||
RunBlockingInParallel([](EngineShard*) { EngineShard::DestroyThreadLocal(); });
|
||||
|
||||
delete namespaces;
|
||||
namespaces = nullptr;
|
||||
}
|
||||
|
||||
void EngineShardSet::InitThreadLocal(ProactorBase* pb) {
|
||||
|
@ -150,7 +160,7 @@ void EngineShardSet::InitThreadLocal(ProactorBase* pb) {
|
|||
|
||||
void EngineShardSet::TEST_EnableCacheMode() {
|
||||
RunBlockingInParallel([](EngineShard* shard) {
|
||||
namespaces.GetDefaultNamespace().GetCurrentDbSlice().TEST_EnableCacheMode();
|
||||
namespaces->GetDefaultNamespace().GetCurrentDbSlice().TEST_EnableCacheMode();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue