Retry MariaDB snapshot-isolation error 1020 as a deadlock - #41084
Open
thai2301 wants to merge 1 commit into
Open
Retry MariaDB snapshot-isolation error 1020 as a deadlock#41084thai2301 wants to merge 1 commit into
thai2301 wants to merge 1 commit into
Conversation
MariaDB enables innodb_snapshot_isolation by default since 11.6.2 (MDEV-35124), now reachable on supported MariaDB 11.8 / 12.3. Under it, a locking read on a row a committed concurrent transaction changed fails with error 1020 (Record has changed since last read) and a full rollback, where it previously succeeded. MariaDB's guidance is to restart the transaction, i.e. it is semantically a deadlock. The adapter's exceptionMap did not map 1020, so it surfaced as a generic exception that DeadlockRecoveryExecutor (and other deadlock-aware retry paths) would not retry, breaking concurrent catalog writes / price reindex under load. Map 1020 to DeadlockException so it is retried the same way as 1213.
|
Hi @thai2301. Thank you for your contribution!
Allowed build names are:
You can find more information about the builds here For more details, review the Code Contributions documentation. |
5 tasks
Author
|
@magento run all tests |
Author
|
@magento run Functional Tests B2B, Functional Tests CE, Functional Tests EE, WebAPI Tests |
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
MariaDB enables
innodb_snapshot_isolationby default since 11.6.2 (MDEV-35124), which is now reachable on the officially supported MariaDB 11.8 (since 2.4.8-p5) and 12.3 (since 2.4.9). Under it, a locking read on a row that a committed concurrent transaction has changed no longer succeeds silently — it fails with error 1020 (Record has changed since last read ...; try restarting transaction) and rolls the whole transaction back. MariaDB's guidance is to restart the transaction, i.e. it is semantically equivalent to a deadlock (1213).Magento\Framework\DB\Adapter\Pdo\Mysql::$exceptionMapmaps 2006 / 2013 / 1205 / 1213 / 1062 / 1146 to typed exceptions but not 1020, so error 1020 surfaced as a generic exception thatDeadlockRecoveryExecutor(and other deadlock-aware retry paths, which catchDeadlockException/LockWaitException) would not retry. The result is frequent, avoidable failures during concurrent catalog writes / price reindex under load on supported MariaDB versions.This maps 1020 to
DeadlockException, so it is retried the same way as 1213 wherever deadlock recovery is already applied, instead of requiring operators to work around it withinnodb_snapshot_isolation=OFF.Related Issue
Fixes #41047
Manual testing scenarios
innodb_snapshot_isolation=ON(the default), run a workload with concurrent catalog writes that trigger a price reindex under load.SQLSTATE[HY000]: General error: 1020 Record has changed since last read in table '...', with no retry.DeadlockExceptionand retried by the existing deadlock-recovery path, so the operation completes without operator intervention.Questions or comments
The reporter (and MariaDB's own documentation) classify 1020 as "restart the transaction", which matches Magento's deadlock semantics rather than lock-wait; hence the mapping to
DeadlockException(same as 1213) rather thanLockWaitException.Contribution checklist