Skip to content

fix(compaction): synchronize SetOnCompactionComplete with running jobs - #496

Merged
xe-nvdk merged 1 commit into
mainfrom
fix/compaction-callback-thread-safety
Jun 11, 2026
Merged

xe-nvdk merged 1 commit into
mainfrom
fix/compaction-callback-thread-safety

Conversation

@xe-nvdk

@xe-nvdk xe-nvdk commented Jun 11, 2026

Copy link
Copy Markdown
Member

Closes #351.

Summary

  • SetOnCompactionComplete wrote Manager.onCompactionComplete unsynchronized while a completing compaction job could read it concurrently — a data race under the Go memory model. The window is real: main.go starts the compaction schedulers (~line 1146/1174) before wiring the callback (~line 2067).
  • The setter now takes m.mu; CompactPartition copies the callback while it already holds m.mu for the metrics/history update, then invokes it outside the lock as before — no behavior change, no new lock ordering (the setter's only caller holds no locks, and the callback body never re-enters the Manager).
  • Adds TestSetOnCompactionCompleteConcurrent, a -race regression test verified to fail when the setter's lock is removed.
  • Release notes entry added to RELEASE_NOTES_2026.06.2.md (Bug fixes).

Test plan

  • go build ./cmd/... ./internal/...
  • go vet ./internal/compaction/ and gofmt -l clean on touched files
  • go test -race ./internal/compaction/ -count=1 passes
  • Regression test confirmed to FAIL under -race with the setter's lock removed, PASS with the fix
  • Internal config-matrix + deep review completed (no Blocker/High findings; comment-level findings addressed)

🤖 Generated with Claude Code

#351)

SetOnCompactionComplete wrote Manager.onCompactionComplete without
holding m.mu, while a completing compaction job read the same field —
a data race under the Go memory model. The window is real in our
wiring: main.go starts the compaction schedulers before wiring the
callback, so a job finishing in that gap races the write.

The setter now takes m.mu, and CompactPartition copies the callback
while it already holds m.mu for the metrics update, still invoking it
outside the lock (unchanged semantics). Adds a -race regression test
verified to fail with the setter's lock removed.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request resolves a potential data race by synchronizing the registration of the post-compaction cache-invalidation callback with running compaction jobs. Specifically, SetOnCompactionComplete now acquires the manager's mutex before writing the callback, and CompactPartition copies the callback to a local variable while holding the mutex before invoking it. A concurrent test has also been added to verify this behavior. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request resolves a data race issue (#351) by synchronizing the registration of the post-compaction cache-invalidation callback with running compaction jobs. Specifically, SetOnCompactionComplete now acquires the manager's mutex lock, and CompactPartition copies the callback to a local variable while holding the lock before executing it. A concurrent test has also been added to verify this behavior and prevent regressions. There are no review comments to address, and I have no additional feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@xe-nvdk
xe-nvdk merged commit db35eb6 into main Jun 11, 2026
5 checks passed
@xe-nvdk
xe-nvdk deleted the fix/compaction-callback-thread-safety branch June 11, 2026 14:32
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.

low(compaction): SetOnCompactionComplete not thread-safe

1 participant