jenkins-bot has submitted this change and it was merged. Change subject: Disallow mismatched beginMasterChanges/commitMasterChanges ......................................................................
Disallow mismatched beginMasterChanges/commitMasterChanges Change-Id: I76a8424e94370dc3776fdac1e974bf61fa69f071 --- M includes/db/loadbalancer/LBFactory.php 1 file changed, 23 insertions(+), 3 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/db/loadbalancer/LBFactory.php b/includes/db/loadbalancer/LBFactory.php index 6b5161b..e40001d 100644 --- a/includes/db/loadbalancer/LBFactory.php +++ b/includes/db/loadbalancer/LBFactory.php @@ -230,6 +230,7 @@ * - commitMasterChanges() * - rollbackMasterChanges() * - commitAll() + * * This allows for custom transaction rounds from any outer transaction scope. * * @param string $fname @@ -240,7 +241,7 @@ if ( $this->trxRoundId !== false ) { throw new DBTransactionError( null, - "Transaction round '{$this->trxRoundId}' already started." + "$fname: transaction round '{$this->trxRoundId}' already started." ); } $this->trxRoundId = $fname; @@ -279,6 +280,12 @@ * @throws Exception */ public function commitMasterChanges( $fname = __METHOD__, array $options = [] ) { + if ( $this->trxRoundId !== false && $this->trxRoundId !== $fname ) { + throw new DBTransactionError( + null, + "$fname: transaction round '{$this->trxRoundId}' still running." + ); + } // Run pre-commit callbacks and suppress post-commit callbacks, aborting on failure $this->forEachLBCallMethod( 'finalizeMasterChanges' ); $this->trxRoundId = false; @@ -509,7 +516,7 @@ * This will commit and wait unless $ticket indicates it is unsafe to do so * * @param string $fname Caller name (e.g. __METHOD__) - * @param mixed $ticket Result of getOuterTransactionScopeTicket() + * @param mixed $ticket Result of getEmptyTransactionTicket() * @param array $opts Options to waitForReplication() * @throws DBReplicationWaitError * @since 1.28 @@ -521,8 +528,21 @@ return; } - $this->commitMasterChanges( $fname ); + $fnameEffective = $fname; + // The transaction owner and any caller with the empty transaction ticket can commit + // so that getEmptyTransactionTicket() callers don't risk seeing DBTransactionError. + if ( $this->trxRoundId !== false && $fname !== $this->trxRoundId ) { + $this->trxLogger->info( "$fname: committing on behalf of {$this->trxRoundId}." ); + $fnameEffective = $this->trxRoundId; + } + + $this->commitMasterChanges( $fnameEffective ); $this->waitForReplication( $opts ); + // If a nested caller committed on behalf of $fname, start another empty $fname + // transaction, leaving the caller with the same empty transaction state as before. + if ( $fnameEffective !== $fname ) { + $this->beginMasterChanges( $fname ); + } } /** -- To view, visit https://gerrit.wikimedia.org/r/307430 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I76a8424e94370dc3776fdac1e974bf61fa69f071 Gerrit-PatchSet: 7 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Aaron Schulz <asch...@wikimedia.org> Gerrit-Reviewer: Chad <ch...@wikimedia.org> Gerrit-Reviewer: Gilles <gdu...@wikimedia.org> Gerrit-Reviewer: Hashar <has...@free.fr> Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com> Gerrit-Reviewer: Parent5446 <tylerro...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits