aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcachestore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-05-05 09:55:09 +0200
committerDan Engelbrecht <[email protected]>2022-05-05 09:55:09 +0200
commit861a92d1ee6c54eeb9035190501baf8ea888591f (patch)
tree89407d8946d6fcd1f3fa01766e62f15be24c0b95 /zenserver/cache/structuredcachestore.cpp
parentcleanup (diff)
downloadzen-861a92d1ee6c54eeb9035190501baf8ea888591f.tar.xz
zen-861a92d1ee6c54eeb9035190501baf8ea888591f.zip
cleanup and review feedback
Diffstat (limited to 'zenserver/cache/structuredcachestore.cpp')
-rw-r--r--zenserver/cache/structuredcachestore.cpp33
1 files changed, 13 insertions, 20 deletions
diff --git a/zenserver/cache/structuredcachestore.cpp b/zenserver/cache/structuredcachestore.cpp
index 075b7d408..7db18a7bb 100644
--- a/zenserver/cache/structuredcachestore.cpp
+++ b/zenserver/cache/structuredcachestore.cpp
@@ -2100,7 +2100,7 @@ ZenCacheDiskLayer::TotalSize() const
//////////////////////////// ZenCacheStore
-const char* ZenCacheNamespaceDirPrefix = "ns_";
+static constexpr std::string_view ZenCacheNamespaceDirPrefix = "ns_";
namespace {
@@ -2146,10 +2146,10 @@ ZenCacheStore::ZenCacheStore(std::filesystem::path BasePath, CasGc& Gc) : GcStor
ZEN_INFO("Found #{} namespaces in '{}' and #{} legacy buckets", Namespaces.size(), BasePath, LegacyBuckets.size());
- if (std::find(Namespaces.begin(), Namespaces.end(), "") == Namespaces.end())
+ if (std::find(Namespaces.begin(), Namespaces.end(), DefaultNamespace) == Namespaces.end())
{
ZEN_INFO("Moving #{} legacy buckets to anonymous namespace", LegacyBuckets.size());
- std::filesystem::path DefaultNamespaceFolder = BasePath / ZenCacheNamespaceDirPrefix;
+ std::filesystem::path DefaultNamespaceFolder = BasePath / fmt::format("{}{}", ZenCacheNamespaceDirPrefix, DefaultNamespace);
CreateDirectories(DefaultNamespaceFolder);
// Move any non-namespace folders into the default namespace folder
@@ -2159,12 +2159,12 @@ ZenCacheStore::ZenCacheStore(std::filesystem::path BasePath, CasGc& Gc) : GcStor
std::filesystem::path NewPath = DefaultNamespaceFolder / DirName;
std::filesystem::rename(LegacyFolder, NewPath);
}
- Namespaces.push_back("");
+ Namespaces.push_back(std::string(DefaultNamespace));
}
for (const std::string& NamespaceName : Namespaces)
{
- Ref<ZenCacheNamespace> Store = new ZenCacheNamespace(Gc, BasePath / (ZenCacheNamespaceDirPrefix + NamespaceName));
+ Ref<ZenCacheNamespace> Store = new ZenCacheNamespace(Gc, BasePath / fmt::format("{}{}", ZenCacheNamespaceDirPrefix, NamespaceName));
m_Namespaces[NamespaceName] = Store;
}
}
@@ -2175,7 +2175,7 @@ ZenCacheStore::~ZenCacheStore()
}
bool
-ZenCacheStore::Get(const std::string& Namespace, std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue)
+ZenCacheStore::Get(std::string_view Namespace, std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue)
{
Ref<ZenCacheNamespace> Store = GetStore(Namespace);
if (!Store)
@@ -2186,9 +2186,9 @@ ZenCacheStore::Get(const std::string& Namespace, std::string_view Bucket, const
}
void
-ZenCacheStore::Put(const std::string& Namespace, std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value)
+ZenCacheStore::Put(std::string_view Namespace, std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value)
{
- Ref<ZenCacheNamespace> Store = GetStore(Namespace);
+ Ref<ZenCacheNamespace> Store = GetStore(std::string(Namespace));
if (!Store)
{
return;
@@ -2197,9 +2197,9 @@ ZenCacheStore::Put(const std::string& Namespace, std::string_view Bucket, const
}
bool
-ZenCacheStore::DropBucket(const std::string& Namespace, std::string_view Bucket)
+ZenCacheStore::DropBucket(std::string_view Namespace, std::string_view Bucket)
{
- Ref<ZenCacheNamespace> Store = GetStore(Namespace);
+ Ref<ZenCacheNamespace> Store = GetStore(std::string(Namespace));
if (!Store)
{
return false;
@@ -2210,14 +2210,7 @@ ZenCacheStore::DropBucket(const std::string& Namespace, std::string_view Bucket)
void
ZenCacheStore::Flush()
{
- 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);
- }
- _.ReleaseNow();
+ std::vector<Ref<ZenCacheNamespace>> Stores = GetAllStores();
for (const Ref<ZenCacheNamespace>& Store : Stores)
{
Store->Flush();
@@ -2235,10 +2228,10 @@ ZenCacheStore::Scrub(ScrubContext& Ctx)
}
Ref<ZenCacheNamespace>
-ZenCacheStore::GetStore(const std::string& Namespace)
+ZenCacheStore::GetStore(std::string_view Namespace)
{
RwLock::SharedLockScope _(m_NamespacesLock);
- if (auto It = m_Namespaces.find(Namespace); It != m_Namespaces.end())
+ if (auto It = m_Namespaces.find(std::string(Namespace)); It != m_Namespaces.end())
{
return It->second;
}