aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcache.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-24 19:26:40 +0200
committerStefan Boberg <[email protected]>2021-05-24 19:26:40 +0200
commite70e2b4453a27d9d1caf77224ffd6335c50981fb (patch)
tree05d469aa1c3ab6c1840fd4732696c708d1a2a07d /zenserver/cache/structuredcache.cpp
parentValidate payloads using embedded CompressedBuffer hash (diff)
downloadzen-e70e2b4453a27d9d1caf77224ffd6335c50981fb.tar.xz
zen-e70e2b4453a27d9d1caf77224ffd6335c50981fb.zip
Added CidStore, currently used to track relationships between compressed and uncompressed chunk hashes
This first implementation is in-memory only, persistence is next
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
-rw-r--r--zenserver/cache/structuredcache.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index 317c5641a..43364af1d 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -12,6 +12,7 @@
#include "structuredcache.h"
#include "structuredcachestore.h"
#include "upstream/jupiter.h"
+#include "zenstore/cidstore.h"
#include <spdlog/spdlog.h>
#include <filesystem>
@@ -20,9 +21,10 @@ namespace zen {
using namespace std::literals;
-HttpStructuredCacheService::HttpStructuredCacheService(std::filesystem::path RootPath, zen::CasStore& InStore)
+HttpStructuredCacheService::HttpStructuredCacheService(std::filesystem::path RootPath, zen::CasStore& InStore, zen::CidStore& InCidStore)
: m_CasStore(InStore)
, m_CacheStore(InStore, RootPath)
+, m_CidStore(InCidStore)
{
spdlog::info("initializing structured cache at '{}'", RootPath);
@@ -144,7 +146,7 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req
if (!References.empty())
{
zen::CbObjectWriter Idx;
- Idx.BeginArray();
+ Idx.BeginArray("r");
for (const IoHash& Hash : References)
{
@@ -222,7 +224,7 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re
// TODO: need to map from uncompressed content address into the storage
// (compressed) content address
- zen::IoBuffer Payload = m_CasStore.FindChunk(Ref.PayloadId);
+ zen::IoBuffer Payload = m_CidStore.FindChunkByCid(Ref.PayloadId);
if (!Payload)
{
@@ -254,6 +256,8 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re
zen::CasStore::InsertResult Result = m_CasStore.InsertChunk(Body, ChunkHash);
+ m_CidStore.AddCompressedCid(Ref.PayloadId, ChunkHash);
+
if (Result.New)
{
return Request.WriteResponse(zen::HttpResponse::Created);