diff --git a/tsdb/ooo_head_read.go b/tsdb/ooo_head_read.go index 14d3724e8a..2eebd8115a 100644 --- a/tsdb/ooo_head_read.go +++ b/tsdb/ooo_head_read.go @@ -349,12 +349,17 @@ func NewOOOCompactionHead(ctx context.Context, head *Head) (*OOOCompactionHead, continue } + var lastMmapRef chunks.ChunkDiskMapperRef mmapRefs := ms.mmapCurrentOOOHeadChunk(head.chunkDiskMapper) if len(mmapRefs) == 0 && len(ms.ooo.oooMmappedChunks) > 0 { // Nothing was m-mapped. So take the mmapRef from the existing slice if it exists. mmapRefs = []chunks.ChunkDiskMapperRef{ms.ooo.oooMmappedChunks[len(ms.ooo.oooMmappedChunks)-1].ref} } - lastMmapRef := mmapRefs[len(mmapRefs)-1] + if len(mmapRefs) == 0 { + lastMmapRef = 0 + } else { + lastMmapRef = mmapRefs[len(mmapRefs)-1] + } seq, off := lastMmapRef.Unpack() if seq > lastSeq || (seq == lastSeq && off > lastOff) { ch.lastMmapRef, lastSeq, lastOff = lastMmapRef, seq, off