From 7d43feb03ffca86276bf6dd47b618b6986c6583a Mon Sep 17 00:00:00 2001 From: johncming Date: Thu, 22 Aug 2019 21:12:59 +0800 Subject: [PATCH] tsdb/wal: some small refactoring for easier reading (#5930) Signed-off-by: johncming --- tsdb/wal/wal.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tsdb/wal/wal.go b/tsdb/wal/wal.go index 82081e321a..1fc4965105 100644 --- a/tsdb/wal/wal.go +++ b/tsdb/wal/wal.go @@ -205,15 +205,16 @@ func NewSize(logger log.Logger, reg prometheus.Registerer, dir string, segmentSi } registerMetrics(reg, w) - _, j, err := w.Segments() - // Index of the Segment we want to open and write to. - writeSegmentIndex := 0 + _, last, err := w.Segments() if err != nil { return nil, errors.Wrap(err, "get segment range") } + + // Index of the Segment we want to open and write to. + writeSegmentIndex := 0 // If some segments already exist create one with a higher index than the last segment. - if j != -1 { - writeSegmentIndex = j + 1 + if last != -1 { + writeSegmentIndex = last + 1 } segment, err := CreateSegment(w.dir, writeSegmentIndex)