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

Sarama update #906

Merged
merged 10 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docker/docker-dev-custom-cfg-kafka/gw/tsdb-gw.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ api-auth-plugin = file
kafka-tcp-addr = kafka:9092

metrics-topic = mdm
metrics-kafka-comp = none
metrics-kafka-comp = snappy
metrics-publish = true
metrics-partition-scheme = bySeries
metrics-max-in-flight = 1000000
Expand Down
34 changes: 24 additions & 10 deletions mdata/aggmetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

@replay replay May 15, 2018

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() and Schemas.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

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()
Copy link
Contributor Author

@replay replay May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't the .Unlock() happen before metricsActive.Set()? IIRC that's thread safe, just len() probably needs to be in the locked block

return m
}
6 changes: 5 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash

set -e


# Find the directory we exist within
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd ${DIR}/..
Expand All @@ -25,7 +29,7 @@ OUTPUT=$BUILDDIR/metrictank
if [ "$1" == "-race" ]
then
set -x
CGO_ENABLED=1 go build -race -ldflags "-X main.gitHash=$GITVERSION" -o $OUTPUT
go build -race -ldflags "-X main.gitHash=$GITVERSION" -o $OUTPUT
else
set -x
go build -ldflags "-X main.gitHash=$GITVERSION" -o $OUTPUT
Expand Down
31 changes: 31 additions & 0 deletions vendor/github.com/Shopify/sarama/.github/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions vendor/github.com/Shopify/sarama/.github/ISSUE_TEMPLATE.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions vendor/github.com/Shopify/sarama/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 10 additions & 8 deletions vendor/github.com/Shopify/sarama/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

180 changes: 180 additions & 0 deletions vendor/github.com/Shopify/sarama/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading