Skip to content

CBG-5472 part 3 of 3: read databases lock-free when collecting calculated stats - #8684

Open
bbrks wants to merge 1 commit into
mainfrom
CBG-5472-stats-snapshot
Open

CBG-5472 part 3 of 3: read databases lock-free when collecting calculated stats#8684
bbrks wants to merge 1 commit into
mainfrom
CBG-5472-stats-snapshot

Conversation

@bbrks

@bbrks bbrks commented Aug 26, 2026

Copy link
Copy Markdown
Member

CBG-5472

Part 3 of 3 split from #8431 - which had in-PR requested changes that ended up spiralling away from the original ticket.

Integration Tests

@factory-droid

factory-droid Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Droid finished @bbrks's task —— View job


LGTM — the lock-free databases snapshot approach looks correct, and the added tests cover the intended regression and concurrency cases.

Base automatically changed from CBG-5472-db-stopping to main August 26, 2026 23:23
@torcolvin
torcolvin requested a review from a team August 26, 2026 23:23
updateCalculatedStats took _databasesLock for read, which a config update can
hold for write across a long wait on index readiness. The stats logger then
stalls for the duration, so the collection it is in the middle of is late or
missed entirely.

Keep an atomic snapshot of the _databases values alongside the map, refreshed
by _addDatabase/_deleteDatabase/_clearDatabases, and have updateCalculatedStats
read that instead. It now never blocks on the lock.

Dropping the lock means the reader can see a database that is being torn down,
since _unloadDatabase closes the context under the write lock it no longer
waits for. The DBStopping state Close sets is what keeps it out: the DBOnline
guard skips it, and _unloadDatabase drops it from the snapshot before calling
Close so the reader stops seeing it first.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@bbrks
bbrks force-pushed the CBG-5472-stats-snapshot branch from 2f1bdbe to 96bd1c8 Compare August 27, 2026 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant