Repository navigation
OracleBackend survives two writers starting on one table or one key at once - #531
Merged
Merged
Conversation
…t once Found by the Oracle pair of test_checkpoint_index_concurrency.py on a live database: two adapters saving to one thread raised ORA-00001 on the shared <thread_id>:latest row, and two adapters starting on a fresh table raised ORA-00955, ORA-00054 or ORA-04020 from the first-time DDL. save() is a MERGE; for a key no writer has seen both take the INSERT branch and the loser meets the primary key. The row exists once the winner commits, so save() now repeats the MERGE once on ORA-00001 and the UPDATE branch takes it. The pool is kept: nothing was wrong with the connection. _ensure_table() had every concurrent first save run CREATE TABLE and CREATE INDEX. A backend now provisions once per process under a lock bound to the event loop (locus.core.loop_bound), a CREATE another process won reads as created (ORA-00955), and a lock collision with that process's DDL or first writes (ORA-00054, ORA-04020) is retried up to five times with a short, growing wait; anything else, or a collision that never clears, propagates. This is the shape the PostgreSQL backend took in #523 for its own first-time DDL race. Tests against the fake connection of the index tests: the repeated MERGE, a violation that persists, other errors surfacing at once, both CREATEs lost, a lock collision on the index that clears, one that never does, and twenty concurrent first saves running the DDL once. Signed-off-by: Federico Kamelhar <federico.kamelhar@oracle.com>
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.
Found while running the Oracle pair of
tests/integration/test_checkpoint_index_concurrency.py(added in #526) against a live database: two adapters saving to one thread raisedORA-00001on the shared<thread_id>:latestrow, and two adapters starting on a fresh table raisedORA-00955,ORA-00054orORA-04020from the first-time DDL. Both are pre-existing races inOracleBackend, unrelated to the index work that exposed them.What changes
save()repeats itsMERGEonce onORA-00001. For a key no writer has seen, two concurrentMERGEs both take theINSERTbranch and the loser meets the primary key. The row exists once the winner commits, so the repeated statement takes theUPDATEbranch. The pool is kept, since nothing was wrong with the connection._ensure_table()provisions once per process and tolerates the other process. Every concurrent first save used to runCREATE TABLEandCREATE INDEX. The DDL now runs under a lock bound to the event loop (locus.core.loop_bound), aCREATEanother process won reads as created (ORA-00955), and a lock collision with that process's DDL or first writes (ORA-00054,ORA-04020) is retried up to five times with a short, growing wait. Anything else, or a collision that never clears, propagates. This is the shape the PostgreSQL backend took in fix(memory): PostgreSQL first-time table creation is serialised, so two processes starting together both succeed #523.Tests
Against the fake Oracle connection of the index tests: the repeated
MERGE, a violation that persists (surfaces after three attempts), other errors surfacing at once, bothCREATEs lost, a lock collision on the index that clears after two waits, one that never clears (surfaces after five attempts, backend not marked initialised), and twenty concurrent first saves running the DDL exactly once.Verification
pytest tests/unit: 11,631 passed, 657 skipped; the version-vs-installed-metadata test was deselected, as it fails for any checkout of current main in a venv whose editable install predates 5.6.0 and is unrelated to this change.ruff check,ruff format --check,mypyon the changed module: clean.CREATEs (before the change the first round failed withORA-00955and thenORA-04020). The Oracle concurrency and time-travel integration tests, 18 tests, passed three times in a row.