diff options
| author | Per Larsson <[email protected]> | 2021-09-03 15:37:19 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-09-03 15:37:19 +0200 |
| commit | c04fa527593da17c719c4d899ec19caeb6480a94 (patch) | |
| tree | fa65fd7585d55712bad546d76a0fc3518023a905 /zenserver/cache/structuredcache.cpp | |
| parent | oops: Fixed AssertException implementation namespace (diff) | |
| download | zen-c04fa527593da17c719c4d899ec19caeb6480a94.tar.xz zen-c04fa527593da17c719c4d899ec19caeb6480a94.zip | |
Zen upstream support (#7)
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index 00b3b545b..0e235a9be 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -149,7 +149,8 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req case kGet: { ZenCacheValue Value; - bool Success = m_CacheStore.Get(Ref.BucketSegment, Ref.HashKey, /* out */ Value); + bool Success = m_CacheStore.Get(Ref.BucketSegment, Ref.HashKey, /* out */ Value); + bool InUpstreamCache = false; if (!Success && m_UpstreamCache) { @@ -159,8 +160,9 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req if (auto UpstreamResult = m_UpstreamCache->GetCacheRecord({Ref.BucketSegment, Ref.HashKey}, CacheRecordType); UpstreamResult.Success) { - Value.Value = UpstreamResult.Value; - Success = true; + Value.Value = UpstreamResult.Value; + Success = true; + InUpstreamCache = true; if (CacheRecordType == ZenContentType::kCbObject) { @@ -215,11 +217,12 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req Request.SetSuppressResponseBody(); } - m_Log.debug("HIT - '{}/{}' ({} bytes, {})", + m_Log.debug("HIT - '{}/{}' ({} bytes {}) ({})", Ref.BucketSegment, Ref.HashKey, Value.Value.Size(), - Value.Value.GetContentType()); + Value.Value.GetContentType(), + InUpstreamCache ? "upstream" : "local"); return Request.WriteResponse(zen::HttpResponse::OK, MapToHttpContentType(Value.Value.GetContentType()), Value.Value); } @@ -267,7 +270,6 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req { auto Result = m_UpstreamCache->EnqueueUpstream( {.Type = ZenContentType::kBinary, .CacheKey = {Ref.BucketSegment, Ref.HashKey}}); - ZEN_ASSERT(Result.Success); } return Request.WriteResponse(zen::HttpResponse::Created); @@ -332,7 +334,6 @@ HttpStructuredCacheService::HandleCacheRecordRequest(zen::HttpServerRequest& Req auto Result = m_UpstreamCache->EnqueueUpstream({.Type = ZenContentType::kCbObject, .CacheKey = {Ref.BucketSegment, Ref.HashKey}, .PayloadIds = std::move(References)}); - ZEN_ASSERT(Result.Success); } return Request.WriteResponse(zen::HttpResponse::Created); @@ -379,18 +380,20 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re case kHead: case kGet: { - zen::IoBuffer Payload = m_CidStore.FindChunkByCid(Ref.PayloadId); + zen::IoBuffer Payload = m_CidStore.FindChunkByCid(Ref.PayloadId); + bool InUpstreamCache = false; if (!Payload && m_UpstreamCache) { if (auto UpstreamResult = m_UpstreamCache->GetCachePayload({{Ref.BucketSegment, Ref.HashKey}, Ref.PayloadId}); UpstreamResult.Success) { - if (zen::CompressedBuffer Compressed = zen::CompressedBuffer::FromCompressed(SharedBuffer(UpstreamResult.Payload))) + if (zen::CompressedBuffer Compressed = zen::CompressedBuffer::FromCompressed(SharedBuffer(UpstreamResult.Value))) { - Payload = UpstreamResult.Payload; + Payload = UpstreamResult.Value; zen::IoHash ChunkHash = zen::IoHash::HashBuffer(Payload); zen::CasStore::InsertResult Result = m_CasStore.InsertChunk(Payload, ChunkHash); + InUpstreamCache = true; m_CidStore.AddCompressedCid(Ref.PayloadId, ChunkHash); } @@ -403,22 +406,17 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re if (!Payload) { - m_Log.debug("MISS - '{}/{}/{}' ({} bytes, {})", - Ref.BucketSegment, - Ref.HashKey, - Ref.PayloadId, - Payload.Size(), - Payload.GetContentType()); - + m_Log.debug("MISS - '{}/{}/{}'", Ref.BucketSegment, Ref.HashKey, Ref.PayloadId); return Request.WriteResponse(zen::HttpResponse::NotFound); } - m_Log.debug("HIT - '{}/{}/{}' ({} bytes, {})", + m_Log.debug("HIT - '{}/{}/{}' ({} bytes, {}) ({})", Ref.BucketSegment, Ref.HashKey, Ref.PayloadId, Payload.Size(), - Payload.GetContentType()); + Payload.GetContentType(), + InUpstreamCache ? "upstream" : "local"); if (Verb == kHead) { |