Skip to content

Fix race when publishing deserialised KV maps#8064

Merged
achamayou merged 5 commits into
mainfrom
copilot/fix-deserialised-map-race
Jul 20, 2026
Merged

Fix race when publishing deserialised KV maps#8064
achamayou merged 5 commits into
mainfrom
copilot/fix-deserialised-map-race

Conversation

@achamayou

Copy link
Copy Markdown
Member

Summary

  • hold the Store map-set lock while deserialised transactions validate and publish new dynamic maps
  • add a concurrent regression that applies serialised map creations while readers look up maps

Background

fill_maps() discovers missing maps while holding maps_lock, but releases that lock before commit_deserialised() calls apply_changes(). The latter publishes each map through add_dynamic_map(), mutating Store::maps concurrently with readers in get_map_internal().

The new regression reproduces 4 TSAN warnings before the fix, with the same get_map_internal()/add_dynamic_map() access pair seen while investigating #8002. The race predates that PR.

Testing

  • Debug kv_test: passed
  • TSAN kv_test: passed with no sanitizer warnings
  • C++ formatting, includes, copyright, and ASCII checks: passed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@achamayou
achamayou requested a review from a team as a code owner July 14, 2026 19:45
Copilot AI review requested due to automatic review settings July 14, 2026 19:45
@achamayou achamayou added the run-long-test Run Long Test job label Jul 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a TSAN-detected data race in CCF’s KV Store by ensuring the map-set (Store::maps) is not mutated concurrently with map lookups when committing deserialised transactions that publish newly created dynamic maps.

Changes:

  • Hold maps_lock during Store::commit_deserialised() when new_maps is non-empty, preventing concurrent add_dynamic_map() mutations of Store::maps while readers call get_map_internal().
  • Add a concurrent regression test that applies serialised dynamic-map creations while multiple reader threads repeatedly look up a (missing) map name to exercise the previously-racy access pattern under TSAN.

Custom instructions used:

  • .github/copilot-instructions.md
  • .github/instructions/reviewing.instructions.md

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/kv/store.h Conditionally acquires maps_lock across apply_changes() during deserialised commits when dynamic maps may be published.
src/kv/test/kv_dynamic_tables.cpp Adds a TSAN-focused concurrency regression test covering concurrent map publication vs. map lookup.

@achamayou
achamayou enabled auto-merge (squash) July 20, 2026 19:52
@achamayou
achamayou merged commit a16d993 into main Jul 20, 2026
19 checks passed
@achamayou
achamayou deleted the copilot/fix-deserialised-map-race branch July 20, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-long-test Run Long Test job

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants