mvcc: fix autoincrement handling#5691
Draft
PThorpe92 wants to merge 8 commits intotursodatabase:mainfrom
Draft
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.
Description
Addressing #5687 and adds some of the tests added in that PR.
Problem
AUTOINCREMENTin MVCC had two correctness issues:WriteWriteConflictonsqlite_sequence.INSERT/UPDATE rowid/DELETEworkloads, auto-assigned rowids could diverge from SQLite semantics (including monotonicity failures in fuzzed cases).Solution
At a high level:
MVCC now treats
sqlite_sequencespecially for conflict/read semantics:sqlite_sequenceat delete/commit timesqlite_sequence, prefer the visible version with the highestseqInsert translation was tightened so sequence-row updates are stable and deterministic in MVCC:
REQUIRE_SEEKto avoid duplicate sequence-row artifactsmax(sqlite_sequence.seq, current table max rowid)NewRowidso concurrent allocation remains allocator-driven but never falls behind sequence/table stateUPDATE ... SET rowid=...writes are marked and applied without bumping the allocator as if they were normal autogen insertsNewRowidinitialization is normalized to SQLite-compatible behavior for autogen allocation.