You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CBG-5472: Make the stats logger independent of the database lock
The stats logger could stall, leaving gaps in sg_stats.log, whenever a
database config update held a lock the stats path also needed. Two
independent locks were involved:
- _databasesLock: updateCalculatedStats took RLock, but a config update
holds the write lock across an infinite index-readiness wait, blocking
the reader for the whole (unbounded) window.
- base.SgwStats.dbStatsMapMutex: String() held it for the entire marshal,
and NewDBStats/ClearDBStats held it for all Prometheus (un)registration
under _databasesLock.
Decouple the reader from both:
- ServerContext now keeps a lock-free atomic snapshot of the database
contexts, refreshed under _databasesLock at each _databases mutation.
updateCalculatedStats reads the snapshot, never the lock.
- dbStatsMapMutex is now held only for the map operation: String()
marshals a shallow copy, and NewDBStats/ClearDBStats do their Prometheus
work outside the lock. The unregister* calls only touch Prometheus (not
the DbStats maps), so this stays race-free.
The stats ticker now keeps emitting (stale-but-present) while databases
are added, removed or reloaded.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0 commit comments