Repository navigation
FEATURE: Add rollback and use READ COMMITTED on MySQL and MariaDB - #10
Merged
Merged
Conversation
With REPEATABLE READ, workers that wait for a subscription lock deadlock with a worker that changes the status of a subscription, because SELECT ... FOR UPDATE takes next-key locks on the status index. The level only applies to the next transaction, not to the session. rollback() is required by SubscriptionStore of subscription engine 2.0.
Worker processes compete for the same subscriptions on MySQL, MariaDB and PostgreSQL. The tests are skipped unless TEST_DATABASE_DSN is set, the new CI job sets it for each database.
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
Implements
SubscriptionStore::rollback()from bwaidelich/subscription-engine#14 and stops workers that boot concurrently from deadlocking on MySQL and MariaDB.beginTransaction() if SQLite BEGIN EXCLUSIVE return + if MySQL or MariaDB and no transaction is active + SET TRANSACTION ISOLATION LEVEL READ COMMITTED # next transaction only dbal->beginTransaction() +rollback() + ROLLBACK on SQLite, otherwise dbal->rollBack()With
REPEATABLE READ,SELECT ... FOR UPDATEtakes next-key locks on thestatusindex. A worker that activates a subscription moves its row within that index and deadlocks with workers waiting for the lock.The integration tests are skipped unless
TEST_DATABASE_DSNis set. A new CI job sets it for MySQL 8.4, MariaDB 11.4 and PostgreSQL 17.The CI job installs
wwwision/subscription-engine:2.x-dev, because the tests rely onlimitandrollback(). That step can be dropped once 2.0 is released.Evidence
Before: with 3 workers booting at once on MySQL and MariaDB,
concurrentBootsDoNotDeadlockfails withDeadlockExceptionAfter: passes
Before: workers that caught the exception and kept going ended with subscriptions in
ERRORat about 340–370 of 800 eventsAfter:
workersThatKeepGoingAfterARealDeadlockPersistEverythingprovokes real deadlocks withREPEATABLE READ, and every event is handled exactly onceOK (34 tests)TEST_DATABASE_DSNMutants that the tests catch:
rollback()as a no-op, no guard for active transactions,SET SESSIONinstead of the next transaction only.Merge Danger
Door: two-way until tagged, then one-way for the behavior change
Blast Radius: MySQL
The constraint still allows
^1, so a release also changes the isolation level for users on subscription engine 1.x. On MySQL and MariaDB, subscriber handlers that share the connection now run withREAD COMMITTEDduring a catch-up, so a handler relying on a stable snapshot across statements sees newly committed data. PostgreSQL and SQLite are unchanged, as is any transaction started outside of the store.