diff options
| author | Dan Engelbrecht <[email protected]> | 2022-05-06 12:12:09 +0200 |
|---|---|---|
| committer | Dan Engelbrecht <[email protected]> | 2022-05-06 12:12:09 +0200 |
| commit | 6db10b5a491297d45c14efae453c420f0d7fa58c (patch) | |
| tree | 0006cf2d58168d596bb948219c77f1122c5b3140 /zenserver/cache/structuredcachestore.cpp | |
| parent | Added GetDirectoryContent utility (diff) | |
| download | zen-6db10b5a491297d45c14efae453c420f0d7fa58c.tar.xz zen-6db10b5a491297d45c14efae453c420f0d7fa58c.zip | |
review feedback and cleanup
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
| -rw-r--r-- | zenserver/cache/structuredcachestore.cpp | 81 |
1 files changed, 36 insertions, 45 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp index da48253e2..3ac319961 100644 --- a/zenserver/cache/structuredcachestore.cpp +++ b/zenserver/cache/structuredcachestore.cpp @@ -2109,7 +2109,12 @@ ZenCacheStore::ZenCacheStore(CasGc& Gc, std::filesystem::path BasePath) : GcStor { std::filesystem::path LegacyFolder = BasePath / DirName; std::filesystem::path NewPath = DefaultNamespaceFolder / DirName; - std::filesystem::rename(LegacyFolder, NewPath); + std::error_code Ec; + std::filesystem::rename(LegacyFolder, NewPath, Ec); + if (Ec) + { + ZEN_ERROR("Unable to move '{}' to '{}', reason '{}'", LegacyFolder, NewPath, Ec.message()); + } } Namespaces.push_back(std::string(DefaultNamespace)); } @@ -2129,54 +2134,45 @@ ZenCacheStore::~ZenCacheStore() bool ZenCacheStore::Get(std::string_view Namespace, std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue) { - Ref<ZenCacheNamespace> Store = GetStore(Namespace); - if (!Store) + if (Ref<ZenCacheNamespace> Store = GetStore(Namespace); Store) { - return false; + return Store->Get(Bucket, HashKey, OutValue); } - return Store->Get(Bucket, HashKey, OutValue); + ZEN_WARN("request for unknown namespace '{}' in ZenCacheStore::Get, bucket '{}', key '{}'", Namespace, Bucket, HashKey.ToHexString()); + return false; } void ZenCacheStore::Put(std::string_view Namespace, std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value) { - Ref<ZenCacheNamespace> Store = GetStore(std::string(Namespace)); - if (!Store) + if (Ref<ZenCacheNamespace> Store = GetStore(Namespace); Store) { - return; + return Store->Put(Bucket, HashKey, Value); } - Store->Put(Bucket, HashKey, Value); + ZEN_WARN("request for unknown namespace '{}' in ZenCacheStore::Put, bucket '{}', key '{}'", Namespace, Bucket, HashKey.ToHexString()); } bool ZenCacheStore::DropBucket(std::string_view Namespace, std::string_view Bucket) { - Ref<ZenCacheNamespace> Store = GetStore(std::string(Namespace)); - if (!Store) + if (Ref<ZenCacheNamespace> Store = GetStore(Namespace); Store) { - return false; + return Store->DropBucket(Bucket); } - return Store->DropBucket(Bucket); + ZEN_WARN("request for unknown namespace '{}' in ZenCacheStore::Put, bucket '{}'", Namespace, Bucket); + return false; } void ZenCacheStore::Flush() { - std::vector<Ref<ZenCacheNamespace>> Stores = GetAllStores(); - for (const Ref<ZenCacheNamespace>& Store : Stores) - { - Store->Flush(); - } + IterateStores([&](const Ref<ZenCacheNamespace>& Store) { Store->Flush(); }); } void ZenCacheStore::Scrub(ScrubContext& Ctx) { - std::vector<Ref<ZenCacheNamespace>> Stores = GetAllStores(); - for (const Ref<ZenCacheNamespace>& Store : Stores) - { - Store->Scrub(Ctx); - } + IterateStores([&](const Ref<ZenCacheNamespace>& Store) { Store->Scrub(Ctx); }); } Ref<ZenCacheNamespace> @@ -2190,50 +2186,45 @@ ZenCacheStore::GetStore(std::string_view Namespace) return nullptr; } -std::vector<Ref<ZenCacheNamespace>> -ZenCacheStore::GetAllStores() const +void +ZenCacheStore::IterateStores(const std::function<void(const Ref<ZenCacheNamespace>& Store)>& Callback) const { std::vector<Ref<ZenCacheNamespace>> Stores; - RwLock::SharedLockScope _(m_NamespacesLock); - Stores.reserve(m_Namespaces.size()); - for (const auto& Entry : m_Namespaces) { - Stores.push_back(Entry.second); + RwLock::SharedLockScope _(m_NamespacesLock); + Stores.reserve(m_Namespaces.size()); + for (const auto& Entry : m_Namespaces) + { + Stores.push_back(Entry.second); + } + } + for (const Ref<ZenCacheNamespace>& Store : Stores) + { + Callback(Store); } - return Stores; } void ZenCacheStore::GatherReferences(GcContext& GcCtx) { - std::vector<Ref<ZenCacheNamespace>> Stores = GetAllStores(); - for (const Ref<ZenCacheNamespace>& Store : Stores) - { - Store->GatherReferences(GcCtx); - } + IterateStores([&](const Ref<ZenCacheNamespace>& Store) { Store->GatherReferences(GcCtx); }); } void ZenCacheStore::CollectGarbage(GcContext& GcCtx) { - std::vector<Ref<ZenCacheNamespace>> Stores = GetAllStores(); - for (const Ref<ZenCacheNamespace>& Store : Stores) - { - Store->CollectGarbage(GcCtx); - } + IterateStores([&](const Ref<ZenCacheNamespace>& Store) { Store->CollectGarbage(GcCtx); }); } GcStorageSize ZenCacheStore::StorageSize() const { - std::vector<Ref<ZenCacheNamespace>> Stores = GetAllStores(); - GcStorageSize Size; - for (const Ref<ZenCacheNamespace>& Store : Stores) - { + GcStorageSize Size; + IterateStores([&](const Ref<ZenCacheNamespace>& Store) { GcStorageSize StoreSize = Store->StorageSize(); Size.MemorySize += StoreSize.MemorySize; Size.DiskSize += StoreSize.DiskSize; - } + }); return Size; } |