Merge "Use late static binding in Article::newFromID()"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 13 Sep 2016 05:02:22 +0000 (05:02 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 13 Sep 2016 05:02:22 +0000 (05:02 +0000)
includes/DefaultSettings.php
includes/db/Database.php
includes/db/loadbalancer/LoadBalancer.php
includes/jobqueue/JobQueueDB.php
includes/jobqueue/jobs/RefreshLinksJob.php
includes/libs/MapCacheLRU.php

index c7fda14..ff7430b 100644 (file)
@@ -5972,7 +5972,7 @@ $wgTrxProfilerLimits = [
        'POST' => [
                'readQueryTime' => 5,
                'writeQueryTime' => 1,
-               'maxAffected' => 500
+               'maxAffected' => 1000
        ],
        'POST-nonwrite' => [
                'masterConns' => 0,
@@ -5983,7 +5983,7 @@ $wgTrxProfilerLimits = [
        'PostSend' => [
                'readQueryTime' => 5,
                'writeQueryTime' => 1,
-               'maxAffected' => 500
+               'maxAffected' => 1000
        ],
        // Background job runner
        'JobRunner' => [
index 0a1774d..c41e7c7 100644 (file)
@@ -331,13 +331,6 @@ abstract class DatabaseBase implements IDatabase {
                return $this->lazyMasterHandle;
        }
 
-       /**
-        * @return TransactionProfiler
-        */
-       protected function getTransactionProfiler() {
-               return $this->trxProfiler;
-       }
-
        /**
         * @param TransactionProfiler $profiler
         * @since 1.27
@@ -914,7 +907,7 @@ abstract class DatabaseBase implements IDatabase {
                # Keep track of whether the transaction has write queries pending
                if ( $this->mTrxLevel && !$this->mTrxDoneWrites && $isWrite ) {
                        $this->mTrxDoneWrites = true;
-                       $this->getTransactionProfiler()->transactionWritingIn(
+                       $this->trxProfiler->transactionWritingIn(
                                $this->mServer, $this->mDBname, $this->mTrxShortId );
                }
 
@@ -1008,7 +1001,7 @@ abstract class DatabaseBase implements IDatabase {
                        $this->mRTTEstimate = $queryRuntime;
                }
 
-               $this->getTransactionProfiler()->recordQueryCompletion(
+               $this->trxProfiler->recordQueryCompletion(
                        $queryProf, $startTime, $isWrite, $this->affectedRows()
                );
                MWDebug::query( $sql, $fname, $isMaster, $queryRuntime );
@@ -3014,7 +3007,7 @@ abstract class DatabaseBase implements IDatabase {
                $this->doCommit( $fname );
                if ( $this->mTrxDoneWrites ) {
                        $this->mDoneWrites = microtime( true );
-                       $this->getTransactionProfiler()->transactionWritingOut(
+                       $this->trxProfiler->transactionWritingOut(
                                $this->mServer, $this->mDBname, $this->mTrxShortId, $writeTime );
                }
 
@@ -3058,7 +3051,7 @@ abstract class DatabaseBase implements IDatabase {
                $this->doRollback( $fname );
                $this->mTrxAtomicLevels = [];
                if ( $this->mTrxDoneWrites ) {
-                       $this->getTransactionProfiler()->transactionWritingOut(
+                       $this->trxProfiler->transactionWritingOut(
                                $this->mServer, $this->mDBname, $this->mTrxShortId );
                }
 
index 42044a7..96ae2e7 100644 (file)
@@ -1662,11 +1662,11 @@ class LoadBalancer {
         *
         * @param IDatabase $conn Replica DB
         * @param DBMasterPos|bool $pos Master position; default: current position
-        * @param integer $timeout Timeout in seconds
+        * @param integer|null $timeout Timeout in seconds [optional]
         * @return bool Success
         * @since 1.27
         */
-       public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = 10 ) {
+       public function safeWaitForMasterPos( IDatabase $conn, $pos = false, $timeout = null ) {
                if ( $this->getServerCount() == 1 || !$conn->getLBInfo( 'replica' ) ) {
                        return true; // server is not a replica DB
                }
@@ -1676,6 +1676,7 @@ class LoadBalancer {
                        return false; // something is misconfigured
                }
 
+               $timeout = $timeout ?: $this->mWaitTimeout;
                $result = $conn->masterPosWait( $pos, $timeout );
                if ( $result == -1 || is_null( $result ) ) {
                        $msg = __METHOD__ . ": Timed out waiting on {$conn->getServer()} pos {$pos}";
index f6b4d53..50727a2 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @author Aaron Schulz
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * Class to handle job queues stored in the DB
@@ -526,7 +527,8 @@ class JobQueueDB extends JobQueue {
         * @return void
         */
        protected function doWaitForBackups() {
-               wfWaitForSlaves( false, $this->wiki, $this->cluster ?: false );
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+               $lbFactory->waitForReplication( [ 'wiki' => $this->wiki, 'cluster' => $this->cluster ] );
        }
 
        /**
@@ -755,9 +757,10 @@ class JobQueueDB extends JobQueue {
         * @return DBConnRef
         */
        protected function getDB( $index ) {
+               $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
                $lb = ( $this->cluster !== false )
-                       ? wfGetLBFactory()->getExternalLB( $this->cluster, $this->wiki )
-                       : wfGetLB( $this->wiki );
+                       ? $lbFactory->getExternalLB( $this->cluster, $this->wiki )
+                       : $lbFactory->getMainLB( $this->wiki );
 
                return $lb->getConnectionRef( $index, [], $this->wiki );
        }
index a337da4..5f33ae0 100644 (file)
@@ -88,7 +88,8 @@ class RefreshLinksJob extends Job {
                        // enqueued will be reflected in backlink page parses when the leaf jobs run.
                        if ( !isset( $params['range'] ) ) {
                                try {
-                                       wfGetLBFactory()->waitForReplication( [
+                                       $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+                                       $lbFactory->waitForReplication( [
                                                'wiki'    => wfWikiID(),
                                                'timeout' => self::LAG_WAIT_TIMEOUT
                                        ] );
@@ -128,13 +129,18 @@ class RefreshLinksJob extends Job {
         * @return bool
         */
        protected function runForTitle( Title $title ) {
-               $stats = MediaWikiServices::getInstance()->getStatsdDataFactory();
+               $services = MediaWikiServices::getInstance();
+               $stats = $services->getStatsdDataFactory();
+               $lbFactory = $services->getDBLoadBalancerFactory();
+               $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
 
                $page = WikiPage::factory( $title );
                $page->loadPageData( WikiPage::READ_LATEST );
 
                // Serialize links updates by page ID so they see each others' changes
-               $scopedLock = LinksUpdate::acquirePageLock( wfGetDB( DB_MASTER ), $page->getId(), 'job' );
+               $dbw = $lbFactory->getMainLB()->getConnection( DB_MASTER );
+               /** @noinspection PhpUnusedLocalVariableInspection */
+               $scopedLock = LinksUpdate::acquirePageLock( $dbw, $page->getId(), 'job' );
                // Get the latest ID *after* acquirePageLock() flushed the transaction.
                // This is used to detect edits/moves after loadPageData() but before the scope lock.
                // The works around the chicken/egg problem of determining the scope lock key.
@@ -241,10 +247,7 @@ class RefreshLinksJob extends Job {
                        $parserOutput
                );
 
-               $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
-               $ticket = $factory->getEmptyTransactionTicket( __METHOD__ );
                foreach ( $updates as $key => $update ) {
-                       $update->setTransactionTicket( $ticket );
                        // FIXME: This code probably shouldn't be here?
                        // Needed by things like Echo notifications which need
                        // to know which user caused the links update
@@ -264,6 +267,7 @@ class RefreshLinksJob extends Job {
                }
 
                foreach ( $updates as $update ) {
+                       $update->setTransactionTicket( $ticket );
                        $update->doUpdate();
                }
 
index 90c9a75..2f5a454 100644 (file)
@@ -115,8 +115,9 @@ class MapCacheLRU {
         * @return mixed The cached value if found or the result of $callback otherwise
         */
        public function getWithSetCallback( $key, callable $callback ) {
-               $value = $this->get( $key );
-               if ( $value === null ) {
+               if ( $this->has( $key ) ) {
+                       $value = $this->get( $key );
+               } else {
                        $value = call_user_func( $callback );
                        if ( $value !== false ) {
                                $this->set( $key, $value );