X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2FJobQueue.php;h=afa757d752ed84f34e1ee6fe777c4edd6dc6059c;hb=b942f819a29dcde2ffaccda31be90cb467d1a3d4;hp=5cec3106dfcdfc01c3c509414c4a40001f8aa02f;hpb=353f203ce222063dbd127b647b9366b5d97b3535;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/JobQueue.php b/includes/JobQueue.php index 5cec3106df..afa757d752 100644 --- a/includes/JobQueue.php +++ b/includes/JobQueue.php @@ -1,4 +1,7 @@ selectRow( 'job', '*', "job_id >= ${offset}", __METHOD__, @@ -122,7 +127,7 @@ abstract class Job { // Failed, someone else beat us to it // Try getting a random row $row = $dbw->selectRow( 'job', array( 'MIN(job_id) as minjob', - 'MAX(job_id) as maxjob' ), "job_id >= $offset", __METHOD__ ); + 'MAX(job_id) as maxjob' ), '1=1', __METHOD__ ); if ( $row === false || is_null( $row->minjob ) || is_null( $row->maxjob ) ) { // No jobs to get wfProfileOut( __METHOD__ ); @@ -158,7 +163,10 @@ abstract class Job { $job = Job::factory( $row->job_cmd, $title, Job::extractBlob( $row->job_params ), $row->job_id ); // Remove any duplicates it may have later in the queue + // Deadlock prone section + $dbw->begin(); $dbw->delete( 'job', $job->insertFields(), __METHOD__ ); + $dbw->commit(); wfProfileOut( __METHOD__ ); return $job; @@ -167,10 +175,10 @@ abstract class Job { /** * Create the appropriate object to handle a specific job * - * @param string $command Job command - * @param Title $title Associated title - * @param array $params Job parameters - * @param int $id Job identifier + * @param $command String: Job command + * @param $title Title: Associated title + * @param $params Array: Job parameters + * @param $id Int: Job identifier * @return Job */ static function factory( $command, $title, $params = false, $id = 0 ) { @@ -181,7 +189,7 @@ abstract class Job { } throw new MWException( "Invalid job command `{$command}`" ); } - + static function makeBlob( $params ) { if ( $params !== false ) { return serialize( $params ); @@ -208,12 +216,23 @@ abstract class Job { * @param $jobs array of Job objects */ static function batchInsert( $jobs ) { - if( count( $jobs ) ) { - $dbw = wfGetDB( DB_MASTER ); - $dbw->begin(); - foreach( $jobs as $job ) { - $rows[] = $job->insertFields(); + if( !count( $jobs ) ) { + return; + } + $dbw = wfGetDB( DB_MASTER ); + $rows = array(); + foreach( $jobs as $job ) { + $rows[] = $job->insertFields(); + if ( count( $rows ) >= 50 ) { + # Do a small transaction to avoid slave lag + $dbw->begin(); + $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); + $dbw->commit(); + $rows = array(); } + } + if ( $rows ) { + $dbw->begin(); $dbw->insert( 'job', $rows, __METHOD__, 'IGNORE' ); $dbw->commit(); } @@ -283,9 +302,11 @@ abstract class Job { } } + protected function setLastError( $error ) { + $this->error = $error; + } + function getLastError() { return $this->error; } } - -