From 8e90a444c211789faf3558d1180b851210e3293e Mon Sep 17 00:00:00 2001 From: Nicholas Katsaros Date: Sun, 21 Jun 2015 21:16:46 -0400 Subject: [PATCH] protect accumulator values with a mutex --- accumulator.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/accumulator.go b/accumulator.go index f0ed8c68c..ab5a02dae 100644 --- a/accumulator.go +++ b/accumulator.go @@ -4,12 +4,15 @@ import ( "fmt" "sort" "strings" + "sync" "time" "github.com/influxdb/influxdb/client" ) type BatchPoints struct { + mu sync.Mutex + client.BatchPoints Debug bool @@ -20,6 +23,9 @@ type BatchPoints struct { } func (bp *BatchPoints) Add(measurement string, val interface{}, tags map[string]string) { + bp.mu.Lock() + defer bp.mu.Unlock() + measurement = bp.Prefix + measurement if bp.Config != nil { @@ -55,6 +61,9 @@ func (bp *BatchPoints) AddValuesWithTime( tags map[string]string, timestamp time.Time, ) { + bp.mu.Lock() + defer bp.mu.Unlock() + measurement = bp.Prefix + measurement if bp.Config != nil {