From 66237c1996518375001849952f2bf3c1dac423e6 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 26 Jan 2024 11:01:39 +0000 Subject: [PATCH] tsdb: use cheaper Mutex on series Mutex is 8 bytes; RWMutex is 24 bytes and much more complicated. Since `RLock` is only used in two places, `UpdateMetadata` and `Delete`, neither of which are hotspots, we should use the cheaper one. Signed-off-by: Bryan Boreham --- tsdb/head.go | 6 +++--- tsdb/head_append.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tsdb/head.go b/tsdb/head.go index cdcd3ea56..14985d277 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -1484,9 +1484,9 @@ func (h *Head) Delete(ctx context.Context, mint, maxt int64, ms ...*labels.Match continue } - series.RLock() + series.Lock() t0, t1 := series.minTime(), series.maxTime() - series.RUnlock() + series.Unlock() if t0 == math.MinInt64 || t1 == math.MinInt64 { continue } @@ -2016,7 +2016,7 @@ func (s sample) Type() chunkenc.ValueType { // memSeries is the in-memory representation of a series. None of its methods // are goroutine safe and it is the caller's responsibility to lock it. type memSeries struct { - sync.RWMutex + sync.Mutex ref chunks.HeadSeriesRef lset labels.Labels diff --git a/tsdb/head_append.go b/tsdb/head_append.go index f112ffa3a..801beb377 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -684,9 +684,9 @@ func (a *headAppender) UpdateMetadata(ref storage.SeriesRef, lset labels.Labels, return 0, fmt.Errorf("unknown series when trying to add metadata with HeadSeriesRef: %d and labels: %s", ref, lset) } - s.RLock() + s.Lock() hasNewMetadata := s.meta == nil || *s.meta != meta - s.RUnlock() + s.Unlock() if hasNewMetadata { a.metadata = append(a.metadata, record.RefMetadata{