X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fobjectcache%2FSqlBagOStuff.php;h=2cfd2a1d7625c11b007d764c4304e808cde2dc04;hp=3cce530c3c0ddd7dc29af4b618000a912909c34c;hb=802c199d0bd80ff0f4d730c61fd58cbf08a52d8d;hpb=89539f2aa1b158fdcc703ad053e2580cb97a6385 diff --git a/includes/objectcache/SqlBagOStuff.php b/includes/objectcache/SqlBagOStuff.php index 3cce530c3c..2cfd2a1d76 100644 --- a/includes/objectcache/SqlBagOStuff.php +++ b/includes/objectcache/SqlBagOStuff.php @@ -145,27 +145,11 @@ class SqlBagOStuff extends BagOStuff { $this->replicaOnly = !empty( $params['slaveOnly'] ); } - protected function getSeparateMainLB() { - global $wgDBtype; - - if ( $this->usesMainDB() && $wgDBtype !== 'sqlite' ) { - if ( !$this->separateMainLB ) { - // We must keep a separate connection to MySQL in order to avoid deadlocks - $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); - $this->separateMainLB = $lbFactory->newMainLB(); - } - return $this->separateMainLB; - } else { - // However, SQLite has an opposite behavior due to DB-level locking - return null; - } - } - /** * Get a connection to the specified database * * @param int $serverIndex - * @return IDatabase + * @return Database * @throws MWException */ protected function getDB( $serverIndex ) { @@ -181,8 +165,8 @@ class SqlBagOStuff extends BagOStuff { throw $this->connFailureErrors[$serverIndex]; } - # If server connection info was given, use that if ( $this->serverInfos ) { + // Use custom database defined by server connection info $info = $this->serverInfos[$serverIndex]; $type = isset( $info['type'] ) ? $info['type'] : 'mysql'; $host = isset( $info['host'] ) ? $info['host'] : '[unknown]'; @@ -190,17 +174,22 @@ class SqlBagOStuff extends BagOStuff { // Use a blank trx profiler to ignore expections as this is a cache $info['trxProfiler'] = new TransactionProfiler(); $db = Database::factory( $type, $info ); - $db->clearFlag( DBO_TRX ); + $db->clearFlag( DBO_TRX ); // auto-commit mode } else { + // Use the main LB database + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); $index = $this->replicaOnly ? DB_REPLICA : DB_MASTER; - if ( $this->getSeparateMainLB() ) { - $db = $this->getSeparateMainLB()->getConnection( $index ); - $db->clearFlag( DBO_TRX ); // auto-commit mode + if ( $lb->getServerType( $lb->getWriterIndex() ) !== 'sqlite' ) { + // Keep a separate connection to avoid contention and deadlocks + $db = $lb->getConnection( $index, [], false, $lb::CONN_TRX_AUTO ); + // @TODO: Use a blank trx profiler to ignore expections as this is a cache } else { - $db = wfGetDB( $index ); - // Can't mess with transaction rounds (DBO_TRX) :( + // However, SQLite has the opposite behavior due to DB-level locking. + // Stock sqlite MediaWiki installs use a separate sqlite cache DB instead. + $db = $lb->getConnection( $index ); } } + $this->logger->debug( sprintf( "Connection %s will be used for SqlBagOStuff", $db ) ); $this->conns[$serverIndex] = $db; } @@ -812,9 +801,7 @@ class SqlBagOStuff extends BagOStuff { return true; } - $lb = $this->getSeparateMainLB() - ?: MediaWikiServices::getInstance()->getDBLoadBalancer(); - + $lb = MediaWikiServices::getInstance()->getDBLoadBalancer(); if ( $lb->getServerCount() <= 1 ) { return true; // no replica DBs }