aboutsummaryrefslogtreecommitdiff
path: root/zenserver/upstream/upstreamcache.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-11-02 10:50:18 +0100
committerPer Larsson <[email protected]>2021-11-02 10:50:18 +0100
commit4b8d4c0e375c729e38bdaadfebf0eaf14f08f5f9 (patch)
treed1e6fb1c71a0c8c5e12b2814f309d09d7093c9b3 /zenserver/upstream/upstreamcache.cpp
parentMerge branch 'main' into zcache-batch (diff)
downloadzen-4b8d4c0e375c729e38bdaadfebf0eaf14f08f5f9.tar.xz
zen-4b8d4c0e375c729e38bdaadfebf0eaf14f08f5f9.zip
Added upstream batch API.
Diffstat (limited to 'zenserver/upstream/upstreamcache.cpp')
-rw-r--r--zenserver/upstream/upstreamcache.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp
index c0cd858b6..437b29cd7 100644
--- a/zenserver/upstream/upstreamcache.cpp
+++ b/zenserver/upstream/upstreamcache.cpp
@@ -780,6 +780,47 @@ public:
return {};
}
+ virtual GetUpstreamCacheBatchResult GetCacheRecords(std::span<CacheKey> CacheKeys,
+ std::span<size_t> KeyIndex,
+ OnCacheGetComplete OnComplete) override
+ {
+ if (!m_Options.ReadUpstream)
+ {
+ return {.Missing = std::vector<size_t>(KeyIndex.begin(), KeyIndex.end())};
+ }
+
+ GetUpstreamCacheBatchResult Result;
+
+ for (size_t Idx : KeyIndex)
+ {
+ const UpstreamCacheKey CacheKey = {CacheKeys[Idx].Bucket, CacheKeys[Idx].Hash};
+
+ GetUpstreamCacheResult CacheResult;
+ for (auto& Endpoint : m_Endpoints)
+ {
+ if (Endpoint->IsHealthy())
+ {
+ CacheResult = Endpoint->GetCacheRecord(CacheKey, ZenContentType::kCbPackage);
+ if (CacheResult.Success)
+ {
+ break;
+ }
+ }
+ }
+
+ if (CacheResult.Success)
+ {
+ OnComplete(Idx, CacheResult.Value);
+ }
+ else
+ {
+ Result.Missing.push_back(Idx);
+ }
+ }
+
+ return Result;
+ }
+
virtual GetUpstreamCacheResult GetCachePayload(UpstreamPayloadKey PayloadKey) override
{
if (m_Options.ReadUpstream)