Fix race in fsm.db (#18386)

We need to take a read lock when reading any of the FSM fields. Expose a
new fsm.Stats to handle a racy read and make sure we're consistently using
the f.db read lock wrappers.
This commit is contained in:
Mike Palmiotto 2022-12-15 10:04:27 -05:00 committed by GitHub
parent d91e69d183
commit 28d99481d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -238,6 +238,13 @@ func (f *FSM) openDBFile(dbPath string) error {
return nil
}
func (f *FSM) Stats() bolt.Stats {
f.l.RLock()
defer f.l.RUnlock()
return f.db.Stats()
}
func (f *FSM) Close() error {
f.l.RLock()
defer f.l.RUnlock()

View File

@ -555,7 +555,7 @@ func (b *RaftBackend) Close() error {
b.l.Lock()
defer b.l.Unlock()
if err := b.fsm.db.Close(); err != nil {
if err := b.fsm.Close(); err != nil {
return err
}
@ -612,7 +612,7 @@ func (b *RaftBackend) DisableUpgradeMigration() (bool, bool) {
func (b *RaftBackend) CollectMetrics(sink *metricsutil.ClusterMetricSink) {
b.l.RLock()
logstoreStats := b.stableStore.(*raftboltdb.BoltStore).Stats()
fsmStats := b.fsm.db.Stats()
fsmStats := b.fsm.Stats()
stats := b.raft.Stats()
b.l.RUnlock()
b.collectMetricsWithStats(logstoreStats, sink, "logstore")