From 81fa7f5708b55c1dcd37f03505e1e57218caa277 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Tue, 15 May 2018 19:04:12 +0200 Subject: [PATCH] address comments re critical section --- mdata/aggmetrics.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/mdata/aggmetrics.go b/mdata/aggmetrics.go index fec1b2de5e..1d9e912dac 100644 --- a/mdata/aggmetrics.go +++ b/mdata/aggmetrics.go @@ -96,23 +96,26 @@ func (ms *AggMetrics) GetOrCreate(key schema.MKey, schemaId, aggId uint16) Metri return m } + k := schema.AMKey{ + MKey: key, + } + + agg := Aggregations.Get(aggId) + schema := Schemas.Get(schemaId) + // if it wasn't there, get the write lock and prepare to add it // but first we need to check again if someone has added it in - // the meantime + // the meantime (quite rare, but anyway) ms.Lock() m, ok = ms.Metrics[key] if ok { ms.Unlock() return m } - k := schema.AMKey{ - MKey: key, - } - agg := Aggregations.Get(aggId) - schema := Schemas.Get(schemaId) m = NewAggMetric(ms.store, ms.cachePusher, k, schema.Retentions, schema.ReorderWindow, &agg, ms.dropFirstChunk) ms.Metrics[key] = m - metricsActive.Set(len(ms.Metrics)) + active := len(ms.Metrics) ms.Unlock() + metricsActive.Set(active) return m }