From 976ef2f4ea785bfe43a765a3c8604afc61342bb1 Mon Sep 17 00:00:00 2001 From: mattpetersepic <58296718+mattpetersepic@users.noreply.github.com> Date: Tue, 8 Feb 2022 20:44:35 -0700 Subject: =?UTF-8?q?Remove=20the=20backwards=20compatibility=20for=20the=20?= =?UTF-8?q?Zen=20CachePolicy=20changes=20no=E2=80=A6=20(#49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the backwards compatibility for the Zen CachePolicy changes now that there has been enough time for all internal users of the old protocol to update. --- zenserver/cache/structuredcache.cpp | 246 +++++------------------------------- 1 file changed, 32 insertions(+), 214 deletions(-) (limited to 'zenserver/cache/structuredcache.cpp') diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index 49e5896d1..e23030e24 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -996,155 +996,9 @@ HttpStructuredCacheService::PutCacheRecord(PutRequestData& Request, const CbPack return PutResult::Success; } -#if BACKWARDS_COMPATABILITY_JAN2022 -void -HttpStructuredCacheService::HandleRpcGetCacheRecordsLegacy(zen::HttpServerRequest& Request, CbObjectView RpcRequest) -{ - ZEN_TRACE_CPU("Z$::RpcGetCacheRecords"); - - CbPackage RpcResponse; - CbObjectView Params = RpcRequest["Params"sv].AsObjectView(); - CacheRecordPolicy BatchPolicy = LoadCacheRecordPolicy(Params["Policy"sv].AsObjectView()); - std::vector CacheKeys; - std::vector CacheValues; - std::vector UpstreamRequests; - - ZEN_ASSERT(RpcRequest["Method"sv].AsString() == "GetCacheRecords"sv); - - for (CbFieldView KeyView : Params["CacheKeys"sv]) - { - CbObjectView KeyObject = KeyView.AsObjectView(); - CacheKeys.push_back(CacheKey::Create(KeyObject["Bucket"sv].AsString(), KeyObject["Hash"sv].AsHash())); - } - - if (CacheKeys.empty()) - { - return Request.WriteResponse(HttpResponseCode::BadRequest); - } - - CacheValues.resize(CacheKeys.size()); - - for (size_t KeyIndex = 0; const CacheKey& Key : CacheKeys) - { - ZenCacheValue CacheValue; - uint32_t MissingCount = 0; - uint32_t MissingReadFromUpstreamCount = 0; - - if (EnumHasAllFlags(BatchPolicy.GetRecordPolicy(), CachePolicy::QueryLocal) && m_CacheStore.Get(Key.Bucket, Key.Hash, CacheValue) && - CacheValue.Value.GetContentType() == ZenContentType::kCbObject) - { - CbObjectView CacheRecord(CacheValue.Value.Data()); - CacheRecord.IterateAttachments( - [this, &MissingCount, &MissingReadFromUpstreamCount, &RpcResponse, &BatchPolicy](CbFieldView AttachmentHash) { - CachePolicy ValuePolicy = BatchPolicy.GetRecordPolicy(); - if (!EnumHasAllFlags(ValuePolicy, CachePolicy::QueryLocal)) - { - // A value that is requested without the Query flag (such as None/Disable) does not count as missing, because we - // didn't ask for it and thus the record is complete in its absence. - if (EnumHasAllFlags(ValuePolicy, CachePolicy::QueryRemote)) - { - MissingReadFromUpstreamCount++; - MissingCount++; - } - } - else if (EnumHasAllFlags(ValuePolicy, CachePolicy::SkipData)) - { - if (!m_CidStore.ContainsChunk(AttachmentHash.AsHash())) - { - if (EnumHasAllFlags(ValuePolicy, CachePolicy::QueryRemote)) - { - MissingReadFromUpstreamCount++; - } - MissingCount++; - } - } - else - { - if (IoBuffer Chunk = m_CidStore.FindChunkByCid(AttachmentHash.AsHash())) - { - ZEN_ASSERT(Chunk.GetSize() > 0); - RpcResponse.AddAttachment(CbAttachment(CompressedBuffer::FromCompressed(SharedBuffer(Chunk)))); - } - else - { - if (EnumHasAllFlags(ValuePolicy, CachePolicy::QueryRemote)) - { - MissingReadFromUpstreamCount++; - } - MissingCount++; - } - } - }); - } - - // Searching upstream is not implemented in this legacy support function - if (CacheValue.Value && (MissingCount == 0 || EnumHasAllFlags(BatchPolicy.GetRecordPolicy(), CachePolicy::PartialRecord))) - { - ZEN_DEBUG("HIT - '{}/{}' {} '{}' (LOCAL) {}", - Key.Bucket, - Key.Hash, - NiceBytes(CacheValue.Value.Size()), - ToString(CacheValue.Value.GetContentType()), - MissingCount ? "(PARTIAL)" : ""sv); - - CacheValues[KeyIndex] = std::move(CacheValue.Value); - m_CacheStats.HitCount++; - } - else - { - if (!EnumHasAnyFlags(BatchPolicy.GetRecordPolicy(), CachePolicy::Query)) - { - // If they requested no query, do not record this as a miss - ZEN_DEBUG("DISABLEDQUERY - '{}/{}'", Key.Bucket, Key.Hash); - } - else - { - ZEN_DEBUG("MISS - '{}/{}' {}", Key.Bucket, Key.Hash, MissingCount ? "(PARTIAL)"sv : ""sv); - m_CacheStats.MissCount++; - } - } - - ++KeyIndex; - } - - CbObjectWriter ResponseObject; - - ResponseObject.BeginArray("Result"sv); - for (const IoBuffer& Value : CacheValues) - { - if (Value) - { - CbObjectView Record(Value.Data()); - ResponseObject << Record; - } - else - { - ResponseObject.AddNull(); - } - } - ResponseObject.EndArray(); - - RpcResponse.SetObject(ResponseObject.Save()); - - BinaryWriter MemStream; - RpcResponse.Save(MemStream); - - Request.WriteResponse(HttpResponseCode::OK, - HttpContentType::kCbPackage, - IoBuffer(IoBuffer::Wrap, MemStream.GetData(), MemStream.GetSize())); -} -#endif - void HttpStructuredCacheService::HandleRpcGetCacheRecords(zen::HttpServerRequest& HttpRequest, CbObjectView RpcRequest) { -#if BACKWARDS_COMPATABILITY_JAN2022 - // Backwards compatability; - if (RpcRequest["Params"sv].AsObjectView()["CacheKeys"sv]) - { - return HandleRpcGetCacheRecordsLegacy(HttpRequest, RpcRequest); - } -#endif ZEN_TRACE_CPU("Z$::RpcGetCacheRecords"); CbObjectView Params = RpcRequest["Params"sv].AsObjectView(); @@ -1559,13 +1413,6 @@ HttpStructuredCacheService::HandleRpcPutCacheValues(zen::HttpServerRequest& Requ void HttpStructuredCacheService::HandleRpcGetCacheValues(zen::HttpServerRequest& HttpRequest, CbObjectView RpcRequest) { -#if BACKWARDS_COMPATABILITY_JAN2022 - if (RpcRequest["Params"sv].AsObjectView()["ChunkRequests"]) - { - return HandleRpcGetCacheChunks(HttpRequest, RpcRequest); - } -#endif - ZEN_TRACE_CPU("Z$::RpcGetCacheValues"); CbObjectView Params = RpcRequest["Params"sv].AsObjectView(); @@ -1737,28 +1584,23 @@ HttpStructuredCacheService::HandleRpcGetCacheChunks(zen::HttpServerRequest& Http std::vector KeyRequests; std::vector Chunks; - BACKWARDS_COMPATABILITY_JAN2022_CODE(bool SendValueOnly = false;) - if (!TryGetCacheChunks_Parse(KeyRequests, Chunks BACKWARDS_COMPATABILITY_JAN2022_CODE(, SendValueOnly), RpcRequest)) + if (!TryGetCacheChunks_Parse(KeyRequests, Chunks, RpcRequest)) { return HttpRequest.WriteResponse(HttpResponseCode::BadRequest); } GetCacheChunks_LoadKeys(KeyRequests); GetCacheChunks_LoadChunks(Chunks); - GetCacheChunks_SendResults(Chunks, HttpRequest BACKWARDS_COMPATABILITY_JAN2022_CODE(, SendValueOnly)); + GetCacheChunks_SendResults(Chunks, HttpRequest); } bool -HttpStructuredCacheService::TryGetCacheChunks_Parse(std::vector& KeyRequests, - std::vector& Chunks, - BACKWARDS_COMPATABILITY_JAN2022_CODE(bool& SendValueOnly, ) CbObjectView RpcRequest) +HttpStructuredCacheService::TryGetCacheChunks_Parse(std::vector& KeyRequests, + std::vector& Chunks, + CbObjectView RpcRequest) { using namespace GetCacheChunks::detail; -#if BACKWARDS_COMPATABILITY_JAN2022 - SendValueOnly = RpcRequest["MethodVersion"sv].AsInt32() < 1; -#else ZEN_ASSERT(RpcRequest["Method"sv].AsString() == "GetCacheChunks"sv); -#endif CbObjectView Params = RpcRequest["Params"sv].AsObjectView(); std::string_view DefaultPolicyText = Params["DefaultPolicy"sv].AsString(); @@ -1809,13 +1651,7 @@ HttpStructuredCacheService::TryGetCacheChunks_Parse(std::vector& Chunks, - zen::HttpServerRequest& HttpRequest - BACKWARDS_COMPATABILITY_JAN2022_CODE(, bool SendValueOnly)) + zen::HttpServerRequest& HttpRequest) { using namespace GetCacheChunks::detail; @@ -2099,57 +1934,40 @@ HttpStructuredCacheService::GetCacheChunks_SendResults(std::vector