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:
parent
d91e69d183
commit
28d99481d3
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
|
|
Loading…
Reference in New Issue