aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-09-13 12:03:27 +0200
committerGitHub <[email protected]>2023-09-13 12:03:27 +0200
commitcaf171abc24c20206eb8ecaff4b6e9137cb9e871 (patch)
tree00ad62f2e829e6cb4608a4d70c6c4104b21315ce /src
parentincremental oplog upload for block-based targets (#392) (diff)
downloadzen-caf171abc24c20206eb8ecaff4b6e9137cb9e871.tar.xz
zen-caf171abc24c20206eb8ecaff4b6e9137cb9e871.zip
ZenCacheStore is now reference counted (#398)
this change also adds a GetNamespaces function which may be used to enumerate all currently known cache namespaces
Diffstat (limited to 'src')
-rw-r--r--src/zencore/include/zencore/refcount.h1
-rw-r--r--src/zenserver/cache/structuredcachestore.cpp10
-rw-r--r--src/zenserver/cache/structuredcachestore.h5
-rw-r--r--src/zenserver/zenserver.cpp13
4 files changed, 20 insertions, 9 deletions
diff --git a/src/zencore/include/zencore/refcount.h b/src/zencore/include/zencore/refcount.h
index f0bb6b85e..74a8f3ac0 100644
--- a/src/zencore/include/zencore/refcount.h
+++ b/src/zencore/include/zencore/refcount.h
@@ -141,6 +141,7 @@ public:
[[nodiscard]] inline bool IsNull() const { return m_Ref == nullptr; }
inline explicit operator bool() const { return m_Ref != nullptr; }
inline T* operator->() const { return m_Ref; }
+ inline T& operator*() const { return *m_Ref; }
inline T* Get() const { return m_Ref; }
inline std::strong_ordering operator<=>(const Ref& Rhs) const = default;
diff --git a/src/zenserver/cache/structuredcachestore.cpp b/src/zenserver/cache/structuredcachestore.cpp
index 1f284863d..56e83eef2 100644
--- a/src/zenserver/cache/structuredcachestore.cpp
+++ b/src/zenserver/cache/structuredcachestore.cpp
@@ -536,6 +536,16 @@ ZenCacheStore::FindNamespace(std::string_view Namespace) const
return nullptr;
}
+std::vector<std::string>
+ZenCacheStore::GetNamespaces()
+{
+ std::vector<std::string> Namespaces;
+
+ IterateNamespaces([&](std::string_view Namespace, ZenCacheNamespace&) { Namespaces.push_back(std::string(Namespace)); });
+
+ return Namespaces;
+}
+
void
ZenCacheStore::IterateNamespaces(const std::function<void(std::string_view Namespace, ZenCacheNamespace& Store)>& Callback) const
{
diff --git a/src/zenserver/cache/structuredcachestore.h b/src/zenserver/cache/structuredcachestore.h
index 067cfc0bf..05b60da34 100644
--- a/src/zenserver/cache/structuredcachestore.h
+++ b/src/zenserver/cache/structuredcachestore.h
@@ -102,11 +102,11 @@ private:
/** Cache store interface
- This manages a set of namespaces used for caching purposes.
+ This manages a set of namespaces used for derived data caching purposes.
*/
-class ZenCacheStore final
+class ZenCacheStore final : public RefCounted
{
public:
static constexpr std::string_view DefaultNamespace =
@@ -157,6 +157,7 @@ public:
Info GetInfo() const;
std::optional<ZenCacheNamespace::Info> GetNamespaceInfo(std::string_view Namespace);
std::optional<ZenCacheNamespace::BucketInfo> GetBucketInfo(std::string_view Namespace, std::string_view Bucket);
+ std::vector<std::string> GetNamespaces();
private:
const ZenCacheNamespace* FindNamespace(std::string_view Namespace) const;
diff --git a/src/zenserver/zenserver.cpp b/src/zenserver/zenserver.cpp
index b8831476d..cfc4a228b 100644
--- a/src/zenserver/zenserver.cpp
+++ b/src/zenserver/zenserver.cpp
@@ -722,7 +722,7 @@ private:
zen::GcManager m_GcManager;
zen::GcScheduler m_GcScheduler{m_GcManager};
std::unique_ptr<zen::CidStore> m_CidStore;
- std::unique_ptr<zen::ZenCacheStore> m_CacheStore;
+ Ref<zen::ZenCacheStore> m_CacheStore;
zen::HttpTestService m_TestService;
#if ZEN_WITH_TESTS
zen::HttpTestingService m_TestingService;
@@ -870,12 +870,11 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
using namespace std::literals;
ZEN_INFO("instantiating structured cache service");
- m_CacheStore =
- std::make_unique<ZenCacheStore>(m_GcManager,
- ZenCacheStore::Configuration{.BasePath = m_DataRoot / "cache",
- .AllowAutomaticCreationOfNamespaces = true,
- .EnableWriteLog = ServerOptions.StructuredCacheWriteLogEnabled,
- .EnableAccessLog = ServerOptions.StructuredCacheAccessLogEnabled});
+ m_CacheStore = new ZenCacheStore(m_GcManager,
+ ZenCacheStore::Configuration{.BasePath = m_DataRoot / "cache",
+ .AllowAutomaticCreationOfNamespaces = true,
+ .EnableWriteLog = ServerOptions.StructuredCacheWriteLogEnabled,
+ .EnableAccessLog = ServerOptions.StructuredCacheAccessLogEnabled});
const ZenUpstreamCacheConfig& UpstreamConfig = ServerOptions.UpstreamCacheConfig;