Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/300759
Change subject: Make onTransactionPreCommitOrIdle() atomic when immediate ...................................................................... Make onTransactionPreCommitOrIdle() atomic when immediate One of the main uses of this method is to tack on some DB updates to the end of atomic transactions to reduce lock contention problems. In this case, multiple updates in the callback are atomic. However, if no transaction is active, then such updates were previously not atomic. Wrap them in transactions now. Change-Id: I18c56e65063a61000c4dfd1979bf972800b173ac --- M includes/db/Database.php M includes/db/IDatabase.php 2 files changed, 9 insertions(+), 5 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/59/300759/1 diff --git a/includes/db/Database.php b/includes/db/Database.php index 9b73584..91517b5 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -2468,7 +2468,10 @@ if ( $this->mTrxLevel ) { $this->mTrxPreCommitCallbacks[] = [ $callback, wfGetCaller() ]; } else { - $this->onTransactionIdle( $callback ); // this will trigger immediately + // If no transaction is active, then make one for this callback + $this->begin( __METHOD__ ); + call_user_func( $callback ); + $this->commit( __METHOD__ ); } } diff --git a/includes/db/IDatabase.php b/includes/db/IDatabase.php index c024632..aa2a980 100644 --- a/includes/db/IDatabase.php +++ b/includes/db/IDatabase.php @@ -1221,7 +1221,7 @@ public function getMasterPos(); /** - * Run an anonymous function as soon as the current transaction commits or rolls back. + * Run a callback as soon as the current transaction commits or rolls back. * An error is thrown if no transaction is pending. Queries in the function will run in * AUTO-COMMIT mode unless there are begin() calls. Callbacks must commit any transactions * that they begin. @@ -1238,7 +1238,7 @@ public function onTransactionResolution( callable $callback ); /** - * Run an anonymous function as soon as there is no transaction pending. + * Run a callback as soon as there is no transaction pending. * If there is a transaction and it is rolled back, then the callback is cancelled. * Queries in the function will run in AUTO-COMMIT mode unless there are begin() calls. * Callbacks must commit any transactions that they begin. @@ -1259,9 +1259,10 @@ public function onTransactionIdle( callable $callback ); /** - * Run an anonymous function before the current transaction commits or now if there is none. + * Run a callback before the current transaction commits or now if there is none. * If there is a transaction and it is rolled back, then the callback is cancelled. - * Callbacks must not start nor commit any transactions. + * Callbacks must not start nor commit any transactions. If no transaction is active, + * then a transaction will wrap the callback. * * This is useful for updates that easily cause deadlocks if locks are held too long * but where atomicity is strongly desired for these updates and some related updates. -- To view, visit https://gerrit.wikimedia.org/r/300759 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I18c56e65063a61000c4dfd1979bf972800b173ac Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits