optimization(tsdb/wlog): avoid expensive error wraps

Signed-off-by: bwplotka <bwplotka@gmail.com>
This commit is contained in:
bwplotka 2026-03-06 13:48:49 +00:00
parent 87cc6d3bb9
commit 23201b2f90

View file

@ -673,10 +673,9 @@ func (w *Watcher) readSegment(r *LiveReader, segmentNum int, tail bool) (err err
// 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.
@ -709,10 +708,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) {
@ -750,7 +748,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 {