From 154743f2d2ff2b7163bcf8d7b76eea3e3579aaba Mon Sep 17 00:00:00 2001 From: mattpetersepic <58296718+mattpetersepic@users.noreply.github.com> Date: Tue, 1 Feb 2022 08:06:36 -0700 Subject: Cache policy support (#47) Add HandleRpc methods for the remaining ICacheStore requests from unreal: PutCacheValues/GetCacheValues. We now have batched versions for PutCacheRecords,GetCacheRecords,PutCacheValues,GetCacheValues,GetCacheChunks. Add support for CachePolicy flags to all of these batched methods. * Add Batched PutCacheValues/GetCacheValues. Rename old GetCacheValues to GetCacheChunks. * HandleRpcGetCacheRecords: Receive a CacheRecordPolicy with each key, and skipdata on attachments we already have. * Changes to CachePolicy copied from Release-5.0 depot. Change serialization to use the key BasePolicy instead of DefaultValuePolicy. * GetChunks: Read CacheRecords from remote if necessary to find ContentId. Implement QueryLocal, StoreLocal, and SkipData. --- zenserver/cache/structuredcache.h | 42 +++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) (limited to 'zenserver/cache/structuredcache.h') diff --git a/zenserver/cache/structuredcache.h b/zenserver/cache/structuredcache.h index 88bf6cda1..14b001e48 100644 --- a/zenserver/cache/structuredcache.h +++ b/zenserver/cache/structuredcache.h @@ -9,6 +9,10 @@ #include "monitoring/httpstatus.h" #include +#include + +// Include the define for BACKWARDS_COMPATABILITY_JAN2022 +#include namespace spdlog { class logger; @@ -25,6 +29,11 @@ class UpstreamCache; class ZenCacheStore; enum class CachePolicy : uint32_t; +namespace GetCacheChunks::detail { + struct KeyRequestData; + struct ChunkRequestData; +} // namespace GetCacheChunks::detail + /** * Structured cache service. Imposes constraints on keys, supports blobs and * structured values @@ -99,12 +108,25 @@ private: void HandlePutCacheValue(zen::HttpServerRequest& Request, const CacheRef& Ref, CachePolicy PolicyFromURL); void HandleRpcRequest(zen::HttpServerRequest& Request); void HandleRpcPutCacheRecords(zen::HttpServerRequest& Request, const CbPackage& BatchRequest); - void HandleRpcGetCacheRecords(zen::HttpServerRequest& Request, CbObjectView BatchRequest); - void HandleRpcGetCacheValues(zen::HttpServerRequest& Request, CbObjectView BatchRequest); - void HandleCacheBucketRequest(zen::HttpServerRequest& Request, std::string_view Bucket); - virtual void HandleStatsRequest(zen::HttpServerRequest& Request) override; - virtual void HandleStatusRequest(zen::HttpServerRequest& Request) override; - PutResult PutCacheRecord(PutRequestData& Request, const CbPackage* Package); +#if BACKWARDS_COMPATABILITY_JAN2022 + void HandleRpcGetCacheRecordsLegacy(zen::HttpServerRequest& Request, CbObjectView BatchRequest); +#endif + void HandleRpcGetCacheRecords(zen::HttpServerRequest& Request, CbObjectView BatchRequest); + void HandleRpcPutCacheValues(zen::HttpServerRequest& Request, const CbPackage& BatchRequest); + void HandleRpcGetCacheValues(zen::HttpServerRequest& Request, CbObjectView BatchRequest); + void HandleRpcGetCacheChunks(zen::HttpServerRequest& Request, CbObjectView BatchRequest); + void HandleCacheBucketRequest(zen::HttpServerRequest& Request, std::string_view Bucket); + virtual void HandleStatsRequest(zen::HttpServerRequest& Request) override; + virtual void HandleStatusRequest(zen::HttpServerRequest& Request) override; + PutResult PutCacheRecord(PutRequestData& Request, const CbPackage* Package); + + bool TryGetCacheChunks_Parse(std::vector& KeyRequests, + std::vector& Chunks, + BACKWARDS_COMPATABILITY_JAN2022_CODE(bool& SendValueOnly, ) CbObjectView RpcRequest); + void GetCacheChunks_LoadKeys(std::vector& KeyRequests); + void GetCacheChunks_LoadChunks(std::vector& Chunks); + void GetCacheChunks_SendResults(std::vector& Chunks, + zen::HttpServerRequest& HttpRequest BACKWARDS_COMPATABILITY_JAN2022_CODE(, bool SendValueOnly)); spdlog::logger& Log() { return m_Log; } spdlog::logger& m_Log; @@ -119,4 +141,12 @@ private: CacheStats m_CacheStats; }; +/** Recognize both kBinary and kCompressedBinary as kCompressedBinary for structured cache value keys. + * We need this until the content type is preserved for kCompressedBinary when passing to and from upstream servers. */ +inline bool +IsCompressedBinary(ZenContentType Type) +{ + return Type == ZenContentType::kBinary || Type == ZenContentType::kCompressedBinary; +} + } // namespace zen -- cgit v1.2.3