diff options
Diffstat (limited to 'src/zenstore/cache/cachedisklayer.cpp')
| -rw-r--r-- | src/zenstore/cache/cachedisklayer.cpp | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/zenstore/cache/cachedisklayer.cpp b/src/zenstore/cache/cachedisklayer.cpp index d897e26ce..f53ab6f8b 100644 --- a/src/zenstore/cache/cachedisklayer.cpp +++ b/src/zenstore/cache/cachedisklayer.cpp @@ -871,7 +871,7 @@ ZenCacheDiskLayer::CacheBucket::WriteIndexSnapshotLocked(const std::function<uin m_LogFlushPosition = LogCount; } } - catch (std::exception& Err) + catch (const std::exception& Err) { ZEN_WARN("snapshot FAILED, reason: '{}'", Err.what()); } @@ -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 { @@ -1432,7 +1434,7 @@ ZenCacheDiskLayer::CacheBucket::Flush() SaveSnapshot(); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_WARN("Failed to flush bucket in '{}'. Reason: '{}'", m_BucketDir, Ex.what()); } @@ -1538,7 +1540,7 @@ ZenCacheDiskLayer::CacheBucket::SaveSnapshot(const std::function<uint64_t()>& Cl std::filesystem::path ManifestPath = GetManifestPath(m_BucketDir, m_BucketName); WriteFile(ManifestPath, Buffer); } - catch (std::exception& Err) + catch (const std::exception& Err) { ZEN_WARN("writing manifest in '{}' FAILED, reason: '{}'", m_BucketDir, Err.what()); } @@ -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; } @@ -1983,7 +1985,7 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) { SaveSnapshot([&]() { return GcCtx.ClaimGCReserve(); }); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_WARN("Failed to write index and manifest after GC in '{}'. Reason: '{}'", m_BucketDir, Ex.what()); } @@ -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()); }); } @@ -2920,7 +2921,7 @@ ZenCacheDiskLayer::CacheBucket::RemoveExpiredData(GcCtx& Ctx, GcStats& Stats) { SaveSnapshot([]() { return 0; }); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_WARN("Failed to write index and manifest after RemoveExpiredData in '{}'. Reason: '{}'", m_BucketDir, Ex.what()); } @@ -3033,7 +3034,7 @@ public: m_IndexLock.reset(); m_CacheBucket.m_IndexLock.WithExclusiveLock([&]() { m_CacheBucket.m_TrackedReferences.reset(); }); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_ERROR("~DiskBucketReferenceChecker threw exception: '{}'", Ex.what()); } @@ -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; @@ -3366,7 +3367,7 @@ ZenCacheDiskLayer::~ZenCacheDiskLayer() // This can cause a deadlock, if GC is running we would block while holding ZenCacheDiskLayer::m_Lock m_DroppedBuckets.clear(); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_ERROR("~ZenCacheDiskLayer() failed. Reason: '{}'", Ex.what()); } @@ -3490,7 +3491,7 @@ ZenCacheDiskLayer::DiscoverBuckets() { IsOk = DeleteDirectories(BadBucketPath); } - catch (std::exception&) + catch (const std::exception&) { } @@ -3633,14 +3634,14 @@ ZenCacheDiskLayer::Flush() { Bucket->Flush(); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_ERROR("Failed flushing bucket. Reason: '{}'", Ex.what()); } }); } } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_ERROR("Failed to flush buckets at '{}'. Reason: '{}'", m_RootDir, Ex.what()); } @@ -3877,7 +3878,7 @@ ZenCacheDiskLayer::MemCacheTrim() } }); } - catch (std::exception& Ex) + catch (const std::exception& Ex) { ZEN_ERROR("Failed scheduling ZenCacheDiskLayer::MemCacheTrim. Reason: '{}'", Ex.what()); m_IsMemCacheTrimming.store(false); |