From edadb880205231ee1274906bf18271c0b96e812a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sat, 26 Jan 2013 16:57:55 -0800 Subject: [PATCH] Improved handling of pending queue delisting. * Also removed outdated comment. Change-Id: I5b9a4bf4ed854d58af09e377378997b23549c230 --- maintenance/nextJobDB.php | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/maintenance/nextJobDB.php b/maintenance/nextJobDB.php index 17a3f2e078..7e6fd966db 100644 --- a/maintenance/nextJobDB.php +++ b/maintenance/nextJobDB.php @@ -18,7 +18,6 @@ * http://www.gnu.org/copyleft/gpl.html * * @file - * @todo Make this work on PostgreSQL and maybe other database servers * @ingroup Maintenance */ @@ -89,22 +88,17 @@ class nextJobDB extends Maintenance { $candidates = array_values( $candidates ); $db = $candidates[ mt_rand( 0, count( $candidates ) - 1 ) ]; if ( !$this->checkJob( $type, $db ) ) { - if ( $type === false ) { - // There are no jobs available in the current database - foreach ( $pendingDBs as $type2 => $dbs ) { - $pendingDBs[$type2] = array_diff( $pendingDBs[$type2], array( $db ) ); - } - } else { - // There are no jobs of this type available in the current database - $pendingDBs[$type] = array_diff( $pendingDBs[$type], array( $db ) ); - } + $pendingDBs = $this->delistDB( $pendingDBs, $db, $type ); // Update the cache to remove the outdated information. // Make sure that this does not race (especially with full rebuilds). - $pendingDbInfo['pendingDBs'] = $pendingDBs; if ( $wgMemc->add( "$memcKey:lock", 1, 60 ) ) { // lock $curInfo = $wgMemc->get( $memcKey ); - if ( $curInfo && $curInfo['timestamp'] === $pendingDbInfo['timestamp'] ) { - $wgMemc->set( $memcKey, $pendingDbInfo ); + if ( is_array( $curInfo ) ) { + $curInfo['pendingDBs'] = + $this->delistDB( $curInfo['pendingDBs'], $db, $type ); + $wgMemc->set( $memcKey, $curInfo ); + // May as well make use of this newer information + $pendingDBs = $curInfo['pendingDBs']; } $wgMemc->delete( "$memcKey:lock" ); // unlock } @@ -115,6 +109,19 @@ class nextJobDB extends Maintenance { $this->output( $db . "\n" ); } + private function delistDB( array $pendingDBs, $db, $type ) { + if ( $type === false ) { + // There are no jobs available in the current database + foreach ( $pendingDBs as $type2 => $dbs ) { + $pendingDBs[$type2] = array_diff( $pendingDBs[$type2], array( $db ) ); + } + } else { + // There are no jobs of this type available in the current database + $pendingDBs[$type] = array_diff( $pendingDBs[$type], array( $db ) ); + } + return $pendingDBs; + } + /** * Check if the specified database has a job of the specified type in it. * The type may be false to indicate "all". @@ -122,7 +129,7 @@ class nextJobDB extends Maintenance { * @param $dbName string * @return bool */ - function checkJob( $type, $dbName ) { + private function checkJob( $type, $dbName ) { $group = JobQueueGroup::singleton( $dbName ); if ( $type === false ) { foreach ( $group->getDefaultQueueTypes() as $type ) { -- 2.20.1