Merge "Do not auto-reconnect to DBs if named locks where lost"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 30 Jan 2016 18:07:35 +0000 (18:07 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 30 Jan 2016 18:07:35 +0000 (18:07 +0000)
includes/db/Database.php
includes/db/IDatabase.php
includes/jobqueue/jobs/CategoryMembershipChangeJob.php

index 9315daf..a4d0ad0 100644 (file)
@@ -3181,6 +3181,7 @@ abstract class DatabaseBase implements IDatabase {
 
                $that = $this;
                $unlocker = new ScopedCallback( function () use ( $that, $lockKey, $fname ) {
+                       $that->commit( __METHOD__, 'flush' );
                        $that->unlock( $lockKey, $fname );
                } );
 
index 1a6e779..1e728d8 100644 (file)
@@ -1519,7 +1519,7 @@ interface IDatabase {
         * This is suitiable for transactions that need to be serialized using cooperative locks,
         * where each transaction can see each others' changes. Any transaction is flushed to clear
         * out stale REPEATABLE-READ snapshot data. Once the returned object falls out of PHP scope,
-        * the lock will be released.
+        * any transaction will be committed and the lock will be released.
         *
         * If the lock acquisition failed, then no transaction flush happens, and null is returned.
         *
index a6869c1..d34ea41 100644 (file)
@@ -63,13 +63,21 @@ class CategoryMembershipChangeJob extends Job {
                // between COMMIT and actual enqueueing of the CategoryMembershipChangeJob job.
                $cutoffUnix -= self::ENQUEUE_FUDGE_SEC;
 
+               $dbr = wfGetDB( DB_SLAVE, array( 'recentchanges' ) );
+               if ( !wfGetLB()->safeWaitForPos( $dbr ) ) {
+                       $this->setLastError( "Timed out while waiting for slave to catch up" );
+                       return false;
+               }
+
+               $dbr->commit( __METHOD__, 'flush' );
+
                // Get the newest revision that has a SRC_CATEGORIZE row...
-               $row = $dbw->selectRow(
+               $row = $dbr->selectRow(
                        array( 'revision', 'recentchanges' ),
                        array( 'rev_timestamp', 'rev_id' ),
                        array(
                                'rev_page' => $page->getId(),
-                               'rev_timestamp >= ' . $dbw->addQuotes( $dbw->timestamp( $cutoffUnix ) )
+                               'rev_timestamp >= ' . $dbr->addQuotes( $dbr->timestamp( $cutoffUnix ) )
                        ),
                        __METHOD__,
                        array( 'ORDER BY' => 'rev_timestamp DESC, rev_id DESC' ),
@@ -96,8 +104,8 @@ class CategoryMembershipChangeJob extends Job {
 
                // Find revisions to this page made around and after this revision which lack category
                // notifications in recent changes. This lets jobs pick up were the last one left off.
-               $encCutoff = $dbw->addQuotes( $dbw->timestamp( $cutoffUnix ) );
-               $res = $dbw->select(
+               $encCutoff = $dbr->addQuotes( $dbr->timestamp( $cutoffUnix ) );
+               $res = $dbr->select(
                        'revision',
                        Revision::selectFields(),
                        array(