-
Notifications
You must be signed in to change notification settings - Fork 107
Sarama update #906
Sarama update #906
Changes from 7 commits
6711c4b
2d7fa77
e2e0b6d
e1e5d42
625f2e9
25d09a3
973585d
0a08182
e5f9f11
81fa7f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,18 +87,32 @@ func (ms *AggMetrics) Get(key schema.MKey) (Metric, bool) { | |
} | ||
|
||
func (ms *AggMetrics) GetOrCreate(key schema.MKey, schemaId, aggId uint16) Metric { | ||
ms.Lock() | ||
|
||
// in the most common case, it's already there and an Rlock is all we need | ||
ms.RLock() | ||
m, ok := ms.Metrics[key] | ||
if !ok { | ||
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)) | ||
ms.RUnlock() | ||
if ok { | ||
return m | ||
} | ||
|
||
// 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 | ||
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)) | ||
ms.Unlock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. couldn't the |
||
return m | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instantiation of
schema.AMKey
,Aggregations.Get()
andSchemas.Get()
could all happen a little further up, after we know that we need to create an entry but before we acquire the write lock, to keep the write lock short