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 GitHub
parent dcd881bb7a
commit bdfac4ff53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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 // ID return unique group ID that consists of
// rules file and group name // rules file and group name
func (g *Group) ID() uint64 { func (g *Group) ID() uint64 {
g.mu.RLock()
defer g.mu.RUnlock()
hash := fnv.New64a() hash := fnv.New64a()
hash.Write([]byte(g.File)) hash.Write([]byte(g.File))
hash.Write([]byte("\xff")) hash.Write([]byte("\xff"))