__METHOD__
);
- // Push lazilly-pushed jobs
// Important: this must be the last deferred update added (T100085, T154425)
- DeferredUpdates::addCallableUpdate( [ 'JobQueueGroup', 'pushLazyJobs' ] );
+ DeferredUpdates::addCallableUpdate( [ JobQueueGroup::class, 'pushLazyJobs' ] );
// Do any deferred jobs
DeferredUpdates::doUpdates( 'enqueue' );
}
// Avoiding running updates without them having outer scope
- if ( !self::getBusyDbConnections() ) {
+ if ( !self::areDatabaseTransactionsActive() ) {
self::doUpdates( $mode );
return true;
}
}
/**
- * @return IDatabase[] Connection where commit() cannot be called yet
+ * @return bool If a transaction round is active or connection is not ready for commit()
*/
- private static function getBusyDbConnections() {
- $connsBusy = [];
-
+ private static function areDatabaseTransactionsActive() {
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ if ( $lbFactory->hasTransactionRound() ) {
+ return true;
+ }
+
+ $connsBusy = false;
$lbFactory->forEachLB( function ( LoadBalancer $lb ) use ( &$connsBusy ) {
$lb->forEachOpenMasterConnection( function ( IDatabase $conn ) use ( &$connsBusy ) {
if ( $conn->writesOrCallbacksPending() || $conn->explicitTrxActive() ) {
- $connsBusy[] = $conn;
+ $connsBusy = true;
}
} );
} );
* @return void
*/
protected function doBatchPush( array $jobs, $flags ) {
- DeferredUpdates::addUpdate( new AutoCommitUpdate(
- wfGetDB( DB_MASTER ),
- __METHOD__,
- function ( IDatabase $dbw, $fname ) use ( $jobs, $flags ) {
- $this->doBatchPushInternal( $dbw, $jobs, $flags, $fname );
- }
- ) );
+ DeferredUpdates::addUpdate(
+ new AutoCommitUpdate(
+ $this->getMasterDB(),
+ __METHOD__,
+ function ( IDatabase $dbw, $fname ) use ( $jobs, $flags ) {
+ $this->doBatchPushInternal( $dbw, $jobs, $flags, $fname );
+ }
+ ),
+ DeferredUpdates::PRESEND
+ );
}
/**
$status = $job->run();
$error = $job->getLastError();
$this->commitMasterChanges( $lbFactory, $job, $fnameTrxOwner );
- // Push lazilly-pushed jobs
// Important: this must be the last deferred update added (T100085, T154425)
- DeferredUpdates::addCallableUpdate( [ 'JobQueueGroup', 'pushLazyJobs' ] );
+ DeferredUpdates::addCallableUpdate( [ JobQueueGroup::class, 'pushLazyJobs' ] );
// Run any deferred update tasks; doUpdates() manages transactions itself
DeferredUpdates::doUpdates();
} catch ( Exception $e ) {
*/
public function rollbackMasterChanges( $fname = __METHOD__ );
+ /**
+ * Check if a transaction round is active
+ * @return bool
+ * @since 1.29
+ */
+ public function hasTransactionRound();
+
/**
* Determine if any master connection has pending changes
* @return bool
} );
}
+ public function hasTransactionRound() {
+ return ( $this->trxRoundId !== false );
+ }
+
/**
* Log query info if multi DB transactions are going to be committed now
*/