From 02f05cbf2c5d27eefa60fe9d8e47408b745fd052 Mon Sep 17 00:00:00 2001 From: Carrie Edwards Date: Tue, 16 Jul 2024 09:01:08 -0700 Subject: [PATCH] Ensure lastMmapRef set to 0 if mmapRefs is empty Signed-off-by: Carrie Edwards --- tsdb/ooo_head_read.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tsdb/ooo_head_read.go b/tsdb/ooo_head_read.go index 14d3724e8..2eebd8115 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