Skip to content

Commit 0d87eb4

Browse files
committed
Merge pull request #20 from nkatsaros/master
protect accumulator values with a mutex
2 parents 480f29b + 8e90a44 commit 0d87eb4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

accumulator.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import (
44
"fmt"
55
"sort"
66
"strings"
7+
"sync"
78
"time"
89

910
"github.com/influxdb/influxdb/client"
1011
)
1112

1213
type BatchPoints struct {
14+
mu sync.Mutex
15+
1316
client.BatchPoints
1417

1518
Debug bool
@@ -20,6 +23,9 @@ type BatchPoints struct {
2023
}
2124

2225
func (bp *BatchPoints) Add(measurement string, val interface{}, tags map[string]string) {
26+
bp.mu.Lock()
27+
defer bp.mu.Unlock()
28+
2329
measurement = bp.Prefix + measurement
2430

2531
if bp.Config != nil {
@@ -55,6 +61,9 @@ func (bp *BatchPoints) AddValuesWithTime(
5561
tags map[string]string,
5662
timestamp time.Time,
5763
) {
64+
bp.mu.Lock()
65+
defer bp.mu.Unlock()
66+
5867
measurement = bp.Prefix + measurement
5968

6069
if bp.Config != nil {

0 commit comments

Comments
 (0)