Merge "Dependency inject TransactionProfiler into DatabaseBase"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Tue, 12 Jan 2016 20:05:36 +0000 (20:05 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 12 Jan 2016 20:05:36 +0000 (20:05 +0000)
includes/db/Database.php
includes/db/loadbalancer/LBFactory.php
includes/db/loadbalancer/LBFactoryMulti.php
includes/db/loadbalancer/LBFactorySimple.php
includes/db/loadbalancer/LBFactorySingle.php
includes/db/loadbalancer/LoadBalancer.php

index 37c9d6f..4684e43 100644 (file)
@@ -282,9 +282,19 @@ abstract class DatabaseBase implements IDatabase {
         * @return TransactionProfiler
         */
        protected function getTransactionProfiler() {
-               return $this->trxProfiler
-                       ? $this->trxProfiler
-                       : Profiler::instance()->getTransactionProfiler();
+               if ( !$this->trxProfiler ) {
+                       $this->trxProfiler = new TransactionProfiler();
+               }
+
+               return $this->trxProfiler;
+       }
+
+       /**
+        * @param TransactionProfiler $profiler
+        * @since 1.27
+        */
+       public function setTransactionProfiler( TransactionProfiler $profiler ) {
+               $this->trxProfiler = $profiler;
        }
 
        /**
index 4aed718..4a13522 100644 (file)
@@ -28,6 +28,8 @@
 abstract class LBFactory {
        /** @var ChronologyProtector */
        protected $chronProt;
+       /** @var TransactionProfiler */
+       protected $trxProfiler;
 
        /** @var LBFactory */
        private static $instance;
@@ -47,6 +49,7 @@ abstract class LBFactory {
                }
 
                $this->chronProt = $this->newChronologyProtector();
+               $this->trxProfiler = Profiler::instance()->getTransactionProfiler();
        }
 
        /**
index e25499c..39be996 100644 (file)
@@ -300,7 +300,8 @@ class LBFactoryMulti extends LBFactory {
                return new LoadBalancer( array(
                        'servers' => $this->makeServerArray( $template, $loads, $groupLoads ),
                        'loadMonitor' => $this->loadMonitorClass,
-                       'readOnlyReason' => $readOnlyReason
+                       'readOnlyReason' => $readOnlyReason,
+                       'trxProfiler' => $this->trxProfiler
                ) );
        }
 
index 3349e1f..53b0310 100644 (file)
@@ -87,7 +87,8 @@ class LBFactorySimple extends LBFactory {
                return new LoadBalancer( array(
                        'servers' => $servers,
                        'loadMonitor' => $this->loadMonitorClass,
-                       'readOnlyReason' => $this->readOnlyReason
+                       'readOnlyReason' => $this->readOnlyReason,
+                       'trxProfiler' => $this->trxProfiler
                ) );
        }
 
@@ -120,7 +121,8 @@ class LBFactorySimple extends LBFactory {
                return new LoadBalancer( array(
                        'servers' => $wgExternalServers[$cluster],
                        'loadMonitor' => $this->loadMonitorClass,
-                       'readOnlyReason' => $this->readOnlyReason
+                       'readOnlyReason' => $this->readOnlyReason,
+                       'trxProfiler' => $this->trxProfiler
                ) );
        }
 
index 5a6cfa7..cbe9517 100644 (file)
@@ -35,8 +35,10 @@ class LBFactorySingle extends LBFactory {
        public function __construct( array $conf ) {
                parent::__construct( $conf );
 
-               $conf['readOnlyReason'] = $this->readOnlyReason;
-               $this->lb = new LoadBalancerSingle( $conf );
+               $this->lb = new LoadBalancerSingle( array(
+                       'readOnlyReason' => $this->readOnlyReason,
+                       'trxProfiler' => $this->trxProfiler
+               ) + $conf );
        }
 
        /**
@@ -103,7 +105,8 @@ class LoadBalancerSingle extends LoadBalancer {
                                        'dbname' => $this->db->getDBname(),
                                        'load' => 1,
                                )
-                       )
+                       ),
+                       'trxProfiler' => $this->trxProfiler
                ) );
 
                if ( isset( $params['readOnlyReason'] ) ) {
index 5d1b745..85a6bf0 100644 (file)
@@ -40,9 +40,9 @@ class LoadBalancer {
        private $mAllowLagged;
        /** @var integer Seconds to spend waiting on slave lag to resolve */
        private $mWaitTimeout;
-
        /** @var array LBFactory information */
        private $mParentInfo;
+
        /** @var string The LoadMonitor subclass name */
        private $mLoadMonitorClass;
        /** @var LoadMonitor */
@@ -67,6 +67,9 @@ class LoadBalancer {
        /** @var integer Total connections opened */
        private $connsOpened = 0;
 
+       /** @var TransactionProfiler */
+       protected $trxProfiler;
+
        /** @var integer Warn when this many connection are held */
        const CONN_HELD_WARN_THRESHOLD = 10;
        /** @var integer Default 'max lag' when unspecified */
@@ -127,6 +130,12 @@ class LoadBalancer {
                }
 
                $this->srvCache = ObjectCache::getLocalServerInstance();
+
+               if ( isset( $params['trxProfiler'] ) ) {
+                       $this->trxProfiler = $params['trxProfiler'];
+               } else {
+                       $this->trxProfiler = new TransactionProfiler();
+               }
        }
 
        /**
@@ -840,6 +849,7 @@ class LoadBalancer {
                $db->setLazyMasterHandle(
                        $this->getLazyConnectionRef( DB_MASTER, array(), $db->getWikiID() )
                );
+               $db->setTransactionProfiler( $this->trxProfiler );
 
                return $db;
        }