Aaron Schulz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/88128
Change subject: Made JobQueueDB use getConnectionRef
......................................................................
Made JobQueueDB use getConnectionRef
* Also moved insertFields() function up a bit about DB connection methods
Change-Id: I7a9d9c9bc71038fe280542b13e0c0e94bfc4de1e
---
M includes/job/JobQueueDB.php
1 file changed, 49 insertions(+), 56 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/28/88128/1
diff --git a/includes/job/JobQueueDB.php b/includes/job/JobQueueDB.php
index af21bc1..379d9d0 100644
--- a/includes/job/JobQueueDB.php
+++ b/includes/job/JobQueueDB.php
@@ -79,7 +79,7 @@
return false;
}
- list( $dbr, $scope ) = $this->getSlaveDB();
+ $dbr = $this->getSlaveDB();
try {
$found = $dbr->selectField( // unclaimed job
'job', '1', array( 'job_cmd' => $this->type,
'job_token' => '' ), __METHOD__
@@ -105,7 +105,7 @@
}
try {
- list( $dbr, $scope ) = $this->getSlaveDB();
+ $dbr = $this->getSlaveDB();
$size = (int)$dbr->selectField( 'job', 'COUNT(*)',
array( 'job_cmd' => $this->type, 'job_token' =>
'' ),
__METHOD__
@@ -134,7 +134,7 @@
return $count;
}
- list( $dbr, $scope ) = $this->getSlaveDB();
+ $dbr = $this->getSlaveDB();
try {
$count = (int)$dbr->selectField( 'job', 'COUNT(*)',
array( 'job_cmd' => $this->type, "job_token !=
{$dbr->addQuotes( '' )}" ),
@@ -167,7 +167,7 @@
return $count;
}
- list( $dbr, $scope ) = $this->getSlaveDB();
+ $dbr = $this->getSlaveDB();
try {
$count = (int)$dbr->selectField( 'job', 'COUNT(*)',
array(
@@ -193,7 +193,7 @@
* @return bool
*/
protected function doBatchPush( array $jobs, $flags ) {
- list( $dbw, $scope ) = $this->getMasterDB();
+ $dbw = $this->getMasterDB();
$that = $this;
$method = __METHOD__;
@@ -284,7 +284,7 @@
return false; // queue is empty
}
- list( $dbw, $scope ) = $this->getMasterDB();
+ $dbw = $this->getMasterDB();
try {
$dbw->commit( __METHOD__, 'flush' ); // flush existing
transaction
$autoTrx = $dbw->getFlag( DBO_TRX ); // get current
setting
@@ -339,7 +339,7 @@
* @return Row|false
*/
protected function claimRandom( $uuid, $rand, $gte ) {
- list( $dbw, $scope ) = $this->getMasterDB();
+ $dbw = $this->getMasterDB();
// Check cache to see if the queue has <= OFFSET items
$tinyQueue = $this->cache->get( $this->getCacheKey( 'small' ) );
@@ -415,7 +415,7 @@
* @return Row|false
*/
protected function claimOldest( $uuid ) {
- list( $dbw, $scope ) = $this->getMasterDB();
+ $dbw = $this->getMasterDB();
$row = false; // the row acquired
do {
@@ -480,7 +480,7 @@
throw new MWException( "Job of type '{$job->getType()}'
has no ID." );
}
- list( $dbw, $scope ) = $this->getMasterDB();
+ $dbw = $this->getMasterDB();
try {
$dbw->commit( __METHOD__, 'flush' ); // flush existing
transaction
$autoTrx = $dbw->getFlag( DBO_TRX ); // get current
setting
@@ -518,7 +518,7 @@
// 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.
- list( $dbw, $scope ) = $this->getMasterDB();
+ $dbw = $this->getMasterDB();
$cache = $this->cache;
$dbw->onTransactionIdle( function() use ( $cache, $params,
$key, $scope ) {
$timestamp = $cache->get( $key ); // current last
timestamp of this job
@@ -538,8 +538,7 @@
* @return bool
*/
protected function doDelete() {
- list( $dbw, $scope ) = $this->getMasterDB();
-
+ $dbw = $this->getMasterDB();
try {
$dbw->delete( 'job', array( 'job_cmd' => $this->type )
);
} catch ( DBError $e ) {
@@ -582,7 +581,7 @@
* @return Iterator
*/
public function getAllQueuedJobs() {
- list( $dbr, $scope ) = $this->getSlaveDB();
+ $dbr = $this->getSlaveDB();
try {
return new MappedIterator(
$dbr->select( 'job', '*',
@@ -611,7 +610,7 @@
}
protected function doGetSiblingQueuesWithJobs( array $types ) {
- list( $dbr, $scope ) = $this->getSlaveDB();
+ $dbr = $this->getSlaveDB();
$res = $dbr->select( 'job', 'DISTINCT job_cmd',
array( 'job_cmd' => $types ), __METHOD__ );
@@ -623,7 +622,7 @@
}
protected function doGetSiblingQueueSizes( array $types ) {
- list( $dbr, $scope ) = $this->getSlaveDB();
+ $dbr = $this->getSlaveDB();
$res = $dbr->select( 'job', array( 'job_cmd', 'COUNT(*) AS
count' ),
array( 'job_cmd' => $types ), __METHOD__, array( 'GROUP
BY' => 'job_cmd' ) );
@@ -642,7 +641,7 @@
public function recycleAndDeleteStaleJobs() {
$now = time();
$count = 0; // affected rows
- list( $dbw, $scope ) = $this->getMasterDB();
+ $dbw = $this->getMasterDB();
try {
if ( !$dbw->lock( "jobqueue-recycle-{$this->type}",
__METHOD__, 1 ) ) {
@@ -719,50 +718,11 @@
}
/**
- * @return Array (DatabaseBase, ScopedCallback)
- */
- protected function getSlaveDB() {
- try {
- return $this->getDB( DB_SLAVE );
- } catch ( DBConnectionError $e ) {
- throw new JobQueueConnectionError( "DBConnectionError:"
. $e->getMessage() );
- }
- }
-
- /**
- * @return Array (DatabaseBase, ScopedCallback)
- */
- protected function getMasterDB() {
- try {
- return $this->getDB( DB_MASTER );
- } catch ( DBConnectionError $e ) {
- throw new JobQueueConnectionError( "DBConnectionError:"
. $e->getMessage() );
- }
- }
-
- /**
- * @param $index integer (DB_SLAVE/DB_MASTER)
- * @return Array (DatabaseBase, ScopedCallback)
- */
- protected function getDB( $index ) {
- $lb = ( $this->cluster !== false )
- ? wfGetLBFactory()->getExternalLB( $this->cluster,
$this->wiki )
- : wfGetLB( $this->wiki );
- $conn = $lb->getConnection( $index, array(), $this->wiki );
- return array(
- $conn,
- new ScopedCallback( function() use ( $lb, $conn ) {
- $lb->reuseConnection( $conn );
- } )
- );
- }
-
- /**
* @param $job Job
* @return array
*/
protected function insertFields( Job $job ) {
- list( $dbw, $scope ) = $this->getMasterDB();
+ $dbw = $this->getMasterDB();
return array(
// Fields that describe the nature of the job
'job_cmd' => $job->getType(),
@@ -781,6 +741,39 @@
}
/**
+ * @return DBConnRef
+ */
+ protected function getSlaveDB() {
+ try {
+ return $this->getDB( DB_SLAVE );
+ } catch ( DBConnectionError $e ) {
+ throw new JobQueueConnectionError( "DBConnectionError:"
. $e->getMessage() );
+ }
+ }
+
+ /**
+ * @return DBConnRef
+ */
+ protected function getMasterDB() {
+ try {
+ return $this->getDB( DB_MASTER );
+ } catch ( DBConnectionError $e ) {
+ throw new JobQueueConnectionError( "DBConnectionError:"
. $e->getMessage() );
+ }
+ }
+
+ /**
+ * @param $index integer (DB_SLAVE/DB_MASTER)
+ * @return DBConnRef
+ */
+ protected function getDB( $index ) {
+ $lb = ( $this->cluster !== false )
+ ? wfGetLBFactory()->getExternalLB( $this->cluster,
$this->wiki )
+ : wfGetLB( $this->wiki );
+ return $lb->getConnectionRef( $index, array(), $this->wiki );
+ }
+
+ /**
* @return string
*/
private function getCacheKey( $property ) {
--
To view, visit https://gerrit.wikimedia.org/r/88128
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7a9d9c9bc71038fe280542b13e0c0e94bfc4de1e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits