Merge "Change multiple documentations in DairkiDiff"
[lhc/web/wiklou.git] / includes / jobqueue / JobRunner.php
index 7ce731d..6d2ce0e 100644 (file)
@@ -126,7 +126,7 @@ class JobRunner implements LoggerAwareInterface {
                $group = JobQueueGroup::singleton();
 
                // Flush any pending DB writes for sanity
-               wfGetLBFactory()->commitAll();
+               wfGetLBFactory()->commitAll( __METHOD__ );
 
                // Some jobs types should not run until a certain timestamp
                $backoffs = array(); // map of (type => UNIX expiry)
@@ -191,21 +191,24 @@ class JobRunner implements LoggerAwareInterface {
                                }
                                // Commit all outstanding connections that are in a transaction
                                // to get a fresh repeatable read snapshot on every connection.
-                               wfGetLBFactory()->commitAll();
+                               // Note that jobs are still responsible for handling slave lag.
+                               wfGetLBFactory()->commitAll( __METHOD__ );
+                               // Clear out title cache data from prior snapshots
+                               LinkCache::singleton()->clear();
                                $timeMs = intval( ( microtime( true ) - $jobStartTime ) * 1000 );
                                $timeMsTotal += $timeMs;
 
                                // Record how long jobs wait before getting popped
                                $readyTs = $job->getReadyTimestamp();
                                if ( $readyTs ) {
-                                       $pickupDelay = $popTime - $readyTs;
+                                       $pickupDelay = max( 0, $popTime - $readyTs );
                                        $stats->timing( 'jobqueue.pickup_delay.all', 1000 * $pickupDelay );
                                        $stats->timing( "jobqueue.pickup_delay.$jType", 1000 * $pickupDelay );
                                }
                                // Record root job age for jobs being run
                                $root = $job->getRootJobParams();
                                if ( $root['rootJobTimestamp'] ) {
-                                       $age = $popTime - wfTimestamp( TS_UNIX, $root['rootJobTimestamp'] );
+                                       $age = max( 0, $popTime - wfTimestamp( TS_UNIX, $root['rootJobTimestamp'] ) );
                                        $stats->timing( "jobqueue.pickup_root_age.$jType", 1000 * $age );
                                }
                                // Track the execution time for jobs
@@ -448,7 +451,7 @@ class JobRunner implements LoggerAwareInterface {
                global $wgJobSerialCommitThreshold;
 
                $lb = wfGetLB( wfWikiID() );
-               if ( $wgJobSerialCommitThreshold !== false ) {
+               if ( $wgJobSerialCommitThreshold !== false && $lb->getServerCount() > 1 ) {
                        // Generally, there is one master connection to the local DB
                        $dbwSerial = $lb->getAnyOpenConnection( $lb->getWriterIndex() );
                } else {
@@ -461,13 +464,13 @@ class JobRunner implements LoggerAwareInterface {
                ) {
                        // Writes are all to foreign DBs, named locks don't form queues,
                        // or $wgJobSerialCommitThreshold is not reached; commit changes now
-                       wfGetLBFactory()->commitMasterChanges();
+                       wfGetLBFactory()->commitMasterChanges( __METHOD__ );
                        return;
                }
 
                $ms = intval( 1000 * $dbwSerial->pendingWriteQueryDuration() );
                $msg = $job->toString() . " COMMIT ENQUEUED [{$ms}ms of writes]";
-               $this->logger->info( $msg );
+               $this->logger->warning( $msg );
                $this->debugCallback( $msg );
 
                // Wait for an exclusive lock to commit
@@ -493,7 +496,7 @@ class JobRunner implements LoggerAwareInterface {
                } );
 
                // Actually commit the DB master changes
-               wfGetLBFactory()->commitMasterChanges();
+               wfGetLBFactory()->commitMasterChanges( __METHOD__ );
 
                // Release the lock
                $dbwSerial->unlock( 'jobrunner-serial-commit', __METHOD__ );