mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-25 21:54:10 -08:00
tsdb/wlog: close segment files sooner
'defer' runs at the end of the whole function; we should close each segment file as soon as we finished reading it. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
34875ae8c7
commit
34230bb172
|
@ -730,10 +730,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)
|
||||
}
|
||||
|
||||
|
|
|
@ -218,11 +218,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 a new issue