From f26907785547784901126195536e13ad3021cfdd Mon Sep 17 00:00:00 2001 From: Jesus Vazquez Date: Fri, 10 Feb 2023 12:52:12 +0100 Subject: [PATCH] Protect NewOOOCompactionHead from an unitialized wbl Signed-off-by: Jesus Vazquez --- tsdb/ooo_head_read.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tsdb/ooo_head_read.go b/tsdb/ooo_head_read.go index 9feb6bc6f..0552c6053 100644 --- a/tsdb/ooo_head_read.go +++ b/tsdb/ooo_head_read.go @@ -276,16 +276,18 @@ type OOOCompactionHead struct { // All the above together have a bit of CPU and memory overhead, and can have a bit of impact // on the sample append latency. So call NewOOOCompactionHead only right before compaction. func NewOOOCompactionHead(head *Head) (*OOOCompactionHead, error) { - newWBLFile, err := head.wbl.NextSegmentSync() - if err != nil { - return nil, err - } - ch := &OOOCompactionHead{ chunkRange: head.chunkRange.Load(), mint: math.MaxInt64, maxt: math.MinInt64, - lastWBLFile: newWBLFile, + lastWBLFile: 0, + } + if head.wbl != nil { + lastWBLFile, err := head.wbl.NextSegmentSync() + if err != nil { + return nil, err + } + ch.lastWBLFile = lastWBLFile } ch.oooIR = NewOOOHeadIndexReader(head, math.MinInt64, math.MaxInt64)