aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/zenstore/cache/structuredcachestore.cpp89
-rw-r--r--src/zenstore/include/zenstore/cache/structuredcachestore.h24
2 files changed, 41 insertions, 72 deletions
diff --git a/src/zenstore/cache/structuredcachestore.cpp b/src/zenstore/cache/structuredcachestore.cpp
index 97b793083..1cb310026 100644
--- a/src/zenstore/cache/structuredcachestore.cpp
+++ b/src/zenstore/cache/structuredcachestore.cpp
@@ -138,15 +138,23 @@ ZenCacheNamespace::~ZenCacheNamespace()
struct ZenCacheNamespace::PutBatchHandle
{
+ PutBatchHandle(ZenCacheDiskLayer& InDiskLayer, ZenCacheDiskLayer::PutBatchHandle* InDiskLayerHandle)
+ : DiskLayer(InDiskLayer)
+ , DiskLayerHandle(InDiskLayerHandle)
+ {
+ }
+ ~PutBatchHandle() noexcept { DiskLayer.DeletePutBatch(DiskLayerHandle); }
+ PutBatchHandle(const PutBatchHandle&) = delete;
+ PutBatchHandle& operator=(const PutBatchHandle&) = delete;
+
+ ZenCacheDiskLayer& DiskLayer;
ZenCacheDiskLayer::PutBatchHandle* DiskLayerHandle = nullptr;
};
-ZenCacheNamespace::PutBatchHandle*
+std::unique_ptr<ZenCacheNamespace::PutBatchHandle>
ZenCacheNamespace::CreatePutBatch(ZenCachePutResultVec_t& OutResult)
{
- ZenCacheNamespace::PutBatchHandle* Handle = new ZenCacheNamespace::PutBatchHandle;
- Handle->DiskLayerHandle = m_DiskLayer.CreatePutBatch(OutResult);
- return Handle;
+ return std::make_unique<ZenCacheNamespace::PutBatchHandle>(m_DiskLayer, m_DiskLayer.CreatePutBatch(OutResult));
}
void
@@ -156,27 +164,27 @@ ZenCacheNamespace::CommitPutBatch(PutBatchHandle* Batch)
m_DiskLayer.CommitPutBatch(Batch->DiskLayerHandle);
}
-void
-ZenCacheNamespace::DeletePutBatch(PutBatchHandle* Batch) noexcept
-{
- ZEN_ASSERT(Batch);
- m_DiskLayer.DeletePutBatch(Batch->DiskLayerHandle);
- delete Batch;
-}
-
struct ZenCacheNamespace::GetBatchHandle
{
- GetBatchHandle(ZenCacheValueVec_t& OutResult) : Results(OutResult) {}
+ GetBatchHandle(ZenCacheDiskLayer& InDiskLayer, ZenCacheValueVec_t& OutResult, ZenCacheDiskLayer::GetBatchHandle* InDiskLayerHandle)
+ : DiskLayer(InDiskLayer)
+ , Results(OutResult)
+ , DiskLayerHandle(InDiskLayerHandle)
+ {
+ }
+ ~GetBatchHandle() noexcept { DiskLayer.DeleteGetBatch(DiskLayerHandle); }
+ GetBatchHandle(const GetBatchHandle&) = delete;
+ GetBatchHandle& operator=(const GetBatchHandle&) = delete;
+
+ ZenCacheDiskLayer& DiskLayer;
ZenCacheValueVec_t& Results;
ZenCacheDiskLayer::GetBatchHandle* DiskLayerHandle = nullptr;
};
-ZenCacheNamespace::GetBatchHandle*
+std::unique_ptr<ZenCacheNamespace::GetBatchHandle>
ZenCacheNamespace::CreateGetBatch(ZenCacheValueVec_t& OutResult)
{
- ZenCacheNamespace::GetBatchHandle* Handle = new ZenCacheNamespace::GetBatchHandle(OutResult);
- Handle->DiskLayerHandle = m_DiskLayer.CreateGetBatch(OutResult);
- return Handle;
+ return std::make_unique<ZenCacheNamespace::GetBatchHandle>(m_DiskLayer, OutResult, m_DiskLayer.CreateGetBatch(OutResult));
}
void
@@ -200,14 +208,6 @@ ZenCacheNamespace::CommitGetBatch(GetBatchHandle* Batch)
}
}
-void
-ZenCacheNamespace::DeleteGetBatch(GetBatchHandle* Batch) noexcept
-{
- ZEN_ASSERT(Batch);
- m_DiskLayer.DeleteGetBatch(Batch->DiskLayerHandle);
- delete Batch;
-}
-
bool
ZenCacheNamespace::Get(std::string_view InBucket, const IoHash& HashKey, ZenCacheValue& OutValue)
{
@@ -560,25 +560,11 @@ ZenCacheStore::PutBatch::Commit()
{
ZEN_MEMSCOPE(GetCacheStoreTag());
ZEN_ASSERT(m_NamespaceBatchHandle);
- m_Store->CommitPutBatch(m_NamespaceBatchHandle);
+ m_Store->CommitPutBatch(m_NamespaceBatchHandle.get());
}
}
-ZenCacheStore::PutBatch::~PutBatch()
-{
- try
- {
- if (m_Store)
- {
- ZEN_ASSERT(m_NamespaceBatchHandle);
- m_Store->DeletePutBatch(m_NamespaceBatchHandle);
- }
- }
- catch (const std::exception& Ex)
- {
- ZEN_ERROR("Exception in cache store when ending batch put operation: '{}'", Ex.what());
- }
-}
+ZenCacheStore::PutBatch::~PutBatch() = default;
ZenCacheStore::GetBatch::GetBatch(ZenCacheStore& CacheStore, std::string_view InNamespace, ZenCacheValueVec_t& OutResult)
: m_CacheStore(CacheStore)
@@ -598,7 +584,7 @@ ZenCacheStore::GetBatch::Commit()
{
ZEN_MEMSCOPE(GetCacheStoreTag());
ZEN_ASSERT(m_NamespaceBatchHandle);
- m_Store->CommitGetBatch(m_NamespaceBatchHandle);
+ m_Store->CommitGetBatch(m_NamespaceBatchHandle.get());
metrics::RequestStats::Scope OpScope(m_CacheStore.m_GetOps, 0);
for (const ZenCacheValue& Result : Results)
@@ -616,22 +602,7 @@ ZenCacheStore::GetBatch::Commit()
}
}
-ZenCacheStore::GetBatch::~GetBatch()
-{
- try
- {
- if (m_Store)
- {
- ZEN_MEMSCOPE(GetCacheStoreTag());
- ZEN_ASSERT(m_NamespaceBatchHandle);
- m_Store->DeleteGetBatch(m_NamespaceBatchHandle);
- }
- }
- catch (const std::exception& Ex)
- {
- ZEN_ERROR("Exception in cache store when ending batch get operation: '{}'", Ex.what());
- }
-}
+ZenCacheStore::GetBatch::~GetBatch() = default;
bool
ZenCacheStore::Get(const CacheRequestContext& Context,
@@ -776,7 +747,7 @@ ZenCacheStore::Put(const CacheRequestContext& Context,
if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store)
{
- ZenCacheNamespace::PutBatchHandle* BatchHandle = OptionalBatchHandle ? OptionalBatchHandle->m_NamespaceBatchHandle : nullptr;
+ ZenCacheNamespace::PutBatchHandle* BatchHandle = OptionalBatchHandle ? OptionalBatchHandle->m_NamespaceBatchHandle.get() : nullptr;
PutResult RetVal = Store->Put(Bucket, HashKey, Value, References, Overwrite, BatchHandle);
if (RetVal.Status == zen::PutStatus::Success)
{
diff --git a/src/zenstore/include/zenstore/cache/structuredcachestore.h b/src/zenstore/include/zenstore/cache/structuredcachestore.h
index 3722a0d31..16be04ace 100644
--- a/src/zenstore/include/zenstore/cache/structuredcachestore.h
+++ b/src/zenstore/include/zenstore/cache/structuredcachestore.h
@@ -85,14 +85,12 @@ public:
~ZenCacheNamespace();
struct PutBatchHandle;
- PutBatchHandle* CreatePutBatch(ZenCachePutResultVec_t& OutResults);
- void CommitPutBatch(PutBatchHandle* Batch);
- void DeletePutBatch(PutBatchHandle* Batch) noexcept;
+ std::unique_ptr<PutBatchHandle> CreatePutBatch(ZenCachePutResultVec_t& OutResults);
+ void CommitPutBatch(PutBatchHandle* Batch);
struct GetBatchHandle;
- GetBatchHandle* CreateGetBatch(ZenCacheValueVec_t& OutResults);
- void CommitGetBatch(GetBatchHandle* Batch);
- void DeleteGetBatch(GetBatchHandle* Batch) noexcept;
+ std::unique_ptr<GetBatchHandle> CreateGetBatch(ZenCacheValueVec_t& OutResults);
+ void CommitGetBatch(GetBatchHandle* Batch);
bool Get(std::string_view Bucket, const IoHash& HashKey, ZenCacheValue& OutValue);
void Get(std::string_view Bucket, const IoHash& HashKey, GetBatchHandle& OptionalBatchHandle);
@@ -217,9 +215,9 @@ public:
~PutBatch();
private:
- ZenCacheStore& m_CacheStore;
- ZenCacheNamespace* m_Store = nullptr;
- ZenCacheNamespace::PutBatchHandle* m_NamespaceBatchHandle = nullptr;
+ ZenCacheStore& m_CacheStore;
+ ZenCacheNamespace* m_Store = nullptr;
+ std::unique_ptr<ZenCacheNamespace::PutBatchHandle> m_NamespaceBatchHandle;
friend class ZenCacheStore;
};
@@ -232,10 +230,10 @@ public:
~GetBatch();
private:
- ZenCacheStore& m_CacheStore;
- ZenCacheNamespace* m_Store = nullptr;
- ZenCacheNamespace::GetBatchHandle* m_NamespaceBatchHandle = nullptr;
- ZenCacheValueVec_t& Results;
+ ZenCacheStore& m_CacheStore;
+ ZenCacheNamespace* m_Store = nullptr;
+ std::unique_ptr<ZenCacheNamespace::GetBatchHandle> m_NamespaceBatchHandle;
+ ZenCacheValueVec_t& Results;
friend class ZenCacheStore;
};