fix concurrent read and wirte group error (#1447)

* fix concurrent read and wirte group

Signed-off-by: denghuan <denghuan@actionsky.com>

* make lock more elegant

Signed-off-by: denghuan <denghuan@actionsky.com>
This commit is contained in:
bigMacro 2018-07-10 23:13:41 +08:00 committed by stuart nelson
parent 5aac7c840b
commit f3bc41d256
1 changed files with 2 additions and 1 deletions

View File

@ -260,12 +260,13 @@ func (d *Dispatcher) processAlert(alert *types.Alert, route *Route) {
fp := groupLabels.Fingerprint()
d.mtx.Lock()
defer d.mtx.Unlock()
group, ok := d.aggrGroups[route]
if !ok {
group = map[model.Fingerprint]*aggrGroup{}
d.aggrGroups[route] = group
}
d.mtx.Unlock()
// If the group does not exist, create it.
ag, ok := group[fp]