Skip to content

Commit 3938f63

Browse files
ultrotterGuido Trotter
andauthored
loadSnapshot: update matcher index properly while not holding lock (#4714)
Since we're building the state separately, we will do the same with the matcher index, and then update it into the Silences with the lock held. Signed-off-by: Guido Trotter <[email protected]> Co-authored-by: Guido Trotter <[email protected]>
1 parent 366e34d commit 3938f63

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

silence/silence.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,9 @@ func (s *Silences) loadSnapshot(r io.Reader) error {
893893
if err != nil {
894894
return err
895895
}
896+
897+
newMatcherIndex := matcherIndex{}
898+
896899
for _, e := range st {
897900
// Comments list was moved to a single comment. Upgrade on loading the snapshot.
898901
if len(e.Silence.Comments) > 0 {
@@ -901,7 +904,7 @@ func (s *Silences) loadSnapshot(r io.Reader) error {
901904
e.Silence.Comments = nil
902905
}
903906
// Add to matcher index, and only if successful, to the new state.
904-
if _, err := s.mi.add(e.Silence); err != nil {
907+
if _, err := newMatcherIndex.add(e.Silence); err != nil {
905908
s.metrics.matcherCompileLoadSnapshotErrorsTotal.Inc()
906909
s.logger.Error("Failed to compile silence matchers during snapshot load", "silence_id", e.Silence.Id, "err", err)
907910
} else {
@@ -910,6 +913,7 @@ func (s *Silences) loadSnapshot(r io.Reader) error {
910913
}
911914
s.mtx.Lock()
912915
s.st = st
916+
s.mi = newMatcherIndex
913917
s.version++
914918
s.mtx.Unlock()
915919

0 commit comments

Comments
 (0)