From ea2bfbb6aa3219575e080006884c2b4b75f1c047 Mon Sep 17 00:00:00 2001 From: Aditya Ujeniya Date: Wed, 8 Jul 2026 14:31:26 +0200 Subject: [PATCH] fix: wire NodeProvider into CLI checkpoint cleanup path The -cleanup-checkpoints CLI flag called CleanupCheckpoints without initializing the MemoryStore singleton or setting its NodeProvider, so it silently fell back to legacy clean-everything behavior and could delete checkpoints for hosts with running jobs. Inject the job repository as NodeProvider the same way runServer does, so the CLI path also skips used hosts. Also update SetNodeProvider's doc comment, which only mentioned Free but is now also consulted by FromCheckpoint and CleanupCheckpoints. Co-Authored-By: Claude Fable 5 --- cmd/cc-backend/main.go | 5 +++++ pkg/metricstore/metricstore.go | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/cmd/cc-backend/main.go b/cmd/cc-backend/main.go index 2db9a9f2..d515332f 100644 --- a/cmd/cc-backend/main.go +++ b/cmd/cc-backend/main.go @@ -589,6 +589,11 @@ func run() error { cleanupDir = metricstore.Keys.Cleanup.RootDir } + // Wire the job repository as NodeProvider so cleanup skips hosts + // with running jobs (same injection as runServer). + metricstore.InitMetrics(metricstore.BuildMetricList()) + metricstore.GetMemoryStore().SetNodeProvider(repository.GetJobRepository()) + cclog.Infof("Cleaning up checkpoints older than %s...", from.Format(time.RFC3339)) n, err := metricstore.CleanupCheckpoints( metricstore.Keys.Checkpoints.RootDir, cleanupDir, from.Unix(), deleteMode) diff --git a/pkg/metricstore/metricstore.go b/pkg/metricstore/metricstore.go index c59b67e5..c763a903 100644 --- a/pkg/metricstore/metricstore.go +++ b/pkg/metricstore/metricstore.go @@ -251,9 +251,11 @@ func (ms *MemoryStore) GetMetricFrequency(metricName string) (int64, error) { } // SetNodeProvider sets the NodeProvider implementation for the MemoryStore. -// This must be called during initialization to provide job state information -// for selective buffer retention during Free operations. -// If not set, the Free function will fall back to freeing all buffers. +// The provider supplies the set of nodes in use by running jobs, which is +// consulted by Free (selective buffer retention), FromCheckpoint (full-history +// loading for used hosts), and CleanupCheckpoints (skipping used hosts). +// It must be set before Init(): the checkpoint load inside Init reads it. +// If not set, all three fall back to their provider-less behavior. func (ms *MemoryStore) SetNodeProvider(provider NodeProvider) { ms.nodeProvider = provider }