diff options
| author | Per Larsson <[email protected]> | 2021-11-09 13:20:00 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-11-09 13:20:00 +0100 |
| commit | e0d54396fa3ba0f5466a4ea1f2810721c18fa55f (patch) | |
| tree | 4ab63a83dac7e1e9245d62be1918d12f4a55ae8d /zenserver/upstream/upstreamcache.cpp | |
| parent | Added batched get chunk(s). (diff) | |
| download | zen-e0d54396fa3ba0f5466a4ea1f2810721c18fa55f.tar.xz zen-e0d54396fa3ba0f5466a4ea1f2810721c18fa55f.zip | |
Sort cache keys when resolving payload ID's.
Diffstat (limited to 'zenserver/upstream/upstreamcache.cpp')
| -rw-r--r-- | zenserver/upstream/upstreamcache.cpp | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/zenserver/upstream/upstreamcache.cpp b/zenserver/upstream/upstreamcache.cpp index 437b29cd7..7ef0caf62 100644 --- a/zenserver/upstream/upstreamcache.cpp +++ b/zenserver/upstream/upstreamcache.cpp @@ -782,7 +782,7 @@ public: virtual GetUpstreamCacheBatchResult GetCacheRecords(std::span<CacheKey> CacheKeys, std::span<size_t> KeyIndex, - OnCacheGetComplete OnComplete) override + OnCacheGetComplete OnComplete) override final { if (!m_Options.ReadUpstream) { @@ -801,6 +801,52 @@ public: if (Endpoint->IsHealthy()) { CacheResult = Endpoint->GetCacheRecord(CacheKey, ZenContentType::kCbPackage); + m_Stats.Add(m_Log, *Endpoint, CacheResult, m_Endpoints); + + if (CacheResult.Success) + { + break; + } + } + } + + if (CacheResult.Success) + { + OnComplete(Idx, CacheResult.Value); + } + else + { + Result.Missing.push_back(Idx); + } + } + + return Result; + } + + virtual GetUpstreamCacheBatchResult GetCachePayloads(std::span<CacheChunkRequest> CacheChunkRequests, + std::span<size_t> ChunkIndex, + OnCacheGetComplete OnComplete) override final + { + if (!m_Options.ReadUpstream) + { + return {.Missing = std::vector<size_t>(ChunkIndex.begin(), ChunkIndex.end())}; + } + + GetUpstreamCacheBatchResult Result; + + for (size_t Idx : ChunkIndex) + { + const CacheChunkRequest& Chunk = CacheChunkRequests[Idx]; + UpstreamPayloadKey PayloadKey{{Chunk.Key.Bucket, Chunk.Key.Hash}, Chunk.ChunkId}; + + GetUpstreamCacheResult CacheResult; + for (auto& Endpoint : m_Endpoints) + { + if (Endpoint->IsHealthy()) + { + CacheResult = Endpoint->GetCachePayload(PayloadKey); + m_Stats.Add(m_Log, *Endpoint, CacheResult, m_Endpoints); + if (CacheResult.Success) { break; |