From 903e8b63de95de2da55ba21f01f70eecb527940c Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Wed, 31 Oct 2018 10:36:48 -0700 Subject: [PATCH] doc: Modernise parameter names and documentation for 'replica' DBs Non-breaking change. Remaining uses are public interfaces (a constant, two globals, a config sub-parameter, SQL queries, storage function names), one i18n message key, and a whole lot of maintenance scripts with calls to the deprecated function wfWaitForSlaves(). Change-Id: I6ee5ca92ccf6a80c08f53d9efe38ebb4b05064d7 --- includes/OutputPage.php | 2 +- includes/Storage/DerivedPageDataUpdater.php | 2 +- includes/Title.php | 4 +-- includes/api/ApiBase.php | 8 +++--- includes/search/SearchDatabase.php | 2 +- includes/user/User.php | 26 +++++++++---------- tests/phpunit/includes/db/LBFactoryTest.php | 6 ++--- .../objectcache/ReplicatedBagOStuffTest.php | 4 +-- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index aa2afe962d..2306788534 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2924,7 +2924,7 @@ class OutputPage extends ContextSource { * then the warning is a bit more obvious. If the lag is * lower than $wgSlaveLagWarning, then no warning is shown. * - * @param int $lag Slave lag + * @param int $lag Replica lag */ public function showLagWarning( $lag ) { $config = $this->getConfig(); diff --git a/includes/Storage/DerivedPageDataUpdater.php b/includes/Storage/DerivedPageDataUpdater.php index e908968b43..ad29f91e99 100644 --- a/includes/Storage/DerivedPageDataUpdater.php +++ b/includes/Storage/DerivedPageDataUpdater.php @@ -279,7 +279,7 @@ class DerivedPageDataUpdater implements IDBAccessObject { $this->jobQueueGroup = $jobQueueGroup; $this->messageCache = $messageCache; $this->contLang = $contLang; - // XXX only needed for waiting for slaves to catch up; there should be a narrower + // XXX only needed for waiting for replicas to catch up; there should be a narrower // interface for that. $this->loadbalancerFactory = $loadbalancerFactory; } diff --git a/includes/Title.php b/includes/Title.php index 51d8b1355c..4fa6fb1f41 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2687,9 +2687,9 @@ class Title implements LinkTarget { $errors[] = [ 'confirmedittext' ]; } - $useSlave = ( $rigor !== 'secure' ); + $useReplica = ( $rigor !== 'secure' ); if ( ( $action == 'edit' || $action == 'create' ) - && !$user->isBlockedFrom( $this, $useSlave ) + && !$user->isBlockedFrom( $this, $useReplica ) ) { // Don't block the user from editing their own talk page unless they've been // explicitly blocked from that too. diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index c66e5d52bb..1149d1ea3c 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -271,7 +271,7 @@ abstract class ApiBase extends ContextSource { private $mMainModule; /** @var string */ private $mModuleName, $mModulePrefix; - private $mSlaveDB = null; + private $mReplicaDB = null; private $mParamCache = []; /** @var array|null|bool */ private $mModuleSource = false; @@ -647,11 +647,11 @@ abstract class ApiBase extends ContextSource { * @return IDatabase */ protected function getDB() { - if ( !isset( $this->mSlaveDB ) ) { - $this->mSlaveDB = wfGetDB( DB_REPLICA, 'api' ); + if ( !isset( $this->mReplicaDB ) ) { + $this->mReplicaDB = wfGetDB( DB_REPLICA, 'api' ); } - return $this->mSlaveDB; + return $this->mReplicaDB; } /** diff --git a/includes/search/SearchDatabase.php b/includes/search/SearchDatabase.php index 93f8d2301f..54bfd28f68 100644 --- a/includes/search/SearchDatabase.php +++ b/includes/search/SearchDatabase.php @@ -30,7 +30,7 @@ use Wikimedia\Rdbms\IDatabase; */ abstract class SearchDatabase extends SearchEngine { /** - * @var IDatabase Slave database for reading from for results + * @var IDatabase Replica database from which to read results */ protected $db; diff --git a/includes/user/User.php b/includes/user/User.php index 11cfd4956d..d783aaa107 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -1822,11 +1822,11 @@ class User implements IDBAccessObject, UserIdentity { /** * Get blocking information - * @param bool $bFromSlave Whether to check the replica DB first. + * @param bool $bFromReplica Whether to check the replica DB first. * To improve performance, non-critical checks are done against replica DBs. * Check when actually saving should be done against master. */ - private function getBlockedStatus( $bFromSlave = true ) { + private function getBlockedStatus( $bFromReplica = true ) { global $wgProxyWhitelist, $wgUser, $wgApplyIpBlocksToXff, $wgSoftBlockRanges; if ( -1 != $this->mBlockedby ) { @@ -1858,7 +1858,7 @@ class User implements IDBAccessObject, UserIdentity { } // User/IP blocking - $block = Block::newFromTarget( $this, $ip, !$bFromSlave ); + $block = Block::newFromTarget( $this, $ip, !$bFromReplica ); // Cookie blocking if ( !$block instanceof Block ) { @@ -1894,7 +1894,7 @@ class User implements IDBAccessObject, UserIdentity { $xff = $this->getRequest()->getHeader( 'X-Forwarded-For' ); $xff = array_map( 'trim', explode( ',', $xff ) ); $xff = array_diff( $xff, [ $ip ] ); - $xffblocks = Block::getBlocksForIPList( $xff, $this->isAnon(), !$bFromSlave ); + $xffblocks = Block::getBlocksForIPList( $xff, $this->isAnon(), !$bFromReplica ); $block = Block::chooseBlock( $xffblocks, $xff ); if ( $block instanceof Block ) { # Mangle the reason to alert the user that the block @@ -2270,22 +2270,22 @@ class User implements IDBAccessObject, UserIdentity { /** * Check if user is blocked * - * @param bool $bFromSlave Whether to check the replica DB instead of + * @param bool $bFromReplica Whether to check the replica DB instead of * the master. Hacked from false due to horrible probs on site. * @return bool True if blocked, false otherwise */ - public function isBlocked( $bFromSlave = true ) { - return $this->getBlock( $bFromSlave ) instanceof Block && $this->getBlock()->prevents( 'edit' ); + public function isBlocked( $bFromReplica = true ) { + return $this->getBlock( $bFromReplica ) instanceof Block && $this->getBlock()->prevents( 'edit' ); } /** * Get the block affecting the user, or null if the user is not blocked * - * @param bool $bFromSlave Whether to check the replica DB instead of the master + * @param bool $bFromReplica Whether to check the replica DB instead of the master * @return Block|null */ - public function getBlock( $bFromSlave = true ) { - $this->getBlockedStatus( $bFromSlave ); + public function getBlock( $bFromReplica = true ) { + $this->getBlockedStatus( $bFromReplica ); return $this->mBlock instanceof Block ? $this->mBlock : null; } @@ -2293,14 +2293,14 @@ class User implements IDBAccessObject, UserIdentity { * Check if user is blocked from editing a particular article * * @param Title $title Title to check - * @param bool $fromSlave Whether to check the replica DB instead of the master + * @param bool $fromReplica Whether to check the replica DB instead of the master * @return bool */ - public function isBlockedFrom( $title, $fromSlave = false ) { + public function isBlockedFrom( $title, $fromReplica = false ) { $blocked = $this->isHidden(); if ( !$blocked ) { - $block = $this->getBlock( $fromSlave ); + $block = $this->getBlock( $fromReplica ); if ( $block ) { $blocked = $block->preventsEdit( $title ); } diff --git a/tests/phpunit/includes/db/LBFactoryTest.php b/tests/phpunit/includes/db/LBFactoryTest.php index e84998ccf2..e865e79b68 100644 --- a/tests/phpunit/includes/db/LBFactoryTest.php +++ b/tests/phpunit/includes/db/LBFactoryTest.php @@ -126,7 +126,7 @@ class LBFactoryTest extends MediaWikiTestCase { 'load' => 0, 'flags' => DBO_TRX // REPEATABLE-READ for consistency ], - [ // emulated slave + [ // emulated replica 'host' => $wgDBserver, 'dbname' => $wgDBname, 'user' => $wgDBuser, @@ -152,7 +152,7 @@ class LBFactoryTest extends MediaWikiTestCase { 'cluster master set' ); $dbr = $lb->getConnection( DB_REPLICA ); - $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows as slave' ); + $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'replica shows as replica' ); $this->assertEquals( ( $wgDBserver != '' ) ? $wgDBserver : 'localhost', $dbr->getLBInfo( 'clusterMasterHost' ), @@ -169,7 +169,7 @@ class LBFactoryTest extends MediaWikiTestCase { $this->assertTrue( $dbw->getLBInfo( 'master' ), 'master shows as master' ); $dbr = $factory->getMainLB()->getConnection( DB_REPLICA ); - $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'slave shows as slave' ); + $this->assertTrue( $dbr->getLBInfo( 'replica' ), 'replica shows as replica' ); // Destructor should trigger without round stage errors unset( $factory ); diff --git a/tests/phpunit/includes/libs/objectcache/ReplicatedBagOStuffTest.php b/tests/phpunit/includes/libs/objectcache/ReplicatedBagOStuffTest.php index 1b502ec14b..b7f22ece94 100644 --- a/tests/phpunit/includes/libs/objectcache/ReplicatedBagOStuffTest.php +++ b/tests/phpunit/includes/libs/objectcache/ReplicatedBagOStuffTest.php @@ -29,7 +29,7 @@ class ReplicatedBagOStuffTest extends MediaWikiTestCase { // Write to master. $this->assertEquals( $this->writeCache->get( $key ), $value ); - // Don't write to slave. Replication is deferred to backend. + // Don't write to replica. Replication is deferred to backend. $this->assertEquals( $this->readCache->get( $key ), false ); } @@ -44,7 +44,7 @@ class ReplicatedBagOStuffTest extends MediaWikiTestCase { $read = wfRandomString(); $this->readCache->set( $key, $read ); - // Read from slave. + // Read from replica. $this->assertEquals( $this->cache->get( $key ), $read ); } -- 2.20.1