aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-11-01 16:47:52 +0100
committerStefan Boberg <[email protected]>2021-11-01 16:47:52 +0100
commit5b81bfcd36e6e76c641e19c512550e5fd4302da0 (patch)
treed04a6478fe55d6b933250cdf68865c3849acb81c
parentgc: Implemented initial root gathering for projects/oplogs (diff)
downloadzen-5b81bfcd36e6e76c641e19c512550e5fd4302da0.tar.xz
zen-5b81bfcd36e6e76c641e19c512550e5fd4302da0.zip
filecas: Fixed debug logging
-rw-r--r--zenstore/filecas.cpp70
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