Repository navigation
perf(knowledge): lock the knowledge base row FOR NO KEY UPDATE on document writes - #8909
Merged
Merged
Conversation
…ument writes Document uploads, document hard deletes, connector creation, and knowledge base restore locked the parent knowledge_base row FOR UPDATE. Every embedding insert takes FOR KEY SHARE on that row through its foreign key and holds it for the whole indexing transaction, and FOR UPDATE conflicts with KEY SHARE, so these writes queued behind any indexing pass in the same knowledge base (and vice versa). A hard delete could also deadlock against an indexing pass on one of its own documents. FOR NO KEY UPDATE still conflicts with itself, FOR SHARE (connector sync saves and completion), FOR UPDATE (KB moves, tag mutations), and the UPDATE/DELETE of the row, so every serialization these locks provided is kept. No path under these locks writes knowledge_base.id, the only key column (the other unique indexes are partial). This matches soft deletion and connector cleanup, which already use FOR NO KEY UPDATE.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Contributor
There was a problem hiding this comment.
No issues found across 3 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Heads up: you’ve reached your flex budget. Increase your flex budget or wait for usage to reset.
Turn on auto-fix | Re-trigger cubic
Contributor
|
…olds the KB key-share lock
This branch was previously deployed
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
knowledge_baserowFOR UPDATE. Every embedding insert takesFOR KEY SHAREon that row through its foreign key for the whole indexing transaction, andFOR UPDATEconflicts with it, so these writes queued behind any indexing pass in the same knowledge base (and a hard delete could deadlock against an indexing pass on one of its own documents).FOR NO KEY UPDATE. It still conflicts with itself,FOR SHARE(connector sync),FOR UPDATE(KB move, tag mutations) and any UPDATE/DELETE of the row, so every serialization these locks provided is kept; only the foreign-keyKEY SHAREconflict goes away.FOR UPDATE(they do need to exclude child inserts). Matches soft delete and connector cleanup, which already useFOR NO KEY UPDATE.Type of Change
Testing
knowledge_base.id(the only key column) or enforces a count-based limitFOR KEY SHAREon the KB row (as an in-flight embedding insert does); withFOR UPDATEthey wait on it and the case times outChecklist
test-auditauthoring gate)