aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-11-01 19:03:42 +0100
committerStefan Boberg <[email protected]>2021-11-01 19:03:54 +0100
commitf3bd5be8beeae2bbc5a0c0612407ce8e72a9b8cf (patch)
tree368ce9f28b80900a8e424a697d3b9ee8a46b76f3
parentproject: fixed logging of new oplog entries (again) to be easier to scan (diff)
downloadzen-f3bd5be8beeae2bbc5a0c0612407ce8e72a9b8cf.tar.xz
zen-f3bd5be8beeae2bbc5a0c0612407ce8e72a9b8cf.zip
gc: added DeletionMode flag to allow gc dry runs
-rw-r--r--zenstore/filecas.cpp11
-rw-r--r--zenstore/gc.cpp13
-rw-r--r--zenstore/include/zenstore/gc.h3
3 files changed, 27 insertions, 0 deletions
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp
index c83f87c1b..0efdc96f5 100644
--- a/zenstore/filecas.cpp
+++ b/zenstore/filecas.cpp
@@ -557,13 +557,24 @@ FileCasStrategy::CollectGarbage(GcContext& GcCtx)
if (ChunksToDelete.empty())
{
+ ZEN_INFO("nothing to delete");
+
return;
}
ZEN_INFO("deleting file CAS garbage: {} chunks ({})", ChunksToDelete.size(), NiceBytes(ChunksToDeleteBytes));
+ if (GcCtx.IsDeletionMode() == false)
+ {
+ ZEN_INFO("NOTE: not actually deleting anything since deletion is disabled");
+
+ return;
+ }
+
for (const IoHash& Hash : ChunksToDelete)
{
+ ZEN_TRACE("deleting chunk {}", Hash);
+
std::error_code Ec;
DeleteChunk(Hash, Ec);
diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp
index 3395761d6..c3cb77b69 100644
--- a/zenstore/gc.cpp
+++ b/zenstore/gc.cpp
@@ -11,6 +11,7 @@ struct GcContext::GcState
{
CasChunkSet m_CasChunks;
CasChunkSet m_CidChunks;
+ bool m_DeletionMode = true;
};
GcContext::GcContext() : m_State(std::make_unique<GcState>())
@@ -45,6 +46,17 @@ GcContext::FilterCas(std::span<const IoHash> Cas, std::function<void(const IoHas
m_State->m_CasChunks.FilterChunks(Cas, [&](const IoHash& Hash) { KeepFunc(Hash); });
}
+bool
+GcContext::IsDeletionMode() const
+{
+ return m_State->m_DeletionMode;
+}
+void
+GcContext::SetDeletionMode(bool NewState)
+{
+ m_State->m_DeletionMode = NewState;
+}
+
//////////////////////////////////////////////////////////////////////////
GcContributor::GcContributor(CasGc& Gc) : m_Gc(Gc)
@@ -115,6 +127,7 @@ CasGc::CollectGarbage()
// First gather reference set
GcContext GcCtx;
+ GcCtx.SetDeletionMode(false);
for (GcContributor* Contributor : m_GcContribs)
{
diff --git a/zenstore/include/zenstore/gc.h b/zenstore/include/zenstore/gc.h
index d3092d91c..46b588570 100644
--- a/zenstore/include/zenstore/gc.h
+++ b/zenstore/include/zenstore/gc.h
@@ -30,6 +30,9 @@ public:
void FilterCids(std::span<const IoHash> Cid, std::function<void(const IoHash&)> KeepFunc);
void FilterCas(std::span<const IoHash> Cas, std::function<void(const IoHash&)> KeepFunc);
+ bool IsDeletionMode() const;
+ void SetDeletionMode(bool NewState);
+
private:
struct GcState;