mirror of https://github.com/prometheus/prometheus
Merge pull request #13200 from bboreham/wlog-defer
tsdb/wlog: close segment files soonerpull/14611/head^2
commit
aa4b056ad0
|
@ -689,10 +689,11 @@ func (w *Watcher) readCheckpoint(checkpointDir string, readFn segmentReadFn) err
|
|||
if err != nil {
|
||||
return fmt.Errorf("unable to open segment: %w", err)
|
||||
}
|
||||
defer sr.Close()
|
||||
|
||||
r := NewLiveReader(w.logger, w.readerMetrics, sr)
|
||||
if err := readFn(w, r, index, false); err != nil && !errors.Is(err, io.EOF) {
|
||||
err = readFn(w, r, index, false)
|
||||
sr.Close()
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return fmt.Errorf("readSegment: %w", err)
|
||||
}
|
||||
|
||||
|
|
|
@ -230,11 +230,11 @@ func TestTailSamples(t *testing.T) {
|
|||
for i := first; i <= last; i++ {
|
||||
segment, err := OpenReadSegment(SegmentName(watcher.walDir, i))
|
||||
require.NoError(t, err)
|
||||
defer segment.Close()
|
||||
|
||||
reader := NewLiveReader(nil, NewLiveReaderMetrics(nil), segment)
|
||||
// Use tail true so we can ensure we got the right number of samples.
|
||||
watcher.readSegment(reader, i, true)
|
||||
require.NoError(t, segment.Close())
|
||||
}
|
||||
|
||||
expectedSeries := seriesCount
|
||||
|
|
Loading…
Reference in New Issue