diff options
| author | Per Larsson <[email protected]> | 2021-12-13 19:46:36 +0100 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-12-13 19:46:36 +0100 |
| commit | 3e666bec6605931114c1d78d48bffeeb75e3e61b (patch) | |
| tree | c8db57d3f2f7f9d6947ad6a6f8ac0b38289e4f77 /zenstore/compactcas.cpp | |
| parent | Fixed bug in z$ GC. (diff) | |
| download | zen-3e666bec6605931114c1d78d48bffeeb75e3e61b.tar.xz zen-3e666bec6605931114c1d78d48bffeeb75e3e61b.zip | |
Remove Cid to CAS chunk mapping after GC.
Diffstat (limited to 'zenstore/compactcas.cpp')
| -rw-r--r-- | zenstore/compactcas.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp index 6149873ad..d4d29c179 100644 --- a/zenstore/compactcas.cpp +++ b/zenstore/compactcas.cpp @@ -268,7 +268,8 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) Flush(); std::vector<IoHash> Candidates; - std::vector<IoHash> Keep; + std::vector<IoHash> ChunksToKeep; + std::vector<IoHash> ChunksToDelete; const uint64_t ChunkCount = m_LocationMap.size(); uint64_t TotalSize{}; @@ -280,10 +281,19 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) TotalSize += Entry.second.GetSize(); } - Keep.reserve(Candidates.size()); - GcCtx.FilterCas(Candidates, [&](const IoHash& Hash) { Keep.push_back(Hash); }); + ChunksToKeep.reserve(Candidates.size()); + GcCtx.FilterCas(Candidates, [&ChunksToKeep, &ChunksToDelete](const IoHash& Hash, bool Keep) { + if (Keep) + { + ChunksToKeep.push_back(Hash); + } + else + { + ChunksToDelete.push_back(Hash); + } + }); - if (m_LocationMap.empty() || Keep.size() == m_LocationMap.size()) + if (m_LocationMap.empty() || ChunksToKeep.size() == m_LocationMap.size()) { ZEN_INFO("garbage collect DONE, scanned #{} {} chunks from '{}', nothing to delete", ChunkCount, @@ -292,10 +302,10 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) return; } - const uint64_t NewChunkCount = Keep.size(); + const uint64_t NewChunkCount = ChunksToKeep.size(); uint64_t NewTotalSize = 0; - for (const IoHash& Key : Keep) + for (const IoHash& Key : ChunksToKeep) { const CasDiskLocation& Loc = m_LocationMap[Key]; NewTotalSize += Loc.GetSize(); @@ -347,7 +357,7 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) std::vector<uint8_t> Chunk; uint64_t NextInsertOffset{}; - for (const IoHash& Key : Keep) + for (const IoHash& Key : ChunksToKeep) { const auto Entry = m_LocationMap.find(Key); const auto& Loc = Entry->second; @@ -386,6 +396,8 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) OpenContainer(false /* IsNewStore */); + GcCtx.DeletedCas(ChunksToDelete); + ZEN_INFO("garbage collect from '{}' DONE, collected #{} {} chunks of total #{} {}", m_Config.RootDirectory / m_ContainerBaseName, ChunkCount - NewChunkCount, @@ -399,6 +411,9 @@ CasContainerStrategy::CollectGarbage(GcContext& GcCtx) // Something went wrong, try create a new container OpenContainer(true /* IsNewStore */); + + GcCtx.DeletedCas(ChunksToDelete); + GcCtx.DeletedCas(ChunksToKeep); } } |