X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fjobqueue%2FJobQueueDB.php;h=b68fdaefb383e72aecb8796b353913f574faab12;hp=b7cc133a75d13cf6b256fcaef6e5636f5cad93c3;hb=2480aae0c97d822e10b50619e7b48b25c45af073;hpb=4a6d1f142599844b1f34760fe7741eb9605da170 diff --git a/includes/jobqueue/JobQueueDB.php b/includes/jobqueue/JobQueueDB.php index b7cc133a75..b68fdaefb3 100644 --- a/includes/jobqueue/JobQueueDB.php +++ b/includes/jobqueue/JobQueueDB.php @@ -184,15 +184,22 @@ class JobQueueDB extends JobQueue { * @return void */ protected function doBatchPush( array $jobs, $flags ) { - DeferredUpdates::addUpdate( - new AutoCommitUpdate( - $this->getMasterDB(), - __METHOD__, - function ( IDatabase $dbw, $fname ) use ( $jobs, $flags ) { - $this->doBatchPushInternal( $dbw, $jobs, $flags, $fname ); - } - ), - DeferredUpdates::PRESEND + $dbw = $this->getMasterDB(); + // In general, there will be two cases here: + // a) sqlite; DB connection is probably a regular round-aware handle. + // If the connection is busy with a transaction, then defer the job writes + // until right before the main round commit step. Any errors that bubble + // up will rollback the main commit round. + // b) mysql/postgres; DB connection is generally a separate CONN_TRX_AUTO handle. + // No transaction is active nor will be started by writes, so enqueue the jobs + // now so that any errors will show up immediately as the interface expects. Any + // errors that bubble up will rollback the main commit round. + $fname = __METHOD__; + $dbw->onTransactionPreCommitOrIdle( + function () use ( $dbw, $jobs, $flags, $fname ) { + $this->doBatchPushInternal( $dbw, $jobs, $flags, $fname ); + }, + $fname ); } @@ -727,7 +734,6 @@ class JobQueueDB extends JobQueue { 'job_title' => $job->getTitle()->getDBkey(), 'job_params' => self::makeBlob( $job->getParams() ), // Additional job metadata - 'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ), 'job_timestamp' => $dbw->timestamp(), 'job_sha1' => Wikimedia\base_convert( sha1( serialize( $job->getDeduplicationInfo() ) ), @@ -771,7 +777,12 @@ class JobQueueDB extends JobQueue { ? $lbFactory->getExternalLB( $this->cluster ) : $lbFactory->getMainLB( $this->wiki ); - return $lb->getConnectionRef( $index, [], $this->wiki ); + return ( $lb->getServerType( $lb->getWriterIndex() ) !== 'sqlite' ) + // Keep a separate connection to avoid contention and deadlocks; + // However, SQLite has the opposite behavior due to DB-level locking. + ? $lb->getConnectionRef( $index, [], $this->wiki, $lb::CONN_TRX_AUTO ) + // Jobs insertion will be defered until the PRESEND stage to reduce contention. + : $lb->getConnectionRef( $index, [], $this->wiki ); } /**