Merge pull request #20 from nkatsaros/master
protect accumulator values with a mutex
This commit is contained in:
commit
0d87eb4725
|
@ -4,12 +4,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/influxdb/influxdb/client"
|
"github.com/influxdb/influxdb/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
type BatchPoints struct {
|
type BatchPoints struct {
|
||||||
|
mu sync.Mutex
|
||||||
|
|
||||||
client.BatchPoints
|
client.BatchPoints
|
||||||
|
|
||||||
Debug bool
|
Debug bool
|
||||||
|
@ -20,6 +23,9 @@ type BatchPoints struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bp *BatchPoints) Add(measurement string, val interface{}, tags map[string]string) {
|
func (bp *BatchPoints) Add(measurement string, val interface{}, tags map[string]string) {
|
||||||
|
bp.mu.Lock()
|
||||||
|
defer bp.mu.Unlock()
|
||||||
|
|
||||||
measurement = bp.Prefix + measurement
|
measurement = bp.Prefix + measurement
|
||||||
|
|
||||||
if bp.Config != nil {
|
if bp.Config != nil {
|
||||||
|
@ -55,6 +61,9 @@ func (bp *BatchPoints) AddValuesWithTime(
|
||||||
tags map[string]string,
|
tags map[string]string,
|
||||||
timestamp time.Time,
|
timestamp time.Time,
|
||||||
) {
|
) {
|
||||||
|
bp.mu.Lock()
|
||||||
|
defer bp.mu.Unlock()
|
||||||
|
|
||||||
measurement = bp.Prefix + measurement
|
measurement = bp.Prefix + measurement
|
||||||
|
|
||||||
if bp.Config != nil {
|
if bp.Config != nil {
|
||||||
|
|
Loading…
Reference in New Issue