From ccd0308abcb98505797161b9142da1fe9ddbe88c Mon Sep 17 00:00:00 2001 From: Oleg Zaytsev Date: Wed, 25 Sep 2024 14:59:16 +0200 Subject: [PATCH] Don't do anything if MemPostings are empty Signed-off-by: Oleg Zaytsev --- tsdb/index/postings.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tsdb/index/postings.go b/tsdb/index/postings.go index 3164d8c2fb..e6a6c708ff 100644 --- a/tsdb/index/postings.go +++ b/tsdb/index/postings.go @@ -293,10 +293,12 @@ func (p *MemPostings) EnsureOrder(numberOfConcurrentProcesses int) { func (p *MemPostings) Delete(deleted map[storage.SeriesRef]struct{}, affected map[labels.Label]struct{}) { p.mtx.Lock() defer p.mtx.Unlock() + if len(p.m) == 0 || len(deleted) == 0 { + return + } // Deleting label names mutates p.m map, so it should be done from a single goroutine after nobody else is reading it. - // Adding +1 to length to account for allPostingsKey processing when MemPostings is empty. - deleteLabelNames := make(chan string, len(p.m)+1) + deleteLabelNames := make(chan string, len(p.m)) process := func(l labels.Label) { orig := p.m[l.Name][l.Value]