From 61df5e785f22748b259c9e71c277e815a0f66e4f Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 26 Feb 2015 15:41:50 -0800 Subject: [PATCH] Made SqlBagOStuff avoid tripping TransactionProfiler * Set a custom profiler with no expectations to avoid tripping the "0 write" expection. This avoids useless log entries. Change-Id: Iac849a729eb36b1a8affb0dbc8b8c195fab4b03a --- includes/db/Database.php | 30 ++++++++++++++++++++------- includes/objectcache/SqlBagOStuff.php | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/includes/db/Database.php b/includes/db/Database.php index ee1722e606..1a7a97d3ed 100644 --- a/includes/db/Database.php +++ b/includes/db/Database.php @@ -153,6 +153,9 @@ abstract class DatabaseBase implements IDatabase { */ protected $allViews = null; + /** @var TransactionProfiler */ + protected $trxProfiler; + /** * A string describing the current software version, and possibly * other details in a user-friendly way. Will be listed on Special:Version, etc. @@ -345,6 +348,15 @@ abstract class DatabaseBase implements IDatabase { public function setFakeMaster( $enabled = true ) { } + /** + * @return TransactionProfiler + */ + protected function getTransactionProfiler() { + return $this->trxProfiler + ? $this->trxProfiler + : Profiler::instance()->getTransactionProfiler(); + } + /** * Returns true if this database supports (and uses) cascading deletes * @@ -798,12 +810,16 @@ abstract class DatabaseBase implements IDatabase { $this->mForeign = $foreign; + if ( isset( $params['trxProfiler'] ) ) { + $this->trxProfiler = $params['trxProfiler']; // override + } + if ( $user ) { $this->open( $server, $user, $password, $dbName ); } $isMaster = !is_null( $this->getLBInfo( 'master' ) ); - $trxProf = Profiler::instance()->getTransactionProfiler(); + $trxProf = $this->getTransactionProfiler(); $trxProf->recordConnection( $this->mServer, $this->mDBname, $isMaster ); } @@ -1103,7 +1119,7 @@ abstract class DatabaseBase implements IDatabase { # Keep track of whether the transaction has write queries pending if ( $this->mTrxLevel && !$this->mTrxDoneWrites && $isWriteQuery ) { $this->mTrxDoneWrites = true; - Profiler::instance()->getTransactionProfiler()->transactionWritingIn( + $this->getTransactionProfiler()->transactionWritingIn( $this->mServer, $this->mDBname, $this->mTrxShortId ); } @@ -1149,7 +1165,7 @@ abstract class DatabaseBase implements IDatabase { $startTime = microtime( true ); $ret = $this->doQuery( $commentedSql ); # Log the query time and feed it into the DB trx profiler - $profiler->getTransactionProfiler()->recordQueryCompletion( + $this->getTransactionProfiler()->recordQueryCompletion( $queryProf, $startTime, $isWriteQuery, $this->affectedRows() ); MWDebug::queryTime( $queryId ); @@ -1180,7 +1196,7 @@ abstract class DatabaseBase implements IDatabase { $startTime = microtime( true ); $ret = $this->doQuery( $commentedSql ); # Log the query time and feed it into the DB trx profiler - $profiler->getTransactionProfiler()->recordQueryCompletion( + $this->getTransactionProfiler()->recordQueryCompletion( $queryProf, $startTime, $isWriteQuery, $this->affectedRows() ); } } else { @@ -3599,7 +3615,7 @@ abstract class DatabaseBase implements IDatabase { $this->runOnTransactionPreCommitCallbacks(); $this->doCommit( $fname ); if ( $this->mTrxDoneWrites ) { - Profiler::instance()->getTransactionProfiler()->transactionWritingOut( + $this->getTransactionProfiler()->transactionWritingOut( $this->mServer, $this->mDBname, $this->mTrxShortId ); } $this->runOnTransactionIdleCallbacks(); @@ -3679,7 +3695,7 @@ abstract class DatabaseBase implements IDatabase { $this->runOnTransactionPreCommitCallbacks(); $this->doCommit( $fname ); if ( $this->mTrxDoneWrites ) { - Profiler::instance()->getTransactionProfiler()->transactionWritingOut( + $this->getTransactionProfiler()->transactionWritingOut( $this->mServer, $this->mDBname, $this->mTrxShortId ); } $this->runOnTransactionIdleCallbacks(); @@ -3738,7 +3754,7 @@ abstract class DatabaseBase implements IDatabase { $this->mTrxPreCommitCallbacks = array(); // cancel $this->mTrxAtomicLevels = new SplStack; if ( $this->mTrxDoneWrites ) { - Profiler::instance()->getTransactionProfiler()->transactionWritingOut( + $this->getTransactionProfiler()->transactionWritingOut( $this->mServer, $this->mDBname, $this->mTrxShortId ); } } diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 2fb9ff992d..82eeb842e8 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -145,6 +145,8 @@ class SqlBagOStuff extends BagOStuff { $type = isset( $info['type'] ) ? $info['type'] : 'mysql'; $host = isset( $info['host'] ) ? $info['host'] : '[unknown]'; $this->logger->debug( __CLASS__ . ": connecting to $host" ); + // Use a blank trx profiler to ignore expections as this is a cache + $info['trxProfiler'] = new TransactionProfiler(); $db = DatabaseBase::factory( $type, $info ); $db->clearFlag( DBO_TRX ); } else { -- 2.20.1