// Copyright Epic Games, Inc. All Rights Reserved. #pragma once #include #include #include #include namespace zen { class CbPackage; class CbObjectWriter; class CbObjectView; namespace cacherequests { // I'd really like to get rid of std::optional (or really the class CacheRecordPolicy) // // CacheRecordPolicy has a record level policy but it can also contain policies for individual // values inside the record. // // However, when we do a "PutCacheRecords" we already list the individual Values with their Id // so we can just as well use an optional plain CachePolicy for each value. // // In "GetCacheRecords" we do not currently as for the individual values but you can add // a policy on a per-value level in the std::optional Policy for each record. // // But as we already need to know the Ids of the values we want to set the policy for // it would be simpler to add an array of requested values which each has an optional policy. // // We could add: // struct GetCacheRecordValueRequest // { // Oid Id; // std::optional Policy; // }; // // and change GetCacheRecordRequest to // struct GetCacheRecordRequest // { // CacheKey Key = CacheKey::Empty; // std::vector ValueRequests; // std::optional Policy; // }; // // This way we don't need the complex CacheRecordPolicy class and the request becomes // more uniform and easier to understand. // // Would need to decide what the ValueRequests actually mean: // Do they dictate which values to fetch or just a change of the policy? // If they dictate the values to fetch you need to know all the value ids to set them // and that is unlikely what we want - we want to be able to get a cache record with // all its values without knowing all the Ids, right? // ////////////////////////////////////////////////////////////////////////// // Put 1..n structured cache records with optional attachments struct PutCacheRecordRequestValue { Oid Id = Oid::Zero; IoHash RawHash = IoHash::Zero; // If Body is not set, this must be set and the value must already exist in cache CompressedBuffer Body = CompressedBuffer::Null; }; struct PutCacheRecordRequest { CacheKey Key = CacheKey::Empty; std::vector Values; std::optional Policy; }; struct PutCacheRecordsRequest { uint32_t AcceptMagic = 0; CachePolicy DefaultPolicy = CachePolicy::Default; std::string Namespace; std::vector Requests; bool Parse(const CbPackage& Package); bool Format(CbPackage& OutPackage) const; }; struct PutCacheRecordsResult { std::vector Success; std::vector Details; bool Parse(const CbPackage& Package); bool Format(CbPackage& OutPackage) const; }; ////////////////////////////////////////////////////////////////////////// // Get 1..n structured cache records with optional attachments // We can get requests for a cache record where we want care about a particular // value id which we now of, but we don't know the ids of the other values and // we still want them. // Not sure if in that case we want different policies for the different attachemnts? struct GetCacheRecordRequest { CacheKey Key = CacheKey::Empty; std::optional Policy; }; struct GetCacheRecordsRequest { uint32_t AcceptMagic = 0; uint16_t AcceptOptions = 0; int32_t ProcessPid = 0; CachePolicy DefaultPolicy = CachePolicy::Default; std::string Namespace; std::vector Requests; bool Parse(const CbPackage& RpcRequest); bool Parse(const CbObjectView& RpcRequest); bool Format(CbPackage& OutPackage, const std::span OptionalRecordFilter = {}) const; bool Format(CbObjectWriter& Writer, const std::span OptionalRecordFilter = {}) const; }; struct GetCacheRecordResultValue { Oid Id = Oid::Zero; IoHash RawHash = IoHash::Zero; uint64_t RawSize = 0; CompressedBuffer Body = CompressedBuffer::Null; }; struct GetCacheRecordResult { CacheKey Key = CacheKey::Empty; std::vector Values; }; struct GetCacheRecordsResult { std::vector> Results; bool Parse(const CbPackage& Package, const std::span OptionalRecordResultIndexes = {}); bool Format(CbPackage& OutPackage) const; }; ////////////////////////////////////////////////////////////////////////// // Put 1..n unstructured cache objects struct PutCacheValueRequest { CacheKey Key = CacheKey::Empty; IoHash RawHash = IoHash::Zero; CompressedBuffer Body = CompressedBuffer::Null; // If not set the value is expected to already exist in cache store std::optional Policy; }; struct PutCacheValuesRequest { uint32_t AcceptMagic = 0; CachePolicy DefaultPolicy = CachePolicy::Default; std::string Namespace; std::vector Requests; bool Parse(const CbPackage& Package); bool Format(CbPackage& OutPackage) const; }; struct PutCacheValuesResult { std::vector Success; bool Parse(const CbPackage& Package); bool Format(CbPackage& OutPackage) const; }; ////////////////////////////////////////////////////////////////////////// // Get 1..n unstructured cache objects (stored data may be structured or unstructured) struct GetCacheValueRequest { CacheKey Key = CacheKey::Empty; std::optional Policy; }; struct GetCacheValuesRequest { uint32_t AcceptMagic = 0; uint16_t AcceptOptions = 0; int32_t ProcessPid = 0; CachePolicy DefaultPolicy = CachePolicy::Default; std::string Namespace; std::vector Requests; bool Parse(const CbObjectView& BatchObject); bool Format(CbPackage& OutPackage, const std::span OptionalValueFilter = {}) const; }; struct CacheValueResult { uint64_t RawSize = 0; uint64_t FragmentOffset = 0; IoHash FragmentHash = IoHash::Zero; IoHash RawHash = IoHash::Zero; CompressedBuffer Body = CompressedBuffer::Null; }; struct CacheValuesResult { std::vector Results; bool Parse(const CbPackage& Package, const std::span OptionalValueResultIndexes = {}); bool Format(CbPackage& OutPackage) const; }; typedef CacheValuesResult GetCacheValuesResult; ////////////////////////////////////////////////////////////////////////// // Get 1..n cache record values (attachments) for 1..n records struct GetCacheChunkRequest { CacheKey Key; Oid ValueId = Oid::Zero; // Set if ChunkId is not known at request time IoHash ChunkId = IoHash::Zero; uint64_t RawOffset = 0ull; uint64_t RawSize = ~uint64_t(0); std::optional Policy; }; struct GetCacheChunksRequest { uint32_t AcceptMagic = 0; uint16_t AcceptOptions = 0; int32_t ProcessPid = 0; CachePolicy DefaultPolicy = CachePolicy::Default; std::string Namespace; std::vector Requests; bool Parse(const CbObjectView& BatchObject); bool Format(CbPackage& OutPackage) const; }; typedef CacheValuesResult GetCacheChunksResult; ////////////////////////////////////////////////////////////////////////// // struct CacheRecordValue // { // Oid Id = Oid::Zero; // IoHash RawHash = IoHash::Zero; // uint64_t RawSize = 0; // }; // // struct CacheRecord // { // CacheKey Key = CacheKey::Empty; // std::vector Values; // // bool Parse(CbObjectView& Reader); // bool Format(CbObjectWriter& Writer) const; // }; } // namespace cacherequests } // namespace zen