Skip to content
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

[10.x] Fixed implementation related to afterCommit on Postgres and MSSQL database drivers #48662

Merged
merged 10 commits into from
Oct 9, 2023

Conversation

SakiTakamachi
Copy link
Contributor

@SakiTakamachi SakiTakamachi commented Oct 7, 2023

Overview

fixes #48658

Hi

I checked the implementation regarding afterCommit, fixed defects, and deleted unused functions.

Cause of the problem

The cause was that by calling afterCommit before lowering the transaction level, the transaction behaved as if it existed, even though it actually did not.

I solved this problem by lowering the transaction level before calling afterCommit, and by lowering the level expected by afterCommitCallbacksShouldBeExecuted() by one step.

I also fixed commit() in the same way.

Other problem

The finally of ManagesTransactions::transaction is unnecessary, so it has been removed. Since the transaction level is lowered with handleCommitTransactionException(), using finally will lower the transaction level by two levels.

Removed unnecessary features

I removed the functionality related to callbacksShouldIgnore as it is no longer used anywhere.

How should TransactionsManager behave?

During normal execution, afterCommit is expected to be executed when the transaction no longer exists. That is, when the transaction level is 0.

When testing using RefreshDatabase, the transaction level is increased by +1 first, as shown in the following link.

$connection->beginTransaction();

So in this case, transaction level 1 will be the lowest, and we would expect afterCommit to be called when level drops to 1.

notes

I swapped the order of the OR in afterCommitCallbacksShouldBeExecuted.
This should basically all be handled with $this->transactionsManager?->afterCommitCallbacksShouldBeExecuted($this->transactions), and to make it clear that $this->transactions == 0 is a fallback is.

Best regards.

@SakiTakamachi SakiTakamachi marked this pull request as draft October 7, 2023 04:48
@SakiTakamachi
Copy link
Contributor Author

The test has failed, so I'll draft it for now.

@SakiTakamachi SakiTakamachi changed the title Fix GH-48658: Fixed implementation related to afterCommit wip Fix GH-48658: Fixed implementation related to afterCommit Oct 7, 2023
@KentarouTakeda
Copy link
Contributor

The failing test doesn't seem to be related to this pull request. It's like a test with a probability of failure.

$ echo PING | redis-cli
PONG

$ git branch
* 10.x
  fix/gh-48658

$ git rev-parse HEAD
cddb4f3bb5231f44f18fce304dbf190ad8348ddc

$ i=0; while true; do ((i++)); phpunit tests/Integration/Queue/ThrottlesExceptionsWithRedisTest.php > /dev/null || { echo "Failed on attempt $i"; break; }; done
Failed on attempt 69

$ i=0; while true; do ((i++)); phpunit tests/Integration/Queue/ThrottlesExceptionsWithRedisTest.php > /dev/null || { echo "Failed on attempt $i"; break; }; done
Failed on attempt 83

When executed in an infinite loop at the beginning of the 10.x branch, there is a very low probability of failure.

@SakiTakamachi SakiTakamachi marked this pull request as ready for review October 7, 2023 08:22
@SakiTakamachi SakiTakamachi changed the title wip Fix GH-48658: Fixed implementation related to afterCommit Fix GH-48658: Fixed implementation related to afterCommit Oct 7, 2023
@crynobone
Copy link
Member

We still need regression tests covering the issue posted to confirm that this fix the issue.

@SakiTakamachi SakiTakamachi force-pushed the fix/gh-48658 branch 2 times, most recently from 7565005 to b98cef5 Compare October 7, 2023 17:35
style fix
@SakiTakamachi
Copy link
Contributor Author

@crynobone
@KentarouTakeda added a test.
Thanks!

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone
Copy link
Member

@SakiTakamachi Can you merge this PR: SakiTakamachi#2

@crynobone crynobone marked this pull request as draft October 9, 2023 07:06
@crynobone crynobone changed the title Fix GH-48658: Fixed implementation related to afterCommit [10.x] Fixed implementation related to afterCommit Oct 9, 2023
@SakiTakamachi
Copy link
Contributor Author

@crynobone
Thank you, I merged it.

@crynobone crynobone marked this pull request as ready for review October 9, 2023 09:03
@crynobone crynobone changed the title [10.x] Fixed implementation related to afterCommit [10.x] Fixed implementation related to afterCommit on Postgres and MSSQL database drivers Oct 9, 2023
@taylorotwell taylorotwell merged commit b650a0d into laravel:10.x Oct 9, 2023
20 checks passed
@taylorotwell
Copy link
Member

Thanks!

@azgooon
Copy link

azgooon commented Oct 9, 2023

Thank you all!

@tonysm
Copy link
Contributor

tonysm commented Oct 10, 2023

Nice. Thanks, y'all! 👍🏼

timacdonald pushed a commit to timacdonald/framework that referenced this pull request Oct 24, 2023
…MSSQL database drivers (laravel#48662)

* fix expected level in afterCommitCallbacksShouldBeExecuted

* remove callbacksShouldIgnore

* Fixed transaction level down timing

* Fixed transaction level down timing

* Add test - after commit is executed on final commit

* style fix

style fix

* [10.x] Test Improvements

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
Co-authored-by: 武田 憲太郎 <takeda@youmind.jp>
Co-authored-by: Mior Muhammad Zaki <crynobone@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants