diff options
| author | Dan Engelbrecht <[email protected]> | 2024-05-02 10:53:15 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-05-02 10:53:15 +0200 |
| commit | 1bafcb32cb48b2256a9d72995388b7df72058039 (patch) | |
| tree | 2385ec3de36c4f45018832eb36bcab6ac2d3670f /src/zenstore/cache/structuredcachestore.cpp | |
| parent | fix get project files loop (#68) (diff) | |
| download | zen-1bafcb32cb48b2256a9d72995388b7df72058039.tar.xz zen-1bafcb32cb48b2256a9d72995388b7df72058039.zip | |
batch cache put (#67)
- Improvement: Batch scope for put of cache values
Diffstat (limited to 'src/zenstore/cache/structuredcachestore.cpp')
| -rw-r--r-- | src/zenstore/cache/structuredcachestore.cpp | 81 |
1 files changed, 69 insertions, 12 deletions
diff --git a/src/zenstore/cache/structuredcachestore.cpp b/src/zenstore/cache/structuredcachestore.cpp index e7524271e..9eded2a50 100644 --- a/src/zenstore/cache/structuredcachestore.cpp +++ b/src/zenstore/cache/structuredcachestore.cpp @@ -137,6 +137,34 @@ ZenCacheNamespace::~ZenCacheNamespace() m_Gc.RemoveGcContributor(this); } +struct ZenCacheNamespace::BatchHandle +{ + ZenCacheDiskLayer::BatchHandle* DiskLayerHandle = nullptr; +}; + +ZenCacheNamespace::BatchHandle* +ZenCacheNamespace::BeginPutBatch(std::vector<bool>& OutResult) +{ + ZenCacheNamespace::BatchHandle* Handle = new ZenCacheNamespace::BatchHandle; + Handle->DiskLayerHandle = m_DiskLayer.BeginPutBatch(OutResult); + return Handle; +} + +void +ZenCacheNamespace::EndPutBatch(BatchHandle* Batch) noexcept +{ + try + { + ZEN_ASSERT(Batch); + m_DiskLayer.EndPutBatch(Batch->DiskLayerHandle); + delete Batch; + } + catch (std::exception& Ex) + { + ZEN_ERROR("Exception in cache namespace layer when ending batch put operation: '{}'", Ex.what()); + } +} + bool ZenCacheNamespace::Get(std::string_view InBucket, const IoHash& HashKey, ZenCacheValue& OutValue) { @@ -160,7 +188,11 @@ ZenCacheNamespace::Get(std::string_view InBucket, const IoHash& HashKey, ZenCach } void -ZenCacheNamespace::Put(std::string_view InBucket, const IoHash& HashKey, const ZenCacheValue& Value, std::span<IoHash> References) +ZenCacheNamespace::Put(std::string_view InBucket, + const IoHash& HashKey, + const ZenCacheValue& Value, + std::span<IoHash> References, + BatchHandle* OptionalBatchHandle) { ZEN_TRACE_CPU("Z$::Namespace::Put"); @@ -170,7 +202,7 @@ ZenCacheNamespace::Put(std::string_view InBucket, const IoHash& HashKey, const Z ZEN_ASSERT(Value.Value.Size()); - m_DiskLayer.Put(InBucket, HashKey, Value, References); + m_DiskLayer.Put(InBucket, HashKey, Value, References, OptionalBatchHandle ? OptionalBatchHandle->DiskLayerHandle : nullptr); m_WriteCount++; } @@ -443,6 +475,31 @@ ZenCacheStore::LogWorker() } } +ZenCacheStore::PutBatch::PutBatch(ZenCacheStore& CacheStore, std::string_view InNamespace, std::vector<bool>& OutResult) +: m_CacheStore(CacheStore) +{ + if (m_Store = m_CacheStore.GetNamespace(InNamespace); m_Store) + { + m_NamespaceBatchHandle = m_Store->BeginPutBatch(OutResult); + } +} + +ZenCacheStore::PutBatch::~PutBatch() +{ + try + { + if (m_Store) + { + ZEN_ASSERT(m_NamespaceBatchHandle); + m_Store->EndPutBatch(m_NamespaceBatchHandle); + } + } + catch (std::exception& Ex) + { + ZEN_ERROR("Exception in cache store when ending batch put operation: '{}'", Ex.what()); + } +} + bool ZenCacheStore::Get(const CacheRequestContext& Context, std::string_view Namespace, @@ -477,8 +534,7 @@ ZenCacheStore::Get(const CacheRequestContext& Context, .Namespace = std::string(Namespace), .Bucket = std::string(Bucket), .HashKey = HashKey, - .Value = OutValue /*, - .Result = Result*/}); + .Value = OutValue}); }); if (Signal) { @@ -511,7 +567,8 @@ ZenCacheStore::Put(const CacheRequestContext& Context, std::string_view Bucket, const IoHash& HashKey, const ZenCacheValue& Value, - std::span<IoHash> References) + std::span<IoHash> References, + PutBatch* OptionalBatchHandle) { // Ad hoc rejection of known bad usage patterns for DDC bucket names @@ -532,12 +589,11 @@ ZenCacheStore::Put(const CacheRequestContext& Context, m_LogQueueLock.WithExclusiveLock([&]() { Signal = m_LogQueue.empty(); m_LogQueue.emplace_back(AccessLogItem{.Op = "PUT ", - .Context = Context, - .Namespace = std::string(Namespace), - .Bucket = std::string(Bucket), - .HashKey = HashKey, - .Value = Value /*, - .Result = true*/}); + .Context = Context, + .Namespace = std::string(Namespace), + .Bucket = std::string(Bucket), + .HashKey = HashKey, + .Value = Value}); }); if (Signal) { @@ -547,7 +603,8 @@ ZenCacheStore::Put(const CacheRequestContext& Context, if (ZenCacheNamespace* Store = GetNamespace(Namespace); Store) { - Store->Put(Bucket, HashKey, Value, References); + ZenCacheNamespace::BatchHandle* BatchHandle = OptionalBatchHandle ? OptionalBatchHandle->m_NamespaceBatchHandle : nullptr; + Store->Put(Bucket, HashKey, Value, References, BatchHandle); m_WriteCount++; return; } |