From 3c98f2c0ee3244cbe606348a56b9312a1968bc77 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 31 Oct 2012 20:49:58 -0700 Subject: [PATCH] [JobQueue] Fixed while loop in claimOldest() function. Change-Id: I326b767c08944bcfde83c5e7f4a8339cecbab6d4 --- includes/job/JobQueueDB.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/job/JobQueueDB.php b/includes/job/JobQueueDB.php index 4a9c47a3e2..d7d2b1974d 100644 --- a/includes/job/JobQueueDB.php +++ b/includes/job/JobQueueDB.php @@ -186,7 +186,7 @@ class JobQueueDB extends JobQueue { // instead, but that either uses ORDER BY (in which case it deadlocks in MySQL) or is // not replication safe. Due to http://bugs.mysql.com/bug.php?id=6980, subqueries cannot // be used here with MySQL. - while ( true ) { + do { $row = $dbw->selectRow( 'job', '*', // find a random job array( 'job_cmd' => $this->type, @@ -203,15 +203,13 @@ class JobQueueDB extends JobQueue { ); // This might get raced out by another runner when claiming the previously // selected row. The use of job_random should minimize this problem, however. - if ( $dbw->affectedRows() ) { - break; // acquired - } else { + if ( !$dbw->affectedRows() ) { $row = false; // raced out } } else { break; // nothing to do } - } + } while ( !$row ); return $row; } @@ -226,7 +224,7 @@ class JobQueueDB extends JobQueue { $dbw = $this->getMasterDB(); $row = false; // the row acquired - while ( true ) { + do { if ( $dbw->getType() === 'mysql' ) { // Per http://bugs.mysql.com/bug.php?id=6980, we can't use subqueries on the // same table being changed in an UPDATE query in MySQL (gives Error: 1093). @@ -268,7 +266,7 @@ class JobQueueDB extends JobQueue { } else { break; // nothing to do } - } + } while ( !$row ); return $row; } -- 2.20.1