From 7cdafe520216f01f27094dc4a353256071510922 Mon Sep 17 00:00:00 2001 From: Dan Engelbrecht Date: Fri, 20 Oct 2023 13:31:09 +0200 Subject: Don't prune block locations due to missing blocks a startup (#487) * Don't prune block locations due to missing blocks a startup This makes the behaviour consistent with FileCas - you can have an index that is not fully backed by data. Asking for a location that is not backed by data results in getting an empty result back Also, don't try to GC blocks that are unknown to the block store at the time of snapshot (to avoid removing data that comes in after GatherReferences in GC) --- src/zenserver/cache/cachedisklayer.cpp | 60 ++-------------------------------- 1 file changed, 3 insertions(+), 57 deletions(-) (limited to 'src/zenserver/cache/cachedisklayer.cpp') diff --git a/src/zenserver/cache/cachedisklayer.cpp b/src/zenserver/cache/cachedisklayer.cpp index ebefa2e54..3cd725a27 100644 --- a/src/zenserver/cache/cachedisklayer.cpp +++ b/src/zenserver/cache/cachedisklayer.cpp @@ -604,8 +604,7 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew) CreateDirectories(m_BucketDir); - std::unordered_map BlockSizes = - m_BlockStore.Initialize(m_BlocksBasePath, MaxBlockSize, BlockStoreDiskLocation::MaxBlockIndex + 1); + m_BlockStore.Initialize(m_BlocksBasePath, MaxBlockSize, BlockStoreDiskLocation::MaxBlockIndex + 1); if (std::filesystem::is_regular_file(IndexPath)) { @@ -636,7 +635,6 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew) std::vector KnownLocations; KnownLocations.reserve(m_Index.size()); - std::vector BadEntries; for (const auto& Entry : m_Index) { size_t EntryIndex = Entry.second; @@ -649,48 +647,10 @@ ZenCacheDiskLayer::CacheBucket::OpenLog(const bool IsNew) continue; } const BlockStoreLocation& BlockLocation = Location.GetBlockLocation(m_PayloadAlignment); - - auto BlockIt = BlockSizes.find(BlockLocation.BlockIndex); - if (BlockIt == BlockSizes.end()) - { - ZEN_WARN("Unknown block {} for entry {} in '{}'", BlockLocation.BlockIndex, Entry.first.ToHexString(), m_BucketDir); - } - else - { - uint64_t BlockSize = BlockIt->second; - if (BlockLocation.Offset + BlockLocation.Size > BlockSize) - { - ZEN_WARN("Range is outside of block {} for entry {} in '{}'", - BlockLocation.BlockIndex, - Entry.first.ToHexString(), - m_BucketDir); - } - else - { - KnownLocations.push_back(BlockLocation); - continue; - } - } - - DiskLocation NewLocation = Payload.Location; - NewLocation.Flags |= DiskLocation::kTombStone; - BadEntries.push_back(DiskIndexEntry{.Key = Entry.first, .Location = NewLocation}); + KnownLocations.push_back(BlockLocation); } - if (!BadEntries.empty()) - { - m_SlogFile.Append(BadEntries); - m_SlogFile.Flush(); - - LogEntryCount += BadEntries.size(); - - for (const DiskIndexEntry& BadEntry : BadEntries) - { - m_Index.erase(BadEntry.Key); - } - } - - m_BlockStore.Prune(KnownLocations); + m_BlockStore.CreateMissingBlocks(KnownLocations); if (IsNew || LogEntryCount > 0) { @@ -1558,11 +1518,6 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) } DeleteCacheKeys.push_back(ChunkHash); }); - if (DeleteCacheKeys.empty()) - { - ZEN_DEBUG("garbage collect SKIPPED, for '{}', no expired cache keys found", m_BucketDir); - return; - } auto __ = MakeGuard([&]() { if (!DeletedChunks.empty()) @@ -1638,11 +1593,6 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) WriteBlockTimeUs += ElapsedUs; WriteBlockLongestTimeUs = std::max(ElapsedUs, WriteBlockLongestTimeUs); }); - if (m_Index.empty()) - { - ZEN_DEBUG("garbage collect SKIPPED, for '{}', container is empty", m_BucketDir); - return; - } BlockStoreState = m_BlockStore.GetReclaimSnapshotState(); @@ -1769,10 +1719,6 @@ ZenCacheDiskLayer::CacheBucket::CollectGarbage(GcContext& GcCtx) } } - if (TotalChunkHashes.empty()) - { - return; - } TotalChunkCount = TotalChunkHashes.size(); std::vector ChunkLocations; -- cgit v1.2.3