bugfix: log collect locker
This commit is contained in:
parent
cfd81a91fc
commit
18ef32a34c
|
@ -167,7 +167,6 @@ func (psc *PointsCounter) GetBytagstring(tagstring string) (*PointCounter, error
|
||||||
func (psc *PointsCounter) Update(tagstring string, value float64) error {
|
func (psc *PointsCounter) Update(tagstring string, value float64) error {
|
||||||
pointCount, err := psc.GetBytagstring(tagstring)
|
pointCount, err := psc.GetBytagstring(tagstring)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
psc.Lock()
|
|
||||||
tmp := new(PointCounter)
|
tmp := new(PointCounter)
|
||||||
tmp.Count = 0
|
tmp.Count = 0
|
||||||
tmp.Sum = 0
|
tmp.Sum = 0
|
||||||
|
@ -177,14 +176,15 @@ func (psc *PointsCounter) Update(tagstring string, value float64) error {
|
||||||
}
|
}
|
||||||
tmp.Max = math.NaN()
|
tmp.Max = math.NaN()
|
||||||
tmp.Min = math.NaN()
|
tmp.Min = math.NaN()
|
||||||
psc.TagstringMap[tagstring] = tmp
|
|
||||||
psc.Unlock()
|
|
||||||
|
|
||||||
pointCount, err = psc.GetBytagstring(tagstring)
|
var has bool
|
||||||
// 如果还是拿不到,就出错返回吧
|
psc.Lock()
|
||||||
if err != nil {
|
pointCount, has = psc.TagstringMap[tagstring]
|
||||||
return fmt.Errorf("when update, cannot get pointCount after add [tagstring:%s]", tagstring)
|
if !has {
|
||||||
|
psc.TagstringMap[tagstring] = tmp
|
||||||
|
pointCount = tmp
|
||||||
}
|
}
|
||||||
|
psc.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
pointCount.Lock()
|
pointCount.Lock()
|
||||||
|
|
Loading…
Reference in New Issue