New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix transactions and data consistency #2041
Fix transactions and data consistency #2041
Conversation
5c081d0
to
e22341a
Compare
Hi @UlrichThomasGabor, |
Hello, thank you for creating this pull request. Please use this issue to track the state of your pull request. |
…ise we loose consistency
… anyway. Introduced transactions in various places to improve data consistency.
92f74fc
to
02eb5b1
Compare
I close this PR since it was merged with 43fe96e. |
@Dominik28111 There is a to-do-list at the end and especially:
is important because otherwise the new |
@UlrichThomasGabor is this fix already released? |
@digitalkaoz The PR yes. I did not keep track of the |
Happens to me a lot when using the sync API at scale. Any workarounds? Downgrading PHP would bei possible but not a solution |
What happens a lot (error message)? Since that was merged I encountered not a single transaction-related fault |
a lot of "There is no active transaction" when transaction is autocommitted (during sync API usage) |
Related to this yiisoft/yii2#18406 or this doctrine/migrations#1202 (all related to the same PHP 8 commit) |
Dunno If its even related to your changes, i guessed that |
You are using Shopware >= 6.4.5? My changes should have fixed all that. The error can still happen if exceptions are caught, which should not be caught, i.e. catching all exceptions If it's not that, than something else is still done wrong... |
Yes, latest Shopware with PHP 8. As i said im using the default sync API
with async scheduling tasks in the back. Nothing fancy, happens only when
there are a lot of syncs.
Dr. Ulrich Thomas Gabor ***@***.***> schrieb am Di., 8. Feb.
2022, 20:07:
… You are using Shopware >= 6.4.5?
My changes should have fixed all that.
The error can still happen if exceptions are caught, which should not be
caught, i.e. catching all exceptions (catch \Exception) { // do not
rethrow } is very bad. Same goes for DBAL-related exceptions (basically
everything in that namespace). You can search all of Shopware and the
plugins you use for that pattern. Maybe something was missed (or
re-introduced...)
If it's not that, than something else is still done wrong...
—
Reply to this email directly, view it on GitHub
<#2041 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHVV7ZCRKTXVXBAIBGVT3U2FSVPANCNFSM5C6HRG2Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Im refering to this issue https://issues.shopware.com/issues/NEXT-15805
which doesnt seem to be resolved with your fix?
As PHP8 is coming to town quickly i would consider it a major problem
Robert Schönthal ***@***.***> schrieb am Di., 8. Feb.
2022, 21:27:
… Yes, latest Shopware with PHP 8. As i said im using the default sync API
with async scheduling tasks in the back. Nothing fancy, happens only when
there are a lot of syncs.
Dr. Ulrich Thomas Gabor ***@***.***> schrieb am Di., 8.
Feb. 2022, 20:07:
> You are using Shopware >= 6.4.5?
>
> My changes should have fixed all that.
>
> The error can still happen if exceptions are caught, which should not be
> caught, i.e. catching all exceptions (catch \Exception) { // do not
> rethrow } is very bad. Same goes for DBAL-related exceptions (basically
> everything in that namespace). You can search all of Shopware and the
> plugins you use for that pattern. Maybe something was missed (or
> re-introduced...)
>
> If it's not that, than something else is still done wrong...
>
> —
> Reply to this email directly, view it on GitHub
> <#2041 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AACHVV7ZCRKTXVXBAIBGVT3U2FSVPANCNFSM5C6HRG2Q>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
>
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>
|
This issue should be fixed, if the Like I said, I'd start by looking at all catch blocks |
Using |
Its a Stock Shopware, 0 lines of PHP Code changed or written...
Dr. Ulrich Thomas Gabor ***@***.***> schrieb am Di., 8. Feb.
2022, 21:43:
… Using commit, beginTransaction or rollback by hand can also break the
transaction flow. They should not be used outside of RetryableTransaction
—
Reply to this email directly, view it on GitHub
<#2041 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHVV5QPCCKGK3QPNCIMMDU2F555ANCNFSM5C6HRG2Q>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Might be that we forgot something last time or something was done wrongly since then. Shopware is changing a lot |
@OliverSkroblin As discussed. #1668 should be merged first. After that I can rebase my branch to the then-current trunk.
1. Why is this change necessary?
This PR fixes various transaction issues and improves data consistency.
2. What does this change do, exactly?
beginTransaction
have been replaced with the newRetryableTransaction
class, as it provides a cleaner interface anyway and the previous code did not executerollback
on exceptions.MultiInsertQueryQueue
now usesRetryableTransaction
as well as there is no use case where it is desirable that half of the inserts is in the DB and then the execution of the script stops and the other half is left in the wide nothingness.3. Describe each step to reproduce the issue or behaviour.
4. Please link to the relevant issues (if any).
This fixes all issues I mentioned in the pull request #1668.
This also fixes https://issues.shopware.com/issues/NEXT-15805.
5. Checklist
6. To-Do-List
beginTransaction
,commit
orrollback
calls. All transactions should be implemented usingRetryableTransaction
.catch (\Exception)
orcatch (\Throwable)
. This is code-smell, i.e. one likely never wants to catch ALL exceptions. You might want to review (i.e. remove) these.IGNORE
s are not necessary anymore. The second-best solution is to changeRetryableTransaction
to pass an argument to the transactional closure (I guess this has to be done viaClosure::bind
to not interfere with Doctrine), passing in its retry$counter
so the closure can determine if this is the first execution or a following one. In the following cases, it could perform anINSERT IGNORE
instead.$connection->setNestTransactionsWithSavepoints(true)
globally.