From c765bf222e99874bed2de8293a1420e7f83901de Mon Sep 17 00:00:00 2001 From: Adam Bernot Date: Wed, 27 Aug 2025 18:00:25 +0000 Subject: [PATCH] refactor: watcher code cleanup Signed-off-by: Adam Bernot --- tsdb/wlog/watcher.go | 8 ++++---- tsdb/wlog/wlog.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tsdb/wlog/watcher.go b/tsdb/wlog/watcher.go index 95bd554a76..a06d49d179 100644 --- a/tsdb/wlog/watcher.go +++ b/tsdb/wlog/watcher.go @@ -293,11 +293,11 @@ func (w *Watcher) Run() error { // Backfill from the checkpoint first if it exists. lastCheckpoint, checkpointIndex, err := LastCheckpoint(w.walDir) - if err != nil && !errors.Is(err, record.ErrNotFound) { + switch { + case errors.Is(err, record.ErrNotFound): // Noop + case err != nil: return fmt.Errorf("tsdb.LastCheckpoint: %w", err) - } - - if err == nil { + default: if err = w.readCheckpoint(lastCheckpoint, (*Watcher).readSegment); err != nil { return fmt.Errorf("readCheckpoint: %w", err) } diff --git a/tsdb/wlog/wlog.go b/tsdb/wlog/wlog.go index dec41ad2c7..c7759f0b96 100644 --- a/tsdb/wlog/wlog.go +++ b/tsdb/wlog/wlog.go @@ -873,7 +873,7 @@ func (w *WL) Close() (err error) { } // Segments returns the range [first, n] of currently existing segments. -// If no segments are found, first and n are -1. +// If no segments are found, first and last are -1. func Segments(wlDir string) (first, last int, err error) { refs, err := listSegments(wlDir) if err != nil {