diff options
| author | Dan Engelbrecht <[email protected]> | 2024-04-03 17:50:48 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2024-04-03 17:50:48 +0200 |
| commit | 4e328366efc3a2cccd286a7e191663af24dfe50d (patch) | |
| tree | 931d259180bb7f54a926b5e5b46867cd7eeb4675 /src/zenstore/cache/cachedisklayer.cpp | |
| parent | zenremoteprojectstore with httpclient (#35) (diff) | |
| download | zen-4e328366efc3a2cccd286a7e191663af24dfe50d.tar.xz zen-4e328366efc3a2cccd286a7e191663af24dfe50d.zip | |
validate rpc chunk responses (#36)
* Validate size of found chunks in cas/cache
Diffstat (limited to 'src/zenstore/cache/cachedisklayer.cpp')
| -rw-r--r-- | src/zenstore/cache/cachedisklayer.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp index d897e26ce..3605f5582 100644 --- a/src/zenstore/cache/cachedisklayer.cpp +++ b/src/zenstore/cache/cachedisklayer.cpp @@ -1141,7 +1141,7 @@ ZenCacheDiskLayer::CacheBucket::GetInlineCacheValue(const DiskLocation& Loc) con } IoBuffer -ZenCacheDiskLayer::CacheBucket::GetStandaloneCacheValue(ZenContentType ContentType, const IoHash& HashKey) const +ZenCacheDiskLayer::CacheBucket::GetStandaloneCacheValue(const DiskLocation& Loc, const IoHash& HashKey) const { ZEN_TRACE_CPU("Z$::Bucket::GetStandaloneCacheValue"); @@ -1152,9 +1152,11 @@ ZenCacheDiskLayer::CacheBucket::GetStandaloneCacheValue(ZenContentType ContentTy if (IoBuffer Data = IoBufferBuilder::MakeFromFile(DataFilePath.ToPath())) { - Data.SetContentType(ContentType); - - return Data; + if (Data.GetSize() == Loc.Size()) + { + Data.SetContentType(Loc.GetContentType()); + return Data; + } } return {}; @@ -1211,7 +1213,7 @@ ZenCacheDiskLayer::CacheBucket::Get(const IoHash& HashKey, ZenCacheValue& OutVal } if (Location.IsFlagSet(DiskLocation::kStandaloneFile)) { - OutValue.Value = GetStandaloneCacheValue(Location.GetContentType(), HashKey); + OutValue.Value = GetStandaloneCacheValue(Location, HashKey); } else { @@ -1621,7 +1623,7 @@ ZenCacheDiskLayer::CacheBucket::ScrubStorage(ScrubContext& Ctx) else { // Structured cache value - IoBuffer Buffer = GetStandaloneCacheValue(Loc.GetContentType(), HashKey); + IoBuffer Buffer = GetStandaloneCacheValue(Loc, HashKey); if (!Buffer) { ReportBadKey(HashKey); @@ -1880,7 +1882,7 @@ ZenCacheDiskLayer::CacheBucket::GatherReferences(GcContext& GcCtx) IoBuffer Buffer; if (Loc.IsFlagSet(DiskLocation::kStandaloneFile)) { - if (Buffer = GetStandaloneCacheValue(Loc.GetContentType(), Key); !Buffer) + if (Buffer = GetStandaloneCacheValue(Loc, Key); !Buffer) { continue; } @@ -2269,9 +2271,8 @@ ZenCacheDiskLayer::CacheBucket::GetValueDetails(RwLock::SharedLockScope& IndexLo const BucketPayload& Payload = m_Payloads[Index]; if (Payload.Location.IsFlagSet(DiskLocation::kStructured)) { - IoBuffer Value = Payload.Location.IsFlagSet(DiskLocation::kStandaloneFile) - ? GetStandaloneCacheValue(Payload.Location.GetContentType(), Key) - : GetInlineCacheValue(Payload.Location); + IoBuffer Value = Payload.Location.IsFlagSet(DiskLocation::kStandaloneFile) ? GetStandaloneCacheValue(Payload.Location, Key) + : GetInlineCacheValue(Payload.Location); CbObjectView Obj(Value.GetData()); Obj.IterateAttachments([&Attachments](CbFieldView Field) { Attachments.emplace_back(Field.AsAttachment()); }); } @@ -3066,7 +3067,7 @@ public: { m_CacheBucket.m_IndexLock.WithExclusiveLock([&]() { m_CacheBucket.m_TrackedReferences = std::make_unique<HashSet>(); }); - std::vector<IoHash> StandaloneKeys; + std::vector<std::pair<IoHash, DiskLocation>> StandaloneKeys; { std::vector<IoHash> InlineKeys; std::unordered_map<uint32_t, std::size_t> BlockIndexToEntriesPerBlockIndex; @@ -3099,7 +3100,7 @@ public: const IoHash& Key = Entry.first; if (Loc.IsFlagSet(DiskLocation::kStandaloneFile)) { - StandaloneKeys.push_back(Key); + StandaloneKeys.push_back(std::make_pair(Key, Loc)); continue; } @@ -3157,7 +3158,7 @@ public: } } } - for (const IoHash& Key : StandaloneKeys) + for (const auto& It : StandaloneKeys) { if (Ctx.IsCancelledFlag.load()) { @@ -3165,7 +3166,7 @@ public: return; } - IoBuffer Buffer = m_CacheBucket.GetStandaloneCacheValue(ZenContentType::kCbObject, Key); + IoBuffer Buffer = m_CacheBucket.GetStandaloneCacheValue(It.second, It.first); if (!Buffer) { continue; |