Skip to content

Commit

Permalink
Rename DB_SLAVE constant to DB_REPLICA
Browse files Browse the repository at this point in the history
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
  • Loading branch information
AaronSchulz authored and legoktm committed Sep 6, 2016
1 parent bdacaac commit 950cf60
Show file tree
Hide file tree
Showing 160 changed files with 314 additions and 312 deletions.
16 changes: 8 additions & 8 deletions includes/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function __construct( $options = [] ) {

$this->mReason = $options['reason'];
$this->mTimestamp = wfTimestamp( TS_MW, $options['timestamp'] );
$this->mExpiry = wfGetDB( DB_SLAVE )->decodeExpiry( $options['expiry'] );
$this->mExpiry = wfGetDB( DB_REPLICA )->decodeExpiry( $options['expiry'] );

# Boolean settings
$this->mAuto = (bool)$options['auto'];
Expand All @@ -168,7 +168,7 @@ function __construct( $options = [] ) {
* @return Block|null
*/
public static function newFromID( $id ) {
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$res = $dbr->selectRow(
'ipblocks',
self::selectFields(),
Expand Down Expand Up @@ -242,7 +242,7 @@ public function equals( Block $block ) {
* @return bool Whether a relevant block was found
*/
protected function newLoad( $vagueTarget = null ) {
$db = wfGetDB( $this->mFromMaster ? DB_MASTER : DB_SLAVE );
$db = wfGetDB( $this->mFromMaster ? DB_MASTER : DB_REPLICA );

if ( $this->type !== null ) {
$conds = [
Expand Down Expand Up @@ -351,7 +351,7 @@ public static function getRangeCond( $start, $end = null ) {
# range. We know that all blocks must be smaller than $wgBlockCIDRLimit,
# so we can improve performance by filtering on a LIKE clause
$chunk = self::getIpFragment( $start );
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$like = $dbr->buildLike( $chunk, $dbr->anyString() );

# Fairly hard to make a malicious SQL statement out of hex characters,
Expand Down Expand Up @@ -405,7 +405,7 @@ protected function initFromRow( $row ) {
$this->mParentBlockId = $row->ipb_parent_block_id;

// I wish I didn't have to do this
$this->mExpiry = wfGetDB( DB_SLAVE )->decodeExpiry( $row->ipb_expiry );
$this->mExpiry = wfGetDB( DB_REPLICA )->decodeExpiry( $row->ipb_expiry );

$this->isHardblock( !$row->ipb_anon_only );
$this->isAutoblocking( $row->ipb_enable_autoblock );
Expand Down Expand Up @@ -569,7 +569,7 @@ public function update() {
*/
protected function getDatabaseArray( $db = null ) {
if ( !$db ) {
$db = wfGetDB( DB_SLAVE );
$db = wfGetDB( DB_REPLICA );
}
$expiry = $db->encodeExpiry( $this->mExpiry );

Expand Down Expand Up @@ -653,7 +653,7 @@ protected static function defaultRetroactiveAutoblock( Block $block, array &$blo
return;
}

$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );

$options = [ 'ORDER BY' => 'rc_timestamp DESC' ];
$conds = [ 'rc_user_text' => (string)$block->getTarget() ];
Expand Down Expand Up @@ -1146,7 +1146,7 @@ public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster
if ( $fromMaster ) {
$db = wfGetDB( DB_MASTER );
} else {
$db = wfGetDB( DB_SLAVE );
$db = wfGetDB( DB_REPLICA );
}
$conds = $db->makeList( $conds, LIST_OR );
if ( !$isAnon ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function initialize() {
return true;
}

$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$row = $dbr->selectRow(
'category',
[ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
Expand Down Expand Up @@ -264,7 +264,7 @@ public function getTitle() {
*/
public function getMembers( $limit = false, $offset = '' ) {

$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );

$conds = [ 'cl_to' => $this->getName(), 'cl_from = page_id' ];
$options = [ 'ORDER BY' => 'cl_sortkey' ];
Expand Down
2 changes: 1 addition & 1 deletion includes/CategoryFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function seed( $articleIds, $categories, $mode = 'AND' ) {
* @return array Array of page_ids (those given to seed() that match the conditions)
*/
public function run() {
$this->dbr = wfGetDB( DB_SLAVE );
$this->dbr = wfGetDB( DB_REPLICA );
while ( count( $this->next ) > 0 ) {
$this->scanNextLayer();
}
Expand Down
2 changes: 1 addition & 1 deletion includes/CategoryViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function finaliseCategoryState() {
}

function doCategoryQuery() {
$dbr = wfGetDB( DB_SLAVE, 'category' );
$dbr = wfGetDB( DB_REPLICA, 'category' );

$this->nextPage = [
'page' => null,
Expand Down
2 changes: 1 addition & 1 deletion includes/DefaultSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1895,7 +1895,7 @@
* - password: DB password
* - type: DB type
*
* - load: Ratio of DB_SLAVE load, must be >=0, the sum of all loads must be >0.
* - load: Ratio of DB_REPLICA load, must be >=0, the sum of all loads must be >0.
* If this is zero for any given server, no normal query traffic will be
* sent to it. It will be excluded from lag checks in maintenance scripts.
* The only way it can receive traffic is if groupLoads is used.
Expand Down
3 changes: 2 additions & 1 deletion includes/Defines.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
* Valid database indexes
* Operation-based indexes
*/
define( 'DB_SLAVE', -1 ); # Read from the replica DB (or only server)
define( 'DB_REPLICA', -1 ); # Read from a replica (or only server)
define( 'DB_MASTER', -2 ); # Write to master (or only server)
/**@}*/

# Obsolete aliases
define( 'DB_SLAVE', -1 );
define( 'DB_READ', -1 );
define( 'DB_WRITE', -2 );

Expand Down
2 changes: 1 addition & 1 deletion includes/EditPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -3613,7 +3613,7 @@ protected function wasDeletedSinceLastEdit() {
* @return bool|stdClass
*/
protected function getLastDelete() {
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$data = $dbr->selectRow(
[ 'logging', 'user' ],
[
Expand Down
6 changes: 3 additions & 3 deletions includes/GlobalFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ function wfReadOnly() {
* Check if the site is in read-only mode and return the message if so
*
* This checks wfConfiguredReadOnlyReason() and the main load balancer
* for replica DB lag. This may result in DB_SLAVE connection being made.
* for replica DB lag. This may result in DB connection being made.
*
* @return string|bool String when in read-only mode; false otherwise
*/
Expand Down Expand Up @@ -3125,7 +3125,7 @@ function wfSplitWikiID( $wiki ) {
* Get a Database object.
*
* @param int $db Index of the connection to get. May be DB_MASTER for the
* master (for write queries), DB_SLAVE for potentially lagged read
* master (for write queries), DB_REPLICA for potentially lagged read
* queries, or an integer >= 0 for a particular server.
*
* @param string|string[] $groups Query groups. An array of group names that this query
Expand All @@ -3134,7 +3134,7 @@ function wfSplitWikiID( $wiki ) {
*
* @param string|bool $wiki The wiki ID, or false for the current wiki
*
* Note: multiple calls to wfGetDB(DB_SLAVE) during the course of one request
* Note: multiple calls to wfGetDB(DB_REPLICA) during the course of one request
* will always return the same object, unless the underlying connection or load
* balancer is manually destroyed.
*
Expand Down
4 changes: 2 additions & 2 deletions includes/HistoryBlob.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function getText() {
if ( isset( self::$blobCache[$this->mOldId] ) ) {
$obj = self::$blobCache[$this->mOldId];
} else {
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$row = $dbr->selectRow(
'text',
[ 'old_flags', 'old_text' ],
Expand Down Expand Up @@ -336,7 +336,7 @@ function setLocation( $id ) {
* @return string|bool
*/
function getText() {
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$row = $dbr->selectRow( 'cur', [ 'cur_text' ], [ 'cur_id' => $this->mCurId ] );
if ( !$row ) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion includes/LinkFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private static function makeRegex( $filterEntry ) {
* @return array Array to be passed to Database::buildLike() or false on error
*/
public static function makeLikeArray( $filterEntry, $protocol = 'http://' ) {
$db = wfGetDB( DB_SLAVE );
$db = wfGetDB( DB_REPLICA );

$target = $protocol . $filterEntry;
$bits = wfParseUrl( $target );
Expand Down
2 changes: 1 addition & 1 deletion includes/Linker.php
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,7 @@ public static function getRollbackEditCount( $rev, $verify ) {
return null;
}

$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );

// Up to the value of $wgShowRollbackEditCount revisions are counted
$res = $dbr->select(
Expand Down
2 changes: 1 addition & 1 deletion includes/OutputPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ public function addCategoryLinks( array $categories ) {
$lb->setArray( $arr );

# Fetch existence plus the hiddencat property
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$fields = array_merge(
LinkCache::getSelectFields(),
[ 'page_namespace', 'page_title', 'pp_value' ]
Expand Down
4 changes: 2 additions & 2 deletions includes/PageProps.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getProperties( $titles, $propertyNames ) {
}

if ( $queryIDs ) {
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$result = $dbr->select(
'page_props',
[
Expand Down Expand Up @@ -198,7 +198,7 @@ public function getAllProperties( $titles ) {
}

if ( $queryIDs != [] ) {
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$result = $dbr->select(
'page_props',
[
Expand Down
4 changes: 2 additions & 2 deletions includes/Pingback.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private function shouldSend() {
* @return bool
*/
private function checkIfSent() {
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$sent = $dbr->selectField(
'updatelog', '1', [ 'ul_key' => $this->key ], __METHOD__ );
return $sent !== false;
Expand Down Expand Up @@ -168,7 +168,7 @@ private function getData() {
*/
private function getOrCreatePingbackId() {
if ( !$this->id ) {
$id = wfGetDB( DB_SLAVE )->selectField(
$id = wfGetDB( DB_REPLICA )->selectField(
'updatelog', 'ul_value', [ 'ul_key' => 'PingBack' ] );

if ( $id == false ) {
Expand Down
2 changes: 1 addition & 1 deletion includes/PrefixSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public function defaultSearchBackend( $namespaces, $search, $limit, $offset ) {

$t = Title::newFromText( $search, $ns );
$prefix = $t ? $t->getDBkey() : '';
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$res = $dbr->select( 'page',
[ 'page_id', 'page_namespace', 'page_title' ],
[
Expand Down
18 changes: 9 additions & 9 deletions includes/Revision.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function newFromTitle( LinkTarget $linkTarget, $id = 0, $flags = 0
} else {
// Use a join to get the latest revision
$conds[] = 'rev_id=page_latest';
$db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE );
$db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_REPLICA );
return self::loadFromConds( $db, $conds, $flags );
}
}
Expand All @@ -161,7 +161,7 @@ public static function newFromPageId( $pageId, $revId = 0, $flags = 0 ) {
} else {
// Use a join to get the latest revision
$conds[] = 'rev_id = page_latest';
$db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE );
$db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_REPLICA );
return self::loadFromConds( $db, $conds, $flags );
}
}
Expand Down Expand Up @@ -316,7 +316,7 @@ public static function loadFromTimestamp( $db, $title, $timestamp ) {
* @return Revision|null
*/
private static function newFromConds( $conditions, $flags = 0 ) {
$db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_SLAVE );
$db = wfGetDB( ( $flags & self::READ_LATEST ) ? DB_MASTER : DB_REPLICA );

$rev = self::loadFromConds( $db, $conditions, $flags );
// Make sure new pending/committed revision are visibile later on
Expand Down Expand Up @@ -370,7 +370,7 @@ private static function loadFromConds( $db, $conditions, $flags = 0 ) {
*/
public static function fetchRevision( LinkTarget $title ) {
$row = self::fetchFromConds(
wfGetDB( DB_SLAVE ),
wfGetDB( DB_REPLICA ),
[
'rev_id=page_latest',
'page_namespace' => $title->getNamespace(),
Expand Down Expand Up @@ -803,7 +803,7 @@ public function getTitle() {
}
// rev_id is defined as NOT NULL, but this revision may not yet have been inserted.
if ( $this->mId !== null ) {
$dbr = wfGetLB( $this->mWiki )->getConnectionRef( DB_SLAVE, [], $this->mWiki );
$dbr = wfGetLB( $this->mWiki )->getConnectionRef( DB_REPLICA, [], $this->mWiki );
$row = $dbr->selectRow(
[ 'page', 'revision' ],
self::selectPageFields(),
Expand Down Expand Up @@ -989,7 +989,7 @@ public function isUnpatrolled() {
* @return RecentChange|null
*/
public function getRecentChange( $flags = 0 ) {
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );

list( $dbType, ) = DBAccessObjectUtils::getDBOptions( $flags );

Expand Down Expand Up @@ -1610,7 +1610,7 @@ protected function loadText() {

if ( !$row ) {
// Text data is immutable; check replica DBs first.
$dbr = wfGetDB( DB_SLAVE );
$dbr = wfGetDB( DB_REPLICA );
$row = $dbr->selectRow( 'text',
[ 'old_text', 'old_flags' ],
[ 'old_id' => $textId ],
Expand Down Expand Up @@ -1792,7 +1792,7 @@ public static function userCanBitfield( $bitfield, $field, User $user = null,
static function getTimestampFromId( $title, $id, $flags = 0 ) {
$db = ( $flags & self::READ_LATEST )
? wfGetDB( DB_MASTER )
: wfGetDB( DB_SLAVE );
: wfGetDB( DB_REPLICA );
// Casting fix for databases that can't take '' for rev_id
if ( $id == '' ) {
$id = 0;
Expand Down Expand Up @@ -1919,7 +1919,7 @@ private function loadMutableFields() {
}

$this->mRefreshMutableFields = false;
$dbr = wfGetLB( $this->mWiki )->getConnectionRef( DB_SLAVE, [], $this->mWiki );
$dbr = wfGetLB( $this->mWiki )->getConnectionRef( DB_REPLICA, [], $this->mWiki );
$row = $dbr->selectRow(
[ 'revision', 'user' ],
[ 'rev_deleted', 'user_name' ],
Expand Down
2 changes: 1 addition & 1 deletion includes/RevisionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected function initCurrent() {
*/
public function reset() {
if ( !$this->res ) {
$this->res = $this->doQuery( wfGetDB( DB_SLAVE ) );
$this->res = $this->doQuery( wfGetDB( DB_REPLICA ) );
} else {
$this->res->rewind();
}
Expand Down
Loading

0 comments on commit 950cf60

Please sign in to comment.