From 4c0871fa0ef99d0d38bcba8e09fce8ef55f791d9 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 15 Jul 2014 19:19:54 -0700 Subject: [PATCH] Made LCStoreDB try to use a separate DB connection * This avoids breaking the main transaction in finishWrite(). * Also removed an unused variable in SqlBagOStuff. Change-Id: Ia330ac362b080c1338616d95b793032c4752dc23 --- includes/cache/LocalisationCache.php | 15 ++++++++++++--- includes/objectcache/SqlBagOStuff.php | 15 +++++---------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/includes/cache/LocalisationCache.php b/includes/cache/LocalisationCache.php index ec36cfb5ab..9dc3dc3a8e 100644 --- a/includes/cache/LocalisationCache.php +++ b/includes/cache/LocalisationCache.php @@ -1163,8 +1163,8 @@ class LCStoreDB implements LCStore { private $readOnly = false; public function get( $code, $key ) { - if ( $this->writesDone ) { - $db = wfGetDB( DB_MASTER ); + if ( $this->writesDone && $this->dbw ) { + $db = $this->dbw; } else { $db = wfGetDB( DB_SLAVE ); } @@ -1184,7 +1184,16 @@ class LCStoreDB implements LCStore { throw new MWException( __METHOD__ . ": Invalid language \"$code\"" ); } - $this->dbw = wfGetDB( DB_MASTER ); + // We must keep a separate connection to MySQL in order to avoid breaking + // main transactions. However, SQLite deadlocks when using two connections. + // @TODO: get this trick to work on PostgreSQL too + if ( wfGetDB( DB_MASTER )->getType() == 'mysql' ) { + $lb = wfGetLBFactory()->newMainLB(); + $this->dbw = $lb->getConnection( DB_MASTER ); + $this->dbw->clearFlag( DBO_TRX ); // auto-commit mode + } else { + $this->dbw = wfGetDB( DB_MASTER ); + } $this->currentLang = $code; $this->batch = array(); diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 483f8b9ac5..8b0b738cd7 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -27,9 +27,6 @@ * @ingroup Cache */ class SqlBagOStuff extends BagOStuff { - /** @var LoadBalancer */ - protected $lb; - protected $serverInfos; /** @var array */ @@ -146,14 +143,12 @@ class SqlBagOStuff extends BagOStuff { $db = DatabaseBase::factory( $type, $info ); $db->clearFlag( DBO_TRX ); } else { - /* - * We must keep a separate connection to MySQL in order to avoid deadlocks - * However, SQLite has an opposite behavior. And PostgreSQL needs to know - * if we are in transaction or no - */ + // We must keep a separate connection to MySQL in order to avoid deadlocks + // However, SQLite has an opposite behavior. + // @TODO: get this trick to work on PostgreSQL too if ( wfGetDB( DB_MASTER )->getType() == 'mysql' ) { - $this->lb = wfGetLBFactory()->newMainLB(); - $db = $this->lb->getConnection( DB_MASTER ); + $lb = wfGetLBFactory()->newMainLB(); + $db = $lb->getConnection( DB_MASTER ); $db->clearFlag( DBO_TRX ); // auto-commit mode } else { $db = wfGetDB( DB_MASTER ); -- 2.20.1