Remove "@author Aaron Schulz" annotations
[lhc/web/wiklou.git] / includes / jobqueue / JobQueueDB.php
index 5ec1127..cefe74d 100644 (file)
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
- * @author Aaron Schulz
  */
+use Wikimedia\Rdbms\IDatabase;
+use Wikimedia\Rdbms\DBConnRef;
+use Wikimedia\Rdbms\DBConnectionError;
+use Wikimedia\Rdbms\DBError;
 use MediaWiki\MediaWikiServices;
+use Wikimedia\ScopedCallback;
 
 /**
  * Class to handle job queues stored in the DB
@@ -68,7 +72,7 @@ class JobQueueDB extends JobQueue {
         * @return bool
         */
        protected function doIsEmpty() {
-               $dbr = $this->getSlaveDB();
+               $dbr = $this->getReplicaDB();
                try {
                        $found = $dbr->selectField( // unclaimed job
                                'job', '1', [ 'job_cmd' => $this->type, 'job_token' => '' ], __METHOD__
@@ -93,7 +97,7 @@ class JobQueueDB extends JobQueue {
                }
 
                try {
-                       $dbr = $this->getSlaveDB();
+                       $dbr = $this->getReplicaDB();
                        $size = (int)$dbr->selectField( 'job', 'COUNT(*)',
                                [ 'job_cmd' => $this->type, 'job_token' => '' ],
                                __METHOD__
@@ -122,7 +126,7 @@ class JobQueueDB extends JobQueue {
                        return $count;
                }
 
-               $dbr = $this->getSlaveDB();
+               $dbr = $this->getReplicaDB();
                try {
                        $count = (int)$dbr->selectField( 'job', 'COUNT(*)',
                                [ 'job_cmd' => $this->type, "job_token != {$dbr->addQuotes( '' )}" ],
@@ -153,7 +157,7 @@ class JobQueueDB extends JobQueue {
                        return $count;
                }
 
-               $dbr = $this->getSlaveDB();
+               $dbr = $this->getReplicaDB();
                try {
                        $count = (int)$dbr->selectField( 'job', 'COUNT(*)',
                                [
@@ -180,14 +184,15 @@ class JobQueueDB extends JobQueue {
         * @return void
         */
        protected function doBatchPush( array $jobs, $flags ) {
-               $dbw = $this->getMasterDB();
-
-               $method = __METHOD__;
-               $dbw->onTransactionIdle(
-                       function () use ( $dbw, $jobs, $flags, $method ) {
-                               $this->doBatchPushInternal( $dbw, $jobs, $flags, $method );
-                       },
-                       __METHOD__
+               DeferredUpdates::addUpdate(
+                       new AutoCommitUpdate(
+                               $this->getMasterDB(),
+                               __METHOD__,
+                               function ( IDatabase $dbw, $fname ) use ( $jobs, $flags ) {
+                                       $this->doBatchPushInternal( $dbw, $jobs, $flags, $fname );
+                               }
+                       ),
+                       DeferredUpdates::PRESEND
                );
        }
 
@@ -345,7 +350,7 @@ class JobQueueDB extends JobQueue {
                                        continue; // try the other direction
                                }
                        } else { // table *may* have >= MAX_OFFSET rows
-                               // Bug 42614: "ORDER BY job_random" with a job_random inequality causes high CPU
+                               // T44614: "ORDER BY job_random" with a job_random inequality causes high CPU
                                // 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
@@ -565,7 +570,7 @@ class JobQueueDB extends JobQueue {
         * @return Iterator
         */
        protected function getJobIterator( array $conds ) {
-               $dbr = $this->getSlaveDB();
+               $dbr = $this->getReplicaDB();
                try {
                        return new MappedIterator(
                                $dbr->select( 'job', self::selectFields(), $conds ),
@@ -593,7 +598,7 @@ class JobQueueDB extends JobQueue {
        }
 
        protected function doGetSiblingQueuesWithJobs( array $types ) {
-               $dbr = $this->getSlaveDB();
+               $dbr = $this->getReplicaDB();
                // @note: this does not check whether the jobs are claimed or not.
                // This is useful so JobQueueGroup::pop() also sees queues that only
                // have stale jobs. This lets recycleAndDeleteStaleJobs() re-enqueue
@@ -610,7 +615,7 @@ class JobQueueDB extends JobQueue {
        }
 
        protected function doGetSiblingQueueSizes( array $types ) {
-               $dbr = $this->getSlaveDB();
+               $dbr = $this->getReplicaDB();
                $res = $dbr->select( 'job', [ 'job_cmd', 'COUNT(*) AS count' ],
                        [ 'job_cmd' => $types ], __METHOD__, [ 'GROUP BY' => 'job_cmd' ] );
 
@@ -736,7 +741,7 @@ class JobQueueDB extends JobQueue {
         * @throws JobQueueConnectionError
         * @return DBConnRef
         */
-       protected function getSlaveDB() {
+       protected function getReplicaDB() {
                try {
                        return $this->getDB( DB_REPLICA );
                } catch ( DBConnectionError $e ) {