return false;
}
- $found = $this->getSlaveDB()->selectField(
- 'job', '1', array( 'job_cmd' => $this->type ), __METHOD__
+ $found = $this->getSlaveDB()->selectField( // unclaimed job
+ 'job', '1', array( 'job_cmd' => $this->type, 'job_token' => '' ), __METHOD__
);
-
$wgMemc->add( $key, $found ? 'false' : 'true', self::CACHE_TTL );
+
+ return !$found;
}
/**
* @see JobQueue::doBatchPush()
+ * @param array $jobs
+ * @param $flags
+ * @throws DBError|Exception
* @return bool
*/
protected function doBatchPush( array $jobs, $flags ) {
foreach ( array_chunk( $rows, 50 ) as $rowBatch ) {
$dbw->insert( 'job', $rowBatch, __METHOD__ );
}
+ wfIncrStats( 'job-insert', count( $rows ) );
} catch ( DBError $e ) {
if ( $atomic ) {
$dbw->rollback( __METHOD__ );
$wgMemc->set( $this->getEmptinessCacheKey(), 'true', self::CACHE_TTL );
break; // nothing to do
}
+ wfIncrStats( 'job-pop' );
// Get the job object from the row...
$title = Title::makeTitleSafe( $row->job_namespace, $row->job_title );
if ( !$title ) {
$dbw->delete( 'job', array( 'job_id' => $row->job_id ), __METHOD__ );
- wfIncrStats( 'job-pop' );
wfDebugLog( 'JobQueueDB', "Row has invalid title '{$row->job_title}'." );
continue; // try again
}
*/
protected function claimRandom( $uuid, $rand, $gte ) {
$dbw = $this->getMasterDB();
- $dir = $gte ? 'ASC' : 'DESC';
$ineq = $gte ? '>=' : '<=';
$row = false; // the row acquired
'job_cmd' => $this->type,
'job_token' => '',
"job_random {$ineq} {$dbw->addQuotes( $rand )}" ),
- __METHOD__,
- array( 'ORDER BY' => "job_random {$dir}" )
+ __METHOD__
+ // Bug 42614: "ORDER BY job_random" causes slowness on mysql for some reason
);
if ( $row ) { // claim the job
$dbw->update( 'job', // update by PK
/**
* @see JobQueue::doAck()
+ * @param Job $job
+ * @throws MWException
* @return Job|bool
*/
protected function doAck( Job $job ) {
/**
* @see JobQueue::doDeduplicateRootJob()
+ * @param Job $job
+ * @throws MWException
* @return bool
*/
protected function doDeduplicateRootJob( Job $job ) {
$key = $this->getRootJobCacheKey( $params['rootJobSignature'] );
// Callers should call batchInsert() and then this function so that if the insert
// fails, the de-duplication registration will be aborted. Since the insert is
- // deferred till "transaction idle", do that same here, so that the ordering is
+ // deferred till "transaction idle", do the same here, so that the ordering is
// maintained. Having only the de-duplication registration succeed would cause
// jobs to become no-ops without any actual jobs that made them redundant.
$this->getMasterDB()->onTransactionIdle( function() use ( $params, $key ) {