vmalert: make group.ID() thread-safe (#1726)

Commit fixes potential race condition when group update
and generating of ID() happens simultaneously.

Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
Roman Khavronenko 2021-10-19 16:44:13 +03:00 committed by Aliaksandr Valialkin
parent 627224d493
commit ca49853664
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -123,6 +123,9 @@ func (g *Group) newRule(qb datasource.QuerierBuilder, rule config.Rule) Rule {
// ID return unique group ID that consists of
// rules file and group name
func (g *Group) ID() uint64 {
g.mu.RLock()
defer g.mu.RUnlock()
hash := fnv.New64a()
hash.Write([]byte(g.File))
hash.Write([]byte("\xff"))