Replace wfGetLB
@deprecated since 1.27 Change-Id: Ibdd49fdfc0d1511503e1ed2173a592c612996c53
This commit is contained in:
parent
b48a74ef5f
commit
e1a203603c
16 changed files with 65 additions and 29 deletions
|
|
@ -71,7 +71,7 @@ want to write code destined for Wikipedia.
|
|||
It's often the case that the best algorithm to use for a given task
|
||||
depends on whether or not replication is in use. Due to our unabashed
|
||||
Wikipedia-centrism, we often just use the replication-friendly version,
|
||||
but if you like, you can use wfGetLB()->getServerCount() > 1 to
|
||||
but if you like, you can use LoadBalancer::getServerCount() > 1 to
|
||||
check to see if replication is in use.
|
||||
|
||||
=== Lag ===
|
||||
|
|
@ -107,7 +107,7 @@ in the session, and then at the start of each request, waiting for the
|
|||
slave to catch up to that position before doing any reads from it. If
|
||||
this wait times out, reads are allowed anyway, but the request is
|
||||
considered to be in "lagged slave mode". Lagged slave mode can be
|
||||
checked by calling wfGetLB()->getLaggedReplicaMode(). The only
|
||||
checked by calling LoadBalancer::getLaggedReplicaMode(). The only
|
||||
practical consequence at present is a warning displayed in the page
|
||||
footer.
|
||||
|
||||
|
|
|
|||
|
|
@ -1919,8 +1919,8 @@ $wgSQLiteDataDir = '';
|
|||
* $wgSharedSchema is the table schema for the shared database. It defaults to
|
||||
* $wgDBmwschema.
|
||||
*
|
||||
* @deprecated since 1.21 In new code, use the $wiki parameter to wfGetLB() to
|
||||
* access remote databases. Using wfGetLB() allows the shared database to
|
||||
* @deprecated since 1.21 In new code, use the $wiki parameter to LBFactory::getMainLB() to
|
||||
* access remote databases. Using LBFactory::getMainLB() allows the shared database to
|
||||
* reside on separate servers to the wiki's own database, with suitable
|
||||
* configuration of $wgLBFactoryConf.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\Rdbms\LoadBalancer;
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ abstract class DBAccessBase implements IDBAccessObject {
|
|||
* @return IDatabase
|
||||
*/
|
||||
protected function getConnection( $id, $groups = [] ) {
|
||||
$loadBalancer = wfGetLB( $this->wiki );
|
||||
$loadBalancer = $this->getLoadBalancer();
|
||||
|
||||
return $loadBalancer->getConnection( $id, $groups, $this->wiki );
|
||||
}
|
||||
|
|
@ -83,13 +84,14 @@ abstract class DBAccessBase implements IDBAccessObject {
|
|||
/**
|
||||
* Get the database type used for read operations.
|
||||
*
|
||||
* @see wfGetLB
|
||||
* @see MediaWikiServices::getDBLoadBalancer
|
||||
*
|
||||
* @since 1.21
|
||||
*
|
||||
* @return LoadBalancer The database load balancer object
|
||||
*/
|
||||
public function getLoadBalancer() {
|
||||
return wfGetLB( $this->wiki );
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
return $lbFactory->getMainLB( $this->wiki );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@
|
|||
* @ingroup FileRepo
|
||||
*/
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\IDatabase;
|
||||
use Wikimedia\Rdbms\LoadBalancer;
|
||||
|
||||
/**
|
||||
* A foreign repository with a MediaWiki database accessible via the configured LBFactory
|
||||
*
|
||||
|
|
@ -59,14 +63,14 @@ class ForeignDBViaLBRepo extends LocalRepo {
|
|||
* @return IDatabase
|
||||
*/
|
||||
function getMasterDB() {
|
||||
return wfGetLB( $this->wiki )->getConnectionRef( DB_MASTER, [], $this->wiki );
|
||||
return $this->getDBLoadBalancer()->getConnectionRef( DB_MASTER, [], $this->wiki );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return IDatabase
|
||||
*/
|
||||
function getReplicaDB() {
|
||||
return wfGetLB( $this->wiki )->getConnectionRef( DB_REPLICA, [], $this->wiki );
|
||||
return $this->getDBLoadBalancer()->getConnectionRef( DB_REPLICA, [], $this->wiki );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -74,10 +78,18 @@ class ForeignDBViaLBRepo extends LocalRepo {
|
|||
*/
|
||||
protected function getDBFactory() {
|
||||
return function ( $index ) {
|
||||
return wfGetLB( $this->wiki )->getConnectionRef( $index, [], $this->wiki );
|
||||
return $this->getDBLoadBalancer()->getConnectionRef( $index, [], $this->wiki );
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return LoadBalancer
|
||||
*/
|
||||
protected function getDBLoadBalancer() {
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
return $lbFactory->getMainLB( $this->wiki );
|
||||
}
|
||||
|
||||
function hasSharedCache() {
|
||||
return $this->hasSharedCache;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class Interwiki {
|
|||
protected $mAPI;
|
||||
|
||||
/** @var string The name of the database (for a connection to be established
|
||||
* with wfGetLB( 'wikiid' ))
|
||||
* with LBFactory::getMainLB( 'wikiid' ))
|
||||
*/
|
||||
protected $mWikiID;
|
||||
|
||||
|
|
|
|||
|
|
@ -414,7 +414,8 @@ class User implements IDBAccessObject, UserIdentity {
|
|||
break;
|
||||
case 'actor':
|
||||
// Make sure this thread sees its own changes
|
||||
if ( wfGetLB()->hasOrMadeRecentMasterChanges() ) {
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
if ( $lb->hasOrMadeRecentMasterChanges() ) {
|
||||
$flags |= self::READ_LATEST;
|
||||
$this->queryFlagsUsed = $flags;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Maintenance script that reports the hostname of a replica DB server.
|
||||
*
|
||||
|
|
@ -43,7 +45,7 @@ class GetSlaveServer extends Maintenance {
|
|||
$db = $this->getDB( DB_REPLICA, $this->getOption( 'group' ) );
|
||||
$host = $db->getServer();
|
||||
} else {
|
||||
$lb = wfGetLB();
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
$i = $lb->getReaderIndex();
|
||||
$host = $lb->getServerName( $i );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@
|
|||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
class InitEditCount extends Maintenance {
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
|
|
@ -48,7 +50,8 @@ in the load balancer, usually indicating a replication environment.' );
|
|||
} elseif ( $this->hasOption( 'quick' ) ) {
|
||||
$backgroundMode = false;
|
||||
} else {
|
||||
$backgroundMode = wfGetLB()->getServerCount() > 1;
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
$backgroundMode = $lb->getServerCount() > 1;
|
||||
}
|
||||
|
||||
$actorQuery = ActorMigration::newMigration()->getJoin( 'rev_user' );
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@
|
|||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Maintenance script to show database lag.
|
||||
*
|
||||
|
|
@ -36,8 +38,8 @@ class DatabaseLag extends Maintenance {
|
|||
}
|
||||
|
||||
public function execute() {
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
if ( $this->hasOption( 'r' ) ) {
|
||||
$lb = wfGetLB();
|
||||
echo 'time ';
|
||||
|
||||
$serverCount = $lb->getServerCount();
|
||||
|
|
@ -58,7 +60,6 @@ class DatabaseLag extends Maintenance {
|
|||
sleep( 5 );
|
||||
}
|
||||
} else {
|
||||
$lb = wfGetLB();
|
||||
$lags = $lb->getLagTimes();
|
||||
foreach ( $lags as $i => $lag ) {
|
||||
$name = $lb->getServerName( $i );
|
||||
|
|
|
|||
|
|
@ -1091,7 +1091,7 @@ CREATE TABLE /*_*/interwiki (
|
|||
-- The URL of the file api.php
|
||||
iw_api nvarchar(max) NOT NULL,
|
||||
|
||||
-- The name of the database (for a connection to be established with wfGetLB( 'wikiid' ))
|
||||
-- The name of the database (for a connection to be established with LBFactory::getMainLB( 'wikiid' ))
|
||||
iw_wikiid nvarchar(64) NOT NULL,
|
||||
|
||||
-- A boolean value indicating whether the wiki is in this project
|
||||
|
|
|
|||
|
|
@ -1540,7 +1540,7 @@ CREATE TABLE /*_*/interwiki (
|
|||
-- The URL of the file api.php
|
||||
iw_api blob NOT NULL,
|
||||
|
||||
-- The name of the database (for a connection to be established with wfGetLB( 'wikiid' ))
|
||||
-- The name of the database (for a connection to be established with LBFactory::getMainLB( 'wikiid' ))
|
||||
iw_wikiid varchar(64) NOT NULL,
|
||||
|
||||
-- A boolean value indicating whether the wiki is in this project
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@
|
|||
|
||||
require_once __DIR__ . '/Maintenance.php';
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\DBReplicationWaitError;
|
||||
|
||||
/**
|
||||
* Maintenance script to update cached special pages.
|
||||
*
|
||||
|
|
@ -119,16 +122,22 @@ class UpdateSpecialPages extends Maintenance {
|
|||
* mysql connection to "go away"
|
||||
*/
|
||||
private function reopenAndWaitForReplicas() {
|
||||
if ( !wfGetLB()->pingAll() ) {
|
||||
$lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
|
||||
$lb = $lbFactory->getMainLB();
|
||||
if ( !$lb->pingAll() ) {
|
||||
$this->output( "\n" );
|
||||
do {
|
||||
$this->error( "Connection failed, reconnecting in 10 seconds..." );
|
||||
sleep( 10 );
|
||||
} while ( !wfGetLB()->pingAll() );
|
||||
} while ( !$lb->pingAll() );
|
||||
$this->output( "Reconnected\n\n" );
|
||||
}
|
||||
# Wait for the replica DB to catch up
|
||||
wfWaitForSlaves();
|
||||
// Wait for the replica DB to catch up
|
||||
try {
|
||||
$lbFactory->waitForReplication();
|
||||
} catch ( DBReplicationWaitError $e ) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
public function doSpecialPageCacheUpdates( $dbw ) {
|
||||
|
|
|
|||
|
|
@ -1244,7 +1244,7 @@ class ParserTestRunner {
|
|||
$teardown[] = $this->markSetupDone( 'setupDatabase' );
|
||||
|
||||
# CREATE TEMPORARY TABLE breaks if there is more than one server
|
||||
if ( wfGetLB()->getServerCount() != 1 ) {
|
||||
if ( MediaWikiServices::getInstance()->getDBLoadBalancer()->getServerCount() != 1 ) {
|
||||
$this->useTemporaryTables = false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1259,7 +1259,8 @@ class RevisionStoreDbTest extends MediaWikiTestCase {
|
|||
*/
|
||||
public function testNewMutableRevisionFromArray_legacyEncoding( array $array ) {
|
||||
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
|
||||
$blobStore = new SqlBlobStore( wfGetLB(), $cache );
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
$blobStore = new SqlBlobStore( $lb, $cache );
|
||||
$blobStore->setLegacyEncoding( 'windows-1252', Language::factory( 'en' ) );
|
||||
|
||||
$factory = $this->getMockBuilder( BlobStoreFactory::class )
|
||||
|
|
|
|||
|
|
@ -614,11 +614,12 @@ class RevisionStoreTest extends MediaWikiTestCase {
|
|||
*/
|
||||
public function testNewRevisionFromRow_legacyEncoding_applied( $encoding, $locale, $row, $text ) {
|
||||
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
|
||||
$blobStore = new SqlBlobStore( wfGetLB(), $cache );
|
||||
$blobStore = new SqlBlobStore( $lb, $cache );
|
||||
$blobStore->setLegacyEncoding( $encoding, Language::factory( $locale ) );
|
||||
|
||||
$store = $this->getRevisionStore( wfGetLB(), $blobStore, $cache );
|
||||
$store = $this->getRevisionStore( $lb, $blobStore, $cache );
|
||||
|
||||
$record = $store->newRevisionFromRow(
|
||||
$this->makeRow( $row ),
|
||||
|
|
@ -640,11 +641,12 @@ class RevisionStoreTest extends MediaWikiTestCase {
|
|||
];
|
||||
|
||||
$cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
|
||||
$blobStore = new SqlBlobStore( wfGetLB(), $cache );
|
||||
$blobStore = new SqlBlobStore( $lb, $cache );
|
||||
$blobStore->setLegacyEncoding( 'windows-1252', Language::factory( 'en' ) );
|
||||
|
||||
$store = $this->getRevisionStore( wfGetLB(), $blobStore, $cache );
|
||||
$store = $this->getRevisionStore( $lb, $blobStore, $cache );
|
||||
|
||||
$record = $store->newRevisionFromRow(
|
||||
$this->makeRow( $row ),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
/**
|
||||
* Tests for the DBSiteStore class.
|
||||
*
|
||||
|
|
@ -37,7 +39,8 @@ class DBSiteStoreTest extends MediaWikiTestCase {
|
|||
private function newDBSiteStore() {
|
||||
// NOTE: Use the real DB load balancer for now. Eventually, the test framework should
|
||||
// provide a LoadBalancer that is safe to use in unit tests.
|
||||
return new DBSiteStore( wfGetLB() );
|
||||
$lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
|
||||
return new DBSiteStore( $lb );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue