Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

Commit

Permalink
address comments re critical section
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed May 15, 2018
1 parent e5f9f11 commit 81fa7f5
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions mdata/aggmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 81fa7f5

Please sign in to comment.