From 87334972231a1bd6ae99ac73231a3ac8b251a590 Mon Sep 17 00:00:00 2001 From: Jan Eitzinger Date: Fri, 5 Jun 2026 08:39:49 +0200 Subject: [PATCH] Fix bug that prevents WAL cleanup on shutdown Entire-Checkpoint: 5b79628feea4 --- pkg/metricstore/metricstore.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/metricstore/metricstore.go b/pkg/metricstore/metricstore.go index 845472b2..703c470e 100644 --- a/pkg/metricstore/metricstore.go +++ b/pkg/metricstore/metricstore.go @@ -308,8 +308,14 @@ func Shutdown() { lastCheckpointMu.Unlock() if Keys.Checkpoints.FileFormat == "wal" { - // WAL files are deleted per-host inside ToCheckpointWAL workers. - files, _, err = ms.ToCheckpointWAL(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix()) + var successDirs []string + files, successDirs, err = ms.ToCheckpointWAL(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix()) + // The final binary snapshot now captures all in-memory data for these + // hosts, making their current.wal redundant. The staging goroutines have + // already exited, so remove the WAL files directly (the channel-based + // RotateWALFiles is no longer safe to call). Without this, current.wal + // files survive shutdown and keep growing across restarts. + RotateWALFilesAfterShutdown(successDirs) } else { files, err = ms.ToCheckpoint(Keys.Checkpoints.RootDir, from.Unix(), time.Now().Unix()) }