Conversation
bbrks
force-pushed
the
CBG-5472
branch
3 times, most recently
from
July 16, 2026 20:55
1e27930 to
f2a7a17
Compare
The stats logger could stall, leaving gaps in sg_stats.log, whenever a database config update held a lock the stats path also needed: - _databasesLock: updateCalculatedStats took RLock, but a config update holds the write lock across an unbounded index-readiness wait. - the per-db stats map mutex, contended by serialization and Prometheus (un)registration. Decouple the stats reader from both: - ServerContext keeps a lock-free atomic snapshot of the database contexts, refreshed under _databasesLock at each _databases mutation; updateCalculatedStats reads the snapshot instead of taking the lock. - The concurrently-mutated stats maps (per-db and per-db replicator) are now a generic snapshotMap that serializes itself under its own lock (snapshot-then-marshal) and performs Prometheus (un)registration outside it, so serialization neither blocks nor is blocked by database registration/removal. Serialized stats output is unchanged (per_db always present; empty replications omitted via omitzero). The stats ticker keeps emitting while databases are added, removed or reloaded. The stats-definition-exporter traverses the stats tree by reflection; teach it to descend into a snapshotMap via the new StatMapValues accessor (the previous map field was handled by the reflect.Map branch). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CBG-5472
Avoid blocking stats logger from database updates and initialisations. Access lock-free version of databases on ServerContext to build stats and minimise the locking required inside DbStats.
Pre-review checklist
Dependencies (if applicable)
Integration Tests