Fix chunk delete deadlock ordering#2570
Merged
Merged
Conversation
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.
Summary
Why
Concurrent
DELETE FROM chunks ...statements can let PostgreSQL's FK cascade lock overlappingmemory_linksrows in executor-chosen order. When two writers delete overlapping chunk graphs, that can produce AB/BA row-lock deadlocks. Explicitly deleting the affected links in a stable order removes the unordered cascade as the first lock owner.Fixes #2560.
Supersedes #2569, which was closed when the fork branch was renamed.
Validation
uv run --project hindsight-api-slim pytest -q hindsight-api-slim/tests/test_chunk_storage_delete_ordering.pyuv run --project hindsight-api-slim ruff format --check hindsight-api-slim/hindsight_api/engine/retain/chunk_storage.py hindsight-api-slim/tests/test_chunk_storage_delete_ordering.pyuv run --project hindsight-api-slim ruff check hindsight-api-slim/hindsight_api/engine/retain/chunk_storage.py hindsight-api-slim/tests/test_chunk_storage_delete_ordering.py