diff options
| author | Dan Engelbrecht <[email protected]> | 2024-03-21 10:58:28 +0100 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-03-21 10:58:28 +0100 |
| commit | 9b82209e3368de806a48554d85cb7c364973eb2d (patch) | |
| tree | 8b52dbe1fd5a1a3255c51198a7b31bef77cf9009 /src/zenstore/cache/cacherpc.cpp | |
| parent | improved process monitoring behaviour with invalid pids (#16) (diff) | |
| download | zen-9b82209e3368de806a48554d85cb7c364973eb2d.tar.xz zen-9b82209e3368de806a48554d85cb7c364973eb2d.zip | |
add support for responding with partial cache chunks (#11)
* add support for responding with partial cache chunks
Diffstat (limited to 'src/zenstore/cache/cacherpc.cpp')
| -rw-r--r-- | src/zenstore/cache/cacherpc.cpp | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/zenstore/cache/cacherpc.cpp b/src/zenstore/cache/cacherpc.cpp index e6ba6629d..27bc4b016 100644 --- a/src/zenstore/cache/cacherpc.cpp +++ b/src/zenstore/cache/cacherpc.cpp @@ -229,7 +229,7 @@ CacheRpcHandler::HandleRpcRequest(const CacheRequestContext& Context, } else if (Method == "GetCacheChunks"sv) { - OutResultPackage = HandleRpcGetCacheChunks(Context, Object); + OutResultPackage = HandleRpcGetCacheChunks(Context, OutAcceptFlags, Object); } else { @@ -1102,7 +1102,7 @@ CacheRpcHandler::HandleRpcGetCacheValues(const CacheRequestContext& Context, CbO } CbPackage -CacheRpcHandler::HandleRpcGetCacheChunks(const CacheRequestContext& Context, CbObjectView RpcRequest) +CacheRpcHandler::HandleRpcGetCacheChunks(const CacheRequestContext& Context, RpcAcceptOptions AcceptOptions, CbObjectView RpcRequest) { ZEN_TRACE_CPU("Z$::RpcGetCacheChunks"); using namespace cache::detail; @@ -1133,7 +1133,7 @@ CacheRpcHandler::HandleRpcGetCacheChunks(const CacheRequestContext& Context, CbO GetUpstreamCacheChunks(Context, Namespace, UpstreamChunks, RequestKeys, Requests); // Send the payload and descriptive data about each chunk to the client - return WriteGetCacheChunksResponse(Context, Namespace, Requests); + return WriteGetCacheChunksResponse(Context, Namespace, AcceptOptions, Requests); } bool @@ -1542,12 +1542,15 @@ CacheRpcHandler::GetUpstreamCacheChunks(const CacheRequestContext& Context, CbPackage CacheRpcHandler::WriteGetCacheChunksResponse([[maybe_unused]] const CacheRequestContext& Context, std::string_view Namespace, + RpcAcceptOptions AcceptOptions, std::vector<cache::detail::ChunkRequest>& Requests) { ZEN_TRACE_CPU("Z$::WriteGetCacheChunksResponse"); using namespace cache::detail; + const bool AcceptsPartialChunks = EnumHasAnyFlags(AcceptOptions, RpcAcceptOptions::kAllowPartialCacheChunks); + CbPackage RpcResponse; CbObjectWriter Writer; @@ -1563,6 +1566,33 @@ CacheRpcHandler::WriteGetCacheChunksResponse([[maybe_unused]] const CacheRequest Writer.AddHash("RawHash"sv, Request.Key->ChunkId); if (Request.Value && !EnumHasAllFlags(Request.DownstreamPolicy, CachePolicy::SkipData)) { + if (AcceptsPartialChunks && (Request.RequestedOffset != 0 || Request.RequestedSize < Request.RawSize)) + { + uint64_t RawOffset = 0; + if (Request.RequestedOffset > 0) + { + OodleCompressor Compressor; + OodleCompressionLevel CompressionLevel; + uint64_t BlockSize = 0; + const bool bOk = Request.Value.TryGetCompressParameters(Compressor, CompressionLevel, BlockSize); + ZEN_ASSERT(bOk); + if (BlockSize > 0) + { + RawOffset = (Request.RequestedOffset / BlockSize) * BlockSize; + } + else + { + RawOffset = Request.RequestedOffset; + } + } + // Technically the receiver can figure this offset out based on the assumption that we reply with + // a set of blocks that encapsulates the requested range, but since the UE side was not initially + // written to handle this we need to indicate that we do indeed reply with a partial response. + // And as we already need to add a field, why not provide some useful information so the client + // don't need to calculate this for us... + Writer.AddInteger("RawOffset", RawOffset); + Request.Value = Request.Value.GetRange(Request.RequestedOffset, Request.RequestedSize); + } RpcResponse.AddAttachment(CbAttachment(Request.Value, Request.Key->ChunkId)); } else |