diff options
| author | mattpetersepic <[email protected]> | 2022-02-18 13:59:27 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-18 13:59:27 -0700 |
| commit | b0310f0da356fb9a5e9202f1352cad82e3811b10 (patch) | |
| tree | a406be9d25ee35f8d1920e8fbc4f6d632ea4de96 /zenserver/cache/structuredcache.cpp | |
| parent | remote_build: allow path .zips are copied to to be overriden (diff) | |
| download | zen-b0310f0da356fb9a5e9202f1352cad82e3811b10.tar.xz zen-b0310f0da356fb9a5e9202f1352cad82e3811b10.zip | |
Value propagation fix - Read/Write ValueAPI as CompressedBinary type when writing to zen and horde upstreams. Return failure from HandleGetCacheRecord if the requested type does not match the cachetype. (#55)
* Fix bug with getting values PUT to Jupiter as CompressedBinary. When getting CompressedBinary records from Jupiter, they are expected to now be a record with a reference to the compact binary. This has to be accounted for when performing upstream GETs.
* HandleGetCacheRecord: avoid crashing on invalid type, and avoid sending back data that doesn't match the AcceptType.
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
| -rw-r--r-- | zenserver/cache/structuredcache.cpp | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index 25077d92a..8ae531720 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -227,44 +227,60 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request if (EnumHasAllFlags(PolicyFromURL, CachePolicy::QueryLocal) && m_CacheStore.Get(Ref.BucketSegment, Ref.HashKey, ClientResultValue)) { - Success = true; + Success = true; + ZenContentType ContentType = ClientResultValue.Value.GetContentType(); if (AcceptType == ZenContentType::kCbPackage) { - CbPackage Package; - uint32_t MissingCount = 0; + if (ContentType == ZenContentType::kCbObject) + { + CbPackage Package; + uint32_t MissingCount = 0; - CbObjectView CacheRecord(ClientResultValue.Value.Data()); - CacheRecord.IterateAttachments([this, &MissingCount, &Package, SkipData](CbFieldView AttachmentHash) { - if (SkipData) - { - MissingCount += m_CidStore.ContainsChunk(AttachmentHash.AsHash()) ? 0 : 1; - } - else - { - if (IoBuffer Chunk = m_CidStore.FindChunkByCid(AttachmentHash.AsHash())) + CbObjectView CacheRecord(ClientResultValue.Value.Data()); + CacheRecord.IterateAttachments([this, &MissingCount, &Package, SkipData](CbFieldView AttachmentHash) { + if (SkipData) { - Package.AddAttachment(CbAttachment(CompressedBuffer::FromCompressed(SharedBuffer(Chunk)))); + if (!m_CidStore.ContainsChunk(AttachmentHash.AsHash())) + { + MissingCount++; + } } else { - MissingCount++; + if (IoBuffer Chunk = m_CidStore.FindChunkByCid(AttachmentHash.AsHash())) + { + Package.AddAttachment(CbAttachment(CompressedBuffer::FromCompressed(SharedBuffer(Chunk)))); + } + else + { + MissingCount++; + } } - } - }); + }); - Success = MissingCount == 0 || PartialRecord; + Success = MissingCount == 0 || PartialRecord; - if (Success) - { - Package.SetObject(LoadCompactBinaryObject(ClientResultValue.Value)); + if (Success) + { + Package.SetObject(LoadCompactBinaryObject(ClientResultValue.Value)); - BinaryWriter MemStream; - Package.Save(MemStream); + BinaryWriter MemStream; + Package.Save(MemStream); - ClientResultValue.Value = IoBuffer(IoBuffer::Clone, MemStream.Data(), MemStream.Size()); - ClientResultValue.Value.SetContentType(HttpContentType::kCbPackage); + ClientResultValue.Value = IoBuffer(IoBuffer::Clone, MemStream.Data(), MemStream.Size()); + ClientResultValue.Value.SetContentType(HttpContentType::kCbPackage); + } } + else + { + Success = false; + } + } + else if (AcceptType != ClientResultValue.Value.GetContentType() && AcceptType != ZenContentType::kUnknownContentType && + AcceptType != ZenContentType::kBinary) + { + Success = false; } } @@ -277,13 +293,13 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request ToString(ClientResultValue.Value.GetContentType())); m_CacheStats.HitCount++; - if (SkipData && AcceptType == ZenContentType::kBinary) + if (SkipData && AcceptType != ZenContentType::kCbPackage && AcceptType != ZenContentType::kCbObject) { return Request.WriteResponse(HttpResponseCode::OK); } else { - // Other types handled SkipData when constructing the ClientResultValue + // kCbPackage handled SkipData when constructing the ClientResultValue, kcbObject ignores SkipData return Request.WriteResponse(HttpResponseCode::OK, ClientResultValue.Value.GetContentType(), ClientResultValue.Value); } } @@ -1462,7 +1478,8 @@ HttpStructuredCacheService::HandleRpcGetCacheValues(zen::HttpServerRequest& Http } if (!Result && EnumHasAllFlags(Policy, CachePolicy::QueryRemote)) { - GetUpstreamCacheResult UpstreamResult = m_UpstreamCache.GetCacheRecord({Key.Bucket, Key.Hash}, ZenContentType::kBinary); + GetUpstreamCacheResult UpstreamResult = + m_UpstreamCache.GetCacheRecord({Key.Bucket, Key.Hash}, ZenContentType::kCompressedBinary); if (UpstreamResult.Success && IsCompressedBinary(UpstreamResult.Value.GetContentType())) { Result = CompressedBuffer::FromCompressed(SharedBuffer(UpstreamResult.Value)); |