if ( $module->isWriteMode()
&& $this->getUser()->isBot()
- && wfGetLB()->getServerCount() > 1
+ && MediaWikiServices::getInstance()->getDBLoadBalancer()->getServerCount() > 1
) {
$this->checkBotReadOnly();
}
$numLagged = 0;
$lagLimit = $this->getConfig()->get( 'APIMaxLagThreshold' );
$laggedServers = [];
- $loadBalancer = wfGetLB();
+ $loadBalancer = MediaWikiServices::getInstance()->getDBLoadBalancer();
foreach ( $loadBalancer->getLagTimes() as $serverIndex => $lag ) {
if ( $lag > $lagLimit ) {
++$numLagged;
}
// If a majority of replica DBs are too lagged then disallow writes
- $replicaCount = wfGetLB()->getServerCount() - 1;
+ $replicaCount = $loadBalancer->getServerCount() - 1;
if ( $numLagged >= ceil( $replicaCount / 2 ) ) {
$laggedServers = implode( ', ', $laggedServers );
wfDebugLog(
protected function appendDbReplLagInfo( $property, $includeAll ) {
$data = [];
- $lb = wfGetLB();
+ $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
$showHostnames = $this->getConfig()->get( 'ShowHostnames' );
if ( $includeAll ) {
if ( !$showHostnames ) {
// Fetch the user ID from the master, so that we don't try to create the user
// when they already exist, due to replication lag
// @codeCoverageIgnoreStart
- if ( !$localId && wfGetLB()->getReaderIndex() != 0 ) {
+ if (
+ !$localId &&
+ MediaWikiServices::getInstance()->getDBLoadBalancer()->getReaderIndex() != 0
+ ) {
$localId = User::idFromName( $username, User::READ_LATEST );
$flags = User::READ_LATEST;
}
$this->applyPatch( 'patch-templatelinks.sql', false, "Creating templatelinks table" );
$this->output( "Populating...\n" );
- if ( wfGetLB()->getServerCount() > 1 ) {
+ $services = MediaWikiServices::getInstance();
+ if ( $services->getDBLoadBalancer()->getServerCount() > 1 ) {
// Slow, replication-friendly update
$res = $this->db->select( 'pagelinks', [ 'pl_from', 'pl_namespace', 'pl_title' ],
[ 'pl_namespace' => NS_TEMPLATE ], __METHOD__ );
foreach ( $res as $row ) {
$count = ( $count + 1 ) % 100;
if ( $count == 0 ) {
- $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
+ $lbFactory = $services->getDBLoadBalancerFactory();
$lbFactory->waitForReplication( [ 'wiki' => wfWikiID() ] );
}
$this->db->insert( 'templatelinks',
) {
$baseRevId = null;
if ( $edittime && $sectionId !== 'new' ) {
+ $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
$dbr = wfGetDB( DB_REPLICA );
$rev = Revision::loadFromTimestamp( $dbr, $this->mTitle, $edittime );
// Try the master if this thread may have just added it.
// This could be abstracted into a Revision method, but we don't want
// to encourage loading of revisions by timestamp.
if ( !$rev
- && wfGetLB()->getServerCount() > 1
- && wfGetLB()->hasOrMadeRecentMasterChanges()
+ && $lb->getServerCount() > 1
+ && $lb->hasOrMadeRecentMasterChanges()
) {
$dbw = wfGetDB( DB_MASTER );
$rev = Revision::loadFromTimestamp( $dbw, $this->mTitle, $edittime );
$s = '';
}
- if ( wfGetLB()->getLaggedReplicaMode() ) {
+ if ( MediaWikiServices::getInstance()->getDBLoadBalancer()->getLaggedReplicaMode() ) {
$s .= ' <strong>' . $this->msg( 'laggedslavemode' )->parse() . '</strong>';
}
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
use MediaWiki\Widget\DateInputWidget;
/**
$out->addWikiMsg( 'nocontribs', $target );
} else {
# Show a message about replica DB lag, if applicable
- $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
+ $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
+ $lag = $lb->safeGetLag( $pager->getDatabase() );
if ( $lag > 0 ) {
$out->showLagWarning( $lag );
}
* @ingroup SpecialPage
*/
+use MediaWiki\MediaWikiServices;
+
/**
* Implements Special:DeletedContributions to display archived revisions
* @ingroup SpecialPage
}
# Show a message about replica DB lag, if applicable
- $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
+ $lb = MediaWikiServices::getInstance()->getDBLoadBalancer();
+ $lag = $lb->safeGetLag( $pager->getDatabase() );
if ( $lag > 0 ) {
$out->showLagWarning( $lag );
}
$output = $this->getOutput();
# Show a message about replica DB lag, if applicable
- $lag = wfGetLB()->safeGetLag( $dbr );
+ $lag = MediaWikiServices::getInstance()->getDBLoadBalancer()->safeGetLag( $dbr );
if ( $lag > 0 ) {
$output->showLagWarning( $lag );
}
break;
case 'name':
// 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;
}