From 424be141e88b04b4de7ab5def2c29b03f5f72d48 Mon Sep 17 00:00:00 2001 From: Per Larsson Date: Wed, 10 Nov 2021 08:47:57 +0100 Subject: Handle cache record policy. --- zenserver/cache/structuredcache.cpp | 40 ++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'zenserver/cache/structuredcache.cpp') diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index decad2f04..073192c12 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -114,9 +114,7 @@ HttpStructuredCacheService::HandleRequest(HttpServerRequest& Request) if (Key == "$batch") { - const auto QueryParams = Request.GetQueryParams(); - CachePolicy Policy = ParseCachePolicy(QueryParams); - return HandleBatchRequest(Request, Policy); + return HandleBatchRequest(Request); } if (std::all_of(begin(Key), end(Key), [](const char c) { return std::isalnum(c); })) @@ -782,10 +780,8 @@ HttpStructuredCacheService::ValidateKeyUri(HttpServerRequest& Request, CacheRef& } void -HttpStructuredCacheService::HandleBatchRequest(zen::HttpServerRequest& Request, CachePolicy Policy) +HttpStructuredCacheService::HandleBatchRequest(zen::HttpServerRequest& Request) { - using namespace fmt::literals; - switch (auto Verb = Request.RequestVerb()) { using enum HttpVerb; @@ -805,11 +801,11 @@ HttpStructuredCacheService::HandleBatchRequest(zen::HttpServerRequest& Request, if (Method == "get-cache-records"sv) { - HandleBatchGetCacheRecords(Request, BatchRequest, Policy); + HandleBatchGetCacheRecords(Request, BatchRequest); } else if (Method == "get-cache-chunks"sv) { - HandleBatchGetCachePayloads(Request, BatchRequest, Policy); + HandleBatchGetCachePayloads(Request, BatchRequest); } else { @@ -824,19 +820,21 @@ HttpStructuredCacheService::HandleBatchRequest(zen::HttpServerRequest& Request, } void -HttpStructuredCacheService::HandleBatchGetCacheRecords(zen::HttpServerRequest& Request, CbObjectView BatchRequest, CachePolicy Policy) +HttpStructuredCacheService::HandleBatchGetCacheRecords(zen::HttpServerRequest& Request, CbObjectView BatchRequest) { using namespace fmt::literals; - const bool SkipData = (Policy & CachePolicy::SkipData) == CachePolicy::SkipData; - const bool SkipAttachments = (Policy & CachePolicy::SkipAttachments) == CachePolicy::SkipAttachments; - const bool QueryUpstream = m_UpstreamCache && ((Policy & CachePolicy::QueryRemote) == CachePolicy::QueryRemote); - const std::string_view Method = BatchRequest["method"sv].AsString(); ZEN_ASSERT(Method == "get-cache-records"sv); CbObjectView Params = BatchRequest["params"sv].AsObjectView(); + CacheRecordPolicy Policy; + CacheRecordPolicy::FromCompactBinary(Params["policy"sv].AsObjectView(), Policy); + + const bool SkipAttachments = (Policy.GetRecordPolicy() & CachePolicy::SkipAttachments) == CachePolicy::SkipAttachments; + const bool QueryUpstream = m_UpstreamCache && ((Policy.GetRecordPolicy() & CachePolicy::QueryRemote) == CachePolicy::QueryRemote); + std::vector CacheKeys; std::vector CacheValues; std::vector Payloads; @@ -855,6 +853,11 @@ HttpStructuredCacheService::HandleBatchGetCacheRecords(zen::HttpServerRequest& R CacheValues.resize(CacheKeys.size()); + if (!SkipAttachments) + { + Payloads.reserve(CacheKeys.size()); + } + for (size_t Idx = 0; const CacheKey& Key : CacheKeys) { ZenCacheValue CacheValue; @@ -971,7 +974,7 @@ HttpStructuredCacheService::HandleBatchGetCacheRecords(zen::HttpServerRequest& R } void -HttpStructuredCacheService::HandleBatchGetCachePayloads(zen::HttpServerRequest& Request, CbObjectView BatchRequest, CachePolicy Policy) +HttpStructuredCacheService::HandleBatchGetCachePayloads(zen::HttpServerRequest& Request, CbObjectView BatchRequest) { using namespace fmt::literals; @@ -999,15 +1002,16 @@ HttpStructuredCacheService::HandleBatchGetCachePayloads(zen::HttpServerRequest& return IoHash::Zero; }; - const bool SkipData = (Policy & CachePolicy::SkipData) == CachePolicy::SkipData; - const bool SkipAttachments = (Policy & CachePolicy::SkipAttachments) == CachePolicy::SkipAttachments; - const bool QueryUpstream = m_UpstreamCache && ((Policy & CachePolicy::QueryRemote) == CachePolicy::QueryRemote); - const std::string_view Method = BatchRequest["method"sv].AsString(); ZEN_ASSERT(Method == "get-cache-chunks"sv); CbObjectView Params = BatchRequest["params"sv].AsObjectView(); + CacheRecordPolicy Policy; + CacheRecordPolicy::FromCompactBinary(Params["policy"sv].AsObjectView(), Policy); + + const bool QueryUpstream = m_UpstreamCache && ((Policy.GetRecordPolicy() & CachePolicy::QueryRemote) == CachePolicy::QueryRemote); + std::vector ChunkRequests; std::vector Missing; -- cgit v1.2.3