From 78dd0681b4ea1c32a296e5af7e1512f7150e23fd Mon Sep 17 00:00:00 2001 From: bwplotka Date: Fri, 6 Mar 2026 13:48:49 +0000 Subject: [PATCH] optimization(tsdb/wlog): avoid expensive error wraps Signed-off-by: bwplotka --- tsdb/wlog/watcher.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/tsdb/wlog/watcher.go b/tsdb/wlog/watcher.go index 4bfcb083c9..851b3d2898 100644 --- a/tsdb/wlog/watcher.go +++ b/tsdb/wlog/watcher.go @@ -662,10 +662,9 @@ func (w *Watcher) readSegment(r *LiveReader, segmentNum int, tail bool) error { // We're not interested in other types of records. } } - if err := r.Err(); err != nil { - return fmt.Errorf("segment %d: %w", segmentNum, err) - } - return nil + // NOTE: r.Err == io.EOF is a common case when tailing. + // Don't wrap error, callers are expected to handle EOF and wrap accordingly. + return r.Err() } // Go through all series in a segment updating the segmentNum, so we can delete older series. @@ -696,10 +695,9 @@ func (w *Watcher) readSegmentForGC(r *LiveReader, segmentNum int, _ bool) error // We're only interested in series. } } - if err := r.Err(); err != nil { - return fmt.Errorf("segment %d: %w", segmentNum, err) - } - return nil + // NOTE: r.Err == io.EOF is a common case when tailing. + // Don't wrap error, callers are expected to handle EOF and wrap accordingly. + return r.Err() } func (w *Watcher) SetStartTime(t time.Time) { @@ -737,7 +735,7 @@ func (w *Watcher) readCheckpoint(checkpointDir string, readFn segmentReadFn) err err = readFn(w, r, index, false) sr.Close() if err != nil && !errors.Is(err, io.EOF) { - return fmt.Errorf("readSegment: %w", err) + return fmt.Errorf("readSegment %d: %w", index, err) } if r.Offset() != size {