diff options
Diffstat (limited to 'zenstore')
| -rw-r--r-- | zenstore/filecas.cpp | 70 |
1 files changed, 60 insertions, 10 deletions
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp index 0714637c6..c83f87c1b 100644 --- a/zenstore/filecas.cpp +++ b/zenstore/filecas.cpp @@ -560,7 +560,7 @@ FileCasStrategy::CollectGarbage(GcContext& GcCtx) return; } - ZEN_INFO("deleting file CAS garbage: {} chunks ({})", ChunkCount.load(), NiceBytes(ChunksToDeleteBytes)); + ZEN_INFO("deleting file CAS garbage: {} chunks ({})", ChunksToDelete.size(), NiceBytes(ChunksToDeleteBytes)); for (const IoHash& Hash : ChunksToDelete) { @@ -673,20 +673,70 @@ TEST_CASE("cas.file.gc") FileCasStrategy FileCas(CasConfig, Gc); FileCas.Initialize(/* IsNewStore */ true); - for (int i = 0; i < 1000; ++i) + const int kIterationCount = 1000; + std::vector<IoHash> Keys{kIterationCount}; + + auto InsertChunks = [&] { + for (int i = 0; i < kIterationCount; ++i) + { + CbObjectWriter Cbo; + Cbo << "id" << i; + CbObject Obj = Cbo.Save(); + + IoBuffer ObjBuffer = Obj.GetBuffer().AsIoBuffer(); + IoHash Hash = HashBuffer(ObjBuffer); + + FileCas.InsertChunk(ObjBuffer, Hash); + + Keys[i] = Hash; + } + }; + + // Drop everything + { - CbObjectWriter Cbo; - Cbo << "id" << i; - CbObject Obj = Cbo.Save(); + InsertChunks(); - IoBuffer ObjBuffer = Obj.GetBuffer().AsIoBuffer(); - IoHash Hash = HashBuffer(ObjBuffer); + GcContext Ctx; + FileCas.CollectGarbage(Ctx); - FileCas.InsertChunk(ObjBuffer, Hash); + for (const IoHash& Key : Keys) + { + IoBuffer Chunk = FileCas.FindChunk(Key); + + CHECK(!Chunk); + } } - GcContext Ctx; - FileCas.CollectGarbage(Ctx); + // Keep roughly half of the chunks + + { + InsertChunks(); + + GcContext Ctx; + + for (const IoHash& Key : Keys) + { + if (Key.Hash[0] & 1) + { + Ctx.ContributeCas(std::vector<IoHash>{Key}); + } + } + + FileCas.CollectGarbage(Ctx); + + for (const IoHash& Key : Keys) + { + if (Key.Hash[0] & 1) + { + CHECK(FileCas.FindChunk(Key)); + } + else + { + CHECK(!FileCas.FindChunk(Key)); + } + } + } } #endif |