From 73ddd4787b4d794a7b7cc28e9baecf4b7a56aea3 Mon Sep 17 00:00:00 2001 From: Jason Wilder Date: Thu, 4 May 2017 14:40:50 -0600 Subject: [PATCH] Fix race in SeriesN and CreateSeriesIfNotExists --- tsdb/index/inmem/inmem.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tsdb/index/inmem/inmem.go b/tsdb/index/inmem/inmem.go index ca40cd8ce3..d262702494 100644 --- a/tsdb/index/inmem/inmem.go +++ b/tsdb/index/inmem/inmem.go @@ -92,7 +92,10 @@ func (i *Index) SeriesSketches() (estimator.Sketch, estimator.Sketch, error) { // Since indexes are not shared across shards, the count returned by SeriesN // cannot be combined with other shards' counts. func (i *Index) SeriesN() int64 { - return int64(len(i.series)) + i.mu.RLock() + n := int64(len(i.series)) + i.mu.RUnlock() + return n } // Measurement returns the measurement object from the index by the name