dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Prevent "Failed to create..." warnings when session loading fails"
[lhc/web/wiklou.git]
/
includes
/
jobqueue
/
JobQueueDB.php
diff --git
a/includes/jobqueue/JobQueueDB.php
b/includes/jobqueue/JobQueueDB.php
index
ed2d0fa
..
aaf9fb0
100644
(file)
--- a/
includes/jobqueue/JobQueueDB.php
+++ b/
includes/jobqueue/JobQueueDB.php
@@
-55,7
+55,7
@@
class JobQueueDB extends JobQueue {
}
protected function supportedOrders() {
}
protected function supportedOrders() {
- return
array( 'random', 'timestamp', 'fifo' )
;
+ return
[ 'random', 'timestamp', 'fifo' ]
;
}
protected function optimalOrder() {
}
protected function optimalOrder() {
@@
-70,7
+70,7
@@
class JobQueueDB extends JobQueue {
$dbr = $this->getSlaveDB();
try {
$found = $dbr->selectField( // unclaimed job
$dbr = $this->getSlaveDB();
try {
$found = $dbr->selectField( // unclaimed job
- 'job', '1',
array( 'job_cmd' => $this->type, 'job_token' => '' )
, __METHOD__
+ 'job', '1',
[ 'job_cmd' => $this->type, 'job_token' => '' ]
, __METHOD__
);
} catch ( DBError $e ) {
$this->throwDBException( $e );
);
} catch ( DBError $e ) {
$this->throwDBException( $e );
@@
-94,7
+94,7
@@
class JobQueueDB extends JobQueue {
try {
$dbr = $this->getSlaveDB();
$size = (int)$dbr->selectField( 'job', 'COUNT(*)',
try {
$dbr = $this->getSlaveDB();
$size = (int)$dbr->selectField( 'job', 'COUNT(*)',
-
array( 'job_cmd' => $this->type, 'job_token' => '' )
,
+
[ 'job_cmd' => $this->type, 'job_token' => '' ]
,
__METHOD__
);
} catch ( DBError $e ) {
__METHOD__
);
} catch ( DBError $e ) {
@@
-124,7
+124,7
@@
class JobQueueDB extends JobQueue {
$dbr = $this->getSlaveDB();
try {
$count = (int)$dbr->selectField( 'job', 'COUNT(*)',
$dbr = $this->getSlaveDB();
try {
$count = (int)$dbr->selectField( 'job', 'COUNT(*)',
-
array( 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" )
,
+
[ 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ]
,
__METHOD__
);
} catch ( DBError $e ) {
__METHOD__
);
} catch ( DBError $e ) {
@@
-155,11
+155,11
@@
class JobQueueDB extends JobQueue {
$dbr = $this->getSlaveDB();
try {
$count = (int)$dbr->selectField( 'job', 'COUNT(*)',
$dbr = $this->getSlaveDB();
try {
$count = (int)$dbr->selectField( 'job', 'COUNT(*)',
- array(
+ [
'job_cmd' => $this->type,
"job_token != {$dbr->addQuotes( '' )}",
"job_attempts >= " . $dbr->addQuotes( $this->maxTries )
'job_cmd' => $this->type,
"job_token != {$dbr->addQuotes( '' )}",
"job_attempts >= " . $dbr->addQuotes( $this->maxTries )
-
)
,
+
]
,
__METHOD__
);
} catch ( DBError $e ) {
__METHOD__
);
} catch ( DBError $e ) {
@@
-181,11
+181,10
@@
class JobQueueDB extends JobQueue {
protected function doBatchPush( array $jobs, $flags ) {
$dbw = $this->getMasterDB();
protected function doBatchPush( array $jobs, $flags ) {
$dbw = $this->getMasterDB();
- $that = $this;
$method = __METHOD__;
$dbw->onTransactionIdle(
$method = __METHOD__;
$dbw->onTransactionIdle(
- function () use ( $dbw, $
that, $
jobs, $flags, $method ) {
- $th
at
->doBatchPushInternal( $dbw, $jobs, $flags, $method );
+ function () use ( $dbw, $jobs, $flags, $method ) {
+ $th
is
->doBatchPushInternal( $dbw, $jobs, $flags, $method );
}
);
}
}
);
}
@@
-205,8
+204,8
@@
class JobQueueDB extends JobQueue {
return;
}
return;
}
- $rowSet =
array()
; // (sha1 => job) map for jobs that are de-duplicated
- $rowList =
array()
; // list of jobs for jobs that are not de-duplicated
+ $rowSet =
[]
; // (sha1 => job) map for jobs that are de-duplicated
+ $rowList =
[]
; // list of jobs for jobs that are not de-duplicated
foreach ( $jobs as $job ) {
$row = $this->insertFields( $job );
if ( $job->ignoreDuplicates() ) {
foreach ( $jobs as $job ) {
$row = $this->insertFields( $job );
if ( $job->ignoreDuplicates() ) {
@@
-223,11
+222,11
@@
class JobQueueDB extends JobQueue {
// Strip out any duplicate jobs that are already in the queue...
if ( count( $rowSet ) ) {
$res = $dbw->select( 'job', 'job_sha1',
// Strip out any duplicate jobs that are already in the queue...
if ( count( $rowSet ) ) {
$res = $dbw->select( 'job', 'job_sha1',
- array(
+ [
// No job_type condition since it's part of the job_sha1 hash
'job_sha1' => array_keys( $rowSet ),
'job_token' => '' // unclaimed
// No job_type condition since it's part of the job_sha1 hash
'job_sha1' => array_keys( $rowSet ),
'job_token' => '' // unclaimed
-
)
,
+
]
,
$method
);
foreach ( $res as $row ) {
$method
);
foreach ( $res as $row ) {
@@
-276,7
+275,7
@@
class JobQueueDB extends JobQueue {
$job = false; // job popped off
do { // retry when our row is invalid or deleted as a duplicate
// Try to reserve a row in the DB...
$job = false; // job popped off
do { // retry when our row is invalid or deleted as a duplicate
// Try to reserve a row in the DB...
- if ( in_array( $this->order,
array( 'fifo', 'timestamp' )
) ) {
+ if ( in_array( $this->order,
[ 'fifo', 'timestamp' ]
) ) {
$row = $this->claimOldest( $uuid );
} else { // random first
$rand = mt_rand( 0, self::MAX_JOB_RANDOM ); // encourage concurrent UPDATEs
$row = $this->claimOldest( $uuid );
} else { // random first
$rand = mt_rand( 0, self::MAX_JOB_RANDOM ); // encourage concurrent UPDATEs
@@
-335,12
+334,12
@@
class JobQueueDB extends JobQueue {
$ineq = $gte ? '>=' : '<=';
$dir = $gte ? 'ASC' : 'DESC';
$row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
$ineq = $gte ? '>=' : '<=';
$dir = $gte ? 'ASC' : 'DESC';
$row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
- array(
+ [
'job_cmd' => $this->type,
'job_token' => '', // unclaimed
'job_cmd' => $this->type,
'job_token' => '', // unclaimed
- "job_random {$ineq} {$dbw->addQuotes( $rand )}"
)
,
+ "job_random {$ineq} {$dbw->addQuotes( $rand )}"
]
,
__METHOD__,
__METHOD__,
- array( 'ORDER BY' => "job_random {$dir}" )
+ [ 'ORDER BY' => "job_random {$dir}" ]
);
if ( !$row && !$invertedDirection ) {
$gte = !$gte;
);
if ( !$row && !$invertedDirection ) {
$gte = !$gte;
@@
-352,12
+351,12
@@
class JobQueueDB extends JobQueue {
// in MySQL if there are many rows for some reason. This uses a small OFFSET
// instead of job_random for reducing excess claim retries.
$row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
// in MySQL if there are many rows for some reason. This uses a small OFFSET
// instead of job_random for reducing excess claim retries.
$row = $dbw->selectRow( 'job', self::selectFields(), // find a random job
- array(
+ [
'job_cmd' => $this->type,
'job_token' => '', // unclaimed
'job_cmd' => $this->type,
'job_token' => '', // unclaimed
-
)
,
+
]
,
__METHOD__,
__METHOD__,
- array( 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) )
+ [ 'OFFSET' => mt_rand( 0, self::MAX_OFFSET ) ]
);
if ( !$row ) {
$tinyQueue = true; // we know the queue must have <= MAX_OFFSET rows
);
if ( !$row ) {
$tinyQueue = true; // we know the queue must have <= MAX_OFFSET rows
@@
-368,11
+367,11
@@
class JobQueueDB extends JobQueue {
if ( $row ) { // claim the job
$dbw->update( 'job', // update by PK
if ( $row ) { // claim the job
$dbw->update( 'job', // update by PK
- array(
+ [
'job_token' => $uuid,
'job_token_timestamp' => $dbw->timestamp(),
'job_token' => $uuid,
'job_token_timestamp' => $dbw->timestamp(),
- 'job_attempts = job_attempts+1'
)
,
-
array( 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' )
,
+ 'job_attempts = job_attempts+1'
]
,
+
[ 'job_cmd' => $this->type, 'job_id' => $row->job_id, 'job_token' => '' ]
,
__METHOD__
);
// This might get raced out by another runner when claiming the previously
__METHOD__
);
// This might get raced out by another runner when claiming the previously
@@
-419,24
+418,24
@@
class JobQueueDB extends JobQueue {
// Use a subquery to find the job, within an UPDATE to claim it.
// This uses as much of the DB wrapper functions as possible.
$dbw->update( 'job',
// Use a subquery to find the job, within an UPDATE to claim it.
// This uses as much of the DB wrapper functions as possible.
$dbw->update( 'job',
- array(
+ [
'job_token' => $uuid,
'job_token_timestamp' => $dbw->timestamp(),
'job_token' => $uuid,
'job_token_timestamp' => $dbw->timestamp(),
- 'job_attempts = job_attempts+1'
)
,
-
array(
'job_id = (' .
+ 'job_attempts = job_attempts+1'
]
,
+
[
'job_id = (' .
$dbw->selectSQLText( 'job', 'job_id',
$dbw->selectSQLText( 'job', 'job_id',
-
array( 'job_cmd' => $this->type, 'job_token' => '' )
,
+
[ 'job_cmd' => $this->type, 'job_token' => '' ]
,
__METHOD__,
__METHOD__,
-
array( 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 )
) .
+
[ 'ORDER BY' => 'job_id ASC', 'LIMIT' => 1 ]
) .
')'
')'
-
)
,
+
]
,
__METHOD__
);
}
// Fetch any row that we just reserved...
if ( $dbw->affectedRows() ) {
$row = $dbw->selectRow( 'job', self::selectFields(),
__METHOD__
);
}
// Fetch any row that we just reserved...
if ( $dbw->affectedRows() ) {
$row = $dbw->selectRow( 'job', self::selectFields(),
-
array( 'job_cmd' => $this->type, 'job_token' => $uuid )
, __METHOD__
+
[ 'job_cmd' => $this->type, 'job_token' => $uuid ]
, __METHOD__
);
if ( !$row ) { // raced out by duplicate job removal
wfDebug( "Row deleted as duplicate by another process.\n" );
);
if ( !$row ) { // raced out by duplicate job removal
wfDebug( "Row deleted as duplicate by another process.\n" );
@@
-471,7
+470,7
@@
class JobQueueDB extends JobQueue {
// Delete a row with a single DELETE without holding row locks over RTTs...
$dbw->delete( 'job',
// Delete a row with a single DELETE without holding row locks over RTTs...
$dbw->delete( 'job',
-
array( 'job_cmd' => $this->type, 'job_id' => $job->metadata['id'] )
, __METHOD__ );
+
[ 'job_cmd' => $this->type, 'job_id' => $job->metadata['id'] ]
, __METHOD__ );
JobQueue::incrStats( 'acks', $this->type );
} catch ( DBError $e ) {
JobQueue::incrStats( 'acks', $this->type );
} catch ( DBError $e ) {
@@
-522,7
+521,7
@@
class JobQueueDB extends JobQueue {
protected function doDelete() {
$dbw = $this->getMasterDB();
try {
protected function doDelete() {
$dbw = $this->getMasterDB();
try {
- $dbw->delete( 'job',
array( 'job_cmd' => $this->type )
);
+ $dbw->delete( 'job',
[ 'job_cmd' => $this->type ]
);
} catch ( DBError $e ) {
$this->throwDBException( $e );
}
} catch ( DBError $e ) {
$this->throwDBException( $e );
}
@@
-542,7
+541,7
@@
class JobQueueDB extends JobQueue {
* @return void
*/
protected function doFlushCaches() {
* @return void
*/
protected function doFlushCaches() {
- foreach (
array( 'size', 'acquiredcount' )
as $type ) {
+ foreach (
[ 'size', 'acquiredcount' ]
as $type ) {
$this->cache->delete( $this->getCacheKey( $type ) );
}
}
$this->cache->delete( $this->getCacheKey( $type ) );
}
}
@@
-552,7
+551,7
@@
class JobQueueDB extends JobQueue {
* @return Iterator
*/
public function getAllQueuedJobs() {
* @return Iterator
*/
public function getAllQueuedJobs() {
- return $this->getJobIterator(
array( 'job_cmd' => $this->getType(), 'job_token' => '' )
);
+ return $this->getJobIterator(
[ 'job_cmd' => $this->getType(), 'job_token' => '' ]
);
}
/**
}
/**
@@
-560,7
+559,7
@@
class JobQueueDB extends JobQueue {
* @return Iterator
*/
public function getAllAcquiredJobs() {
* @return Iterator
*/
public function getAllAcquiredJobs() {
- return $this->getJobIterator(
array( 'job_cmd' => $this->getType(), "job_token > ''" )
);
+ return $this->getJobIterator(
[ 'job_cmd' => $this->getType(), "job_token > ''" ]
);
}
/**
}
/**
@@
-576,7
+575,7
@@
class JobQueueDB extends JobQueue {
$job = Job::factory(
$row->job_cmd,
Title::makeTitle( $row->job_namespace, $row->job_title ),
$job = Job::factory(
$row->job_cmd,
Title::makeTitle( $row->job_namespace, $row->job_title ),
- strlen( $row->job_params ) ? unserialize( $row->job_params ) :
array()
+ strlen( $row->job_params ) ? unserialize( $row->job_params ) :
[]
);
$job->metadata['id'] = $row->job_id;
$job->metadata['timestamp'] = $row->job_timestamp;
);
$job->metadata['id'] = $row->job_id;
$job->metadata['timestamp'] = $row->job_timestamp;
@@
-602,9
+601,9
@@
class JobQueueDB extends JobQueue {
// have stale jobs. This lets recycleAndDeleteStaleJobs() re-enqueue
// failed jobs so that they can be popped again for that edge case.
$res = $dbr->select( 'job', 'DISTINCT job_cmd',
// have stale jobs. This lets recycleAndDeleteStaleJobs() re-enqueue
// failed jobs so that they can be popped again for that edge case.
$res = $dbr->select( 'job', 'DISTINCT job_cmd',
-
array( 'job_cmd' => $types )
, __METHOD__ );
+
[ 'job_cmd' => $types ]
, __METHOD__ );
- $types =
array()
;
+ $types =
[]
;
foreach ( $res as $row ) {
$types[] = $row->job_cmd;
}
foreach ( $res as $row ) {
$types[] = $row->job_cmd;
}
@@
-614,10
+613,10
@@
class JobQueueDB extends JobQueue {
protected function doGetSiblingQueueSizes( array $types ) {
$dbr = $this->getSlaveDB();
protected function doGetSiblingQueueSizes( array $types ) {
$dbr = $this->getSlaveDB();
- $res = $dbr->select( 'job',
array( 'job_cmd', 'COUNT(*) AS count' )
,
-
array( 'job_cmd' => $types ), __METHOD__, array( 'GROUP BY' => 'job_cmd' )
);
+ $res = $dbr->select( 'job',
[ 'job_cmd', 'COUNT(*) AS count' ]
,
+
[ 'job_cmd' => $types ], __METHOD__, [ 'GROUP BY' => 'job_cmd' ]
);
- $sizes =
array()
;
+ $sizes =
[]
;
foreach ( $res as $row ) {
$sizes[$row->job_cmd] = (int)$row->count;
}
foreach ( $res as $row ) {
$sizes[$row->job_cmd] = (int)$row->count;
}
@@
-647,11
+646,11
@@
class JobQueueDB extends JobQueue {
// These jobs can be recycled into the queue by expiring the claim. Selecting
// the IDs first means that the UPDATE can be done by primary key (less deadlocks).
$res = $dbw->select( 'job', 'job_id',
// These jobs can be recycled into the queue by expiring the claim. Selecting
// the IDs first means that the UPDATE can be done by primary key (less deadlocks).
$res = $dbw->select( 'job', 'job_id',
- array(
+ [
'job_cmd' => $this->type,
"job_token != {$dbw->addQuotes( '' )}", // was acquired
"job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}", // stale
'job_cmd' => $this->type,
"job_token != {$dbw->addQuotes( '' )}", // was acquired
"job_token_timestamp < {$dbw->addQuotes( $claimCutoff )}", // stale
- "job_attempts < {$dbw->addQuotes( $this->maxTries )}"
)
, // retries left
+ "job_attempts < {$dbw->addQuotes( $this->maxTries )}"
]
, // retries left
__METHOD__
);
$ids = array_map(
__METHOD__
);
$ids = array_map(
@@
-664,11
+663,11
@@
class JobQueueDB extends JobQueue {
// Set the timestamp to the current time, as it is useful to now that the job
// was already tried before (the timestamp becomes the "released" time).
$dbw->update( 'job',
// Set the timestamp to the current time, as it is useful to now that the job
// was already tried before (the timestamp becomes the "released" time).
$dbw->update( 'job',
- array(
+ [
'job_token' => '',
'job_token' => '',
- 'job_token_timestamp' => $dbw->timestamp( $now )
)
, // time of release
- array(
- 'job_id' => $ids
)
,
+ 'job_token_timestamp' => $dbw->timestamp( $now )
]
, // time of release
+ [
+ 'job_id' => $ids
]
,
__METHOD__
);
$affected = $dbw->affectedRows();
__METHOD__
);
$affected = $dbw->affectedRows();
@@
-680,11
+679,11
@@
class JobQueueDB extends JobQueue {
// Just destroy any stale jobs...
$pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
// Just destroy any stale jobs...
$pruneCutoff = $dbw->timestamp( $now - self::MAX_AGE_PRUNE );
- $conds =
array(
+ $conds =
[
'job_cmd' => $this->type,
"job_token != {$dbw->addQuotes( '' )}", // was acquired
"job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}" // stale
'job_cmd' => $this->type,
"job_token != {$dbw->addQuotes( '' )}", // was acquired
"job_token_timestamp < {$dbw->addQuotes( $pruneCutoff )}" // stale
-
)
;
+
]
;
if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times...
$conds[] = "job_attempts >= {$dbw->addQuotes( $this->maxTries )}";
}
if ( $this->claimTTL > 0 ) { // only prune jobs attempted too many times...
$conds[] = "job_attempts >= {$dbw->addQuotes( $this->maxTries )}";
}
@@
-697,7
+696,7
@@
class JobQueueDB extends JobQueue {
}, iterator_to_array( $res )
);
if ( count( $ids ) ) {
}, iterator_to_array( $res )
);
if ( count( $ids ) ) {
- $dbw->delete( 'job',
array( 'job_id' => $ids )
, __METHOD__ );
+ $dbw->delete( 'job',
[ 'job_id' => $ids ]
, __METHOD__ );
$affected = $dbw->affectedRows();
$count += $affected;
JobQueue::incrStats( 'abandons', $this->type, $affected );
$affected = $dbw->affectedRows();
$count += $affected;
JobQueue::incrStats( 'abandons', $this->type, $affected );
@@
-718,7
+717,7
@@
class JobQueueDB extends JobQueue {
protected function insertFields( IJobSpecification $job ) {
$dbw = $this->getMasterDB();
protected function insertFields( IJobSpecification $job ) {
$dbw = $this->getMasterDB();
- return
array(
+ return
[
// Fields that describe the nature of the job
'job_cmd' => $job->getType(),
'job_namespace' => $job->getTitle()->getNamespace(),
// Fields that describe the nature of the job
'job_cmd' => $job->getType(),
'job_namespace' => $job->getTitle()->getNamespace(),
@@
-727,12
+726,12
@@
class JobQueueDB extends JobQueue {
// Additional job metadata
'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ),
'job_timestamp' => $dbw->timestamp(),
// Additional job metadata
'job_id' => $dbw->nextSequenceValue( 'job_job_id_seq' ),
'job_timestamp' => $dbw->timestamp(),
- 'job_sha1' =>
wfBaseC
onvert(
+ 'job_sha1' =>
Wikimedia\base_c
onvert(
sha1( serialize( $job->getDeduplicationInfo() ) ),
16, 36, 31
),
'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
sha1( serialize( $job->getDeduplicationInfo() ) ),
16, 36, 31
),
'job_random' => mt_rand( 0, self::MAX_JOB_RANDOM )
-
)
;
+
]
;
}
/**
}
/**
@@
-768,7
+767,7
@@
class JobQueueDB extends JobQueue {
? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki )
: wfGetLB( $this->wiki );
? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki )
: wfGetLB( $this->wiki );
- return $lb->getConnectionRef( $index,
array()
, $this->wiki );
+ return $lb->getConnectionRef( $index,
[]
, $this->wiki );
}
/**
}
/**
@@
-820,7
+819,7
@@
class JobQueueDB extends JobQueue {
* @return array
*/
public static function selectFields() {
* @return array
*/
public static function selectFields() {
- return
array(
+ return
[
'job_id',
'job_cmd',
'job_namespace',
'job_id',
'job_cmd',
'job_namespace',
@@
-832,6
+831,6
@@
class JobQueueDB extends JobQueue {
'job_token',
'job_token_timestamp',
'job_sha1',
'job_token',
'job_token_timestamp',
'job_sha1',
-
)
;
+
]
;
}
}
}
}