X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdeferred%2FDeferredUpdates.php;h=d43ffbc97553a94576c176eb39f551caff9603e8;hb=fab912b65c5363466beac64669573c366d74027c;hp=c754cff685b30b89f90e23d9e974210e8280384f;hpb=8699880aab6f666f902b8d8927325760adfe7c20;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/deferred/DeferredUpdates.php b/includes/deferred/DeferredUpdates.php index c754cff685..d43ffbc975 100644 --- a/includes/deferred/DeferredUpdates.php +++ b/includes/deferred/DeferredUpdates.php @@ -28,6 +28,7 @@ use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\LBFactory; use Wikimedia\Rdbms\ILBFactory; use Wikimedia\Rdbms\LoadBalancer; +use Wikimedia\Rdbms\DBTransactionError; /** * Class for managing the deferred updates @@ -352,28 +353,30 @@ class DeferredUpdates { * @since 1.34 */ public static function attemptUpdate( DeferrableUpdate $update, ILBFactory $lbFactory ) { + $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ ); + if ( !$ticket || $lbFactory->hasTransactionRound() ) { + throw new DBTransactionError( null, "A database transaction round is pending." ); + } + if ( $update instanceof DataUpdate ) { - $update->setTransactionTicket( $lbFactory->getEmptyTransactionTicket( __METHOD__ ) ); + $update->setTransactionTicket( $ticket ); } - if ( + $fnameTrxOwner = get_class( $update ) . '::doUpdate'; + $useExplicitTrxRound = !( $update instanceof TransactionRoundAwareUpdate && $update->getTransactionRoundRequirement() == $update::TRX_ROUND_ABSENT - ) { - $fnameTrxOwner = null; + ); + // Flush any pending changes left over from an implicit transaction round + if ( $useExplicitTrxRound ) { + $lbFactory->beginMasterChanges( $fnameTrxOwner ); // new explicit round } else { - $fnameTrxOwner = get_class( $update ) . '::doUpdate'; + $lbFactory->commitMasterChanges( $fnameTrxOwner ); // new implicit round } - - if ( $fnameTrxOwner !== null ) { - $lbFactory->beginMasterChanges( $fnameTrxOwner ); - } - + // Run the update after any stale master view snapshots have been flushed $update->doUpdate(); - - if ( $fnameTrxOwner !== null ) { - $lbFactory->commitMasterChanges( $fnameTrxOwner ); - } + // Commit any pending changes from the explicit or implicit transaction round + $lbFactory->commitMasterChanges( $fnameTrxOwner ); } /**