From: Aaron Schulz Date: Wed, 6 Jan 2016 01:09:06 +0000 (-0800) Subject: Dependency inject TransactionProfiler into DatabaseBase X-Git-Tag: 1.31.0-rc.0~8367^2 X-Git-Url: http://git.cyclocoop.org/data/Luca_Pacioli_%28Gemaelde%29.jpeg?a=commitdiff_plain;h=7c8edbec735062755bf71ed419a25f388b960205;p=lhc%2Fweb%2Fwiklou.git Dependency inject TransactionProfiler into DatabaseBase Change-Id: Ie5fc8120c3a3a5afe17897084d345f5fdb06843c --- diff --git a/includes/db/Database.php b/includes/db/Database.php index 3fec522d66..7ababe102a 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -354,9 +354,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; } /** diff --git a/includes/db/loadbalancer/LBFactory.php b/includes/db/loadbalancer/LBFactory.php index 4aed7180ee..4a135222bf 100644 --- a/includes/db/loadbalancer/LBFactory.php +++ b/includes/db/loadbalancer/LBFactory.php @@ -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(); } /** diff --git a/includes/db/loadbalancer/LBFactoryMulti.php b/includes/db/loadbalancer/LBFactoryMulti.php index e25499c2b7..39be9965ec 100644 --- a/includes/db/loadbalancer/LBFactoryMulti.php +++ b/includes/db/loadbalancer/LBFactoryMulti.php @@ -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 ) ); } diff --git a/includes/db/loadbalancer/LBFactorySimple.php b/includes/db/loadbalancer/LBFactorySimple.php index 3349e1f737..53b0310842 100644 --- a/includes/db/loadbalancer/LBFactorySimple.php +++ b/includes/db/loadbalancer/LBFactorySimple.php @@ -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 ) ); } diff --git a/includes/db/loadbalancer/LBFactorySingle.php b/includes/db/loadbalancer/LBFactorySingle.php index 5a6cfa753d..cbe9517323 100644 --- a/includes/db/loadbalancer/LBFactorySingle.php +++ b/includes/db/loadbalancer/LBFactorySingle.php @@ -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'] ) ) { diff --git a/includes/db/loadbalancer/LoadBalancer.php b/includes/db/loadbalancer/LoadBalancer.php index 5d1b7459d6..85a6bf08e8 100644 --- a/includes/db/loadbalancer/LoadBalancer.php +++ b/includes/db/loadbalancer/LoadBalancer.php @@ -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; }