Repository navigation
[MOD-16691] Rename spec-lock state to SpecLockState and add debug-only release asserts at BG cycle boundaries (step 1) - #10353
Merged
Merged
Conversation
Pure mechanical rename, no behavior change: the enum tracked the state of the per-query spec rwlock, not generic context flags. RS_CTX_UNSET -> SPEC_LOCK_UNSET, RS_CTX_READONLY -> SPEC_LOCK_READ, RS_CTX_READWRITE -> SPEC_LOCK_WRITE, and the RedisSearchCtx field 'flags' -> 'lock_state'. Co-Authored-By: Claude Fable 5 <[email protected]>
Add RequestCycle_AssertLockUnset / RequestCycle_EnsureLockReleased bookends around every background (worker-pool) query execution cycle. The spec rwlock must be taken and released on the same worker thread within one cycle; releasing it later from another thread (request free / client unblock on the main thread) is undefined behavior for pthread_rwlock. - Entry asserts: AREQ_Execute_Callback, cursorRead_ctx, HREQ_Execute_Callback. - Exit checks: AREQ_Execute (after unlock, before the final DecrRef), runCursor (after unlock, before Cursor_Pause/Free/reply-store handoff), the AREQ_Execute_Callback error label and early-bail paths, the cursorRead dropped-index bail, and HREQ_Execute_Callback before blockedClientHybridCtx_destroy. Debug builds assert on a leaked lock; release builds recover by force-unlocking on the same worker thread and logging a warning. Coordinator BG paths are untouched (they never take the spec lock). Co-Authored-By: Claude Fable 5 <[email protected]>
Replace the RequestCycle_AssertLockUnset / RequestCycle_EnsureLockReleased helper functions (which included a release-build warn + force-unlock recovery path) with a single debug-only RedisSearchCtx_AssertLockNotHeld macro next to the lock primitives in search_ctx.h. RS_LOG_ASSERT already compiles to nothing without ENABLE_ASSERT, so release builds are untouched. Also drop the tautological early-bail checks: on those paths the entry assert already proved the lock state was clean and no code in between takes the lock. Kept sites: the three BG entry points, and the genuine post-execution exits (AREQ_Execute, the AREQ_Execute_Callback error label, runCursor, HREQ_Execute_Callback). Co-Authored-By: Claude Fable 5 <[email protected]>
GuyAv46
marked this pull request as ready for review
July 6, 2026 09:07
GuyAv46
enabled auto-merge
July 6, 2026 09:08
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #10353 +/- ##
==========================================
- Coverage 81.48% 81.39% -0.10%
==========================================
Files 541 543 +2
Lines 73331 73723 +392
Branches 28779 29026 +247
==========================================
+ Hits 59757 60009 +252
- Misses 13307 13445 +138
- Partials 267 269 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
1 of 4 tasks
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.



Describe the changes in the pull request
Step 1 of the blocked-client / cross-thread ownership refactor designed in #9426. Independent of step 0 (#10336) — the two can land in either order.
RedisSearchCtxis a misleadingly namedRSContextFlags flagsfield, and nothing checks that a background query cycle releases the spec read-lock on the worker thread that acquired it. A leaked lock would be silently released later from whichever thread happens to free the request — forpthread_rwlock_t, unlocking from a non-owning thread is undefined behavior.RSContextFlags flags→SpecLockState lock_state(SPEC_LOCK_UNSET/READ/WRITE). Lock primitives keep their exact signatures and behavior, includingRedisSearchCtx_UnlockSpec's idempotent no-op onUNSET(hybrid relies on it).ENABLE_ASSERT)RedisSearchCtx_AssertLockNotHeldmacro next to the lock primitives, and place it at the background request-cycle boundaries: the three worker-pool entry points (AREQ_Execute_Callback,cursorRead_ctx,HREQ_Execute_Callback) and the post-execution exits while the request is still provably alive (insideAREQ_Executebefore the final DecrRef, theAREQ_Execute_Callbackerror label,runCursorafter the post-sendChunkunlock, and beforeblockedClientHybridCtx_destroy). Compiles to nothing in release builds.test_blocked_client_timeout.py54/54,test_cursors.py28/28,test_hybrid_timeout.py30/30,test_multithread.py33/33.Which additional issues this PR fixes
Main objects this PR modified
RedisSearchCtx.lock_state(SpecLockState) andRedisSearchCtx_AssertLockNotHeld,src/search_ctx.h/src/redis_index.csrc/aggregate/aggregate_exec.c,src/hybrid/hybrid_exec.cMark if applicable
Release Notes
🤖 Generated with Claude Code