From f525c725908bcb21e75240d79ce7b488af23e3df Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Fri, 18 Nov 2016 07:42:39 -0800 Subject: [PATCH] Rename getSlaveDB() FileRepo method to getReplicaDB() The old name is left as an alias. Change-Id: I60ab2cd5ce05df4247d5e25b017d2debee56554e --- includes/api/ApiQueryAllImages.php | 4 ++-- includes/filerepo/ForeignDBRepo.php | 2 +- includes/filerepo/ForeignDBViaLBRepo.php | 2 +- includes/filerepo/LocalRepo.php | 22 ++++++++++++++++------ includes/filerepo/file/ForeignDBFile.php | 4 ++-- includes/filerepo/file/LocalFile.php | 16 ++++++++-------- includes/filerepo/file/OldLocalFile.php | 6 +++--- includes/page/WikiFilePage.php | 2 +- includes/upload/UploadStash.php | 4 ++-- maintenance/cleanupUploadStash.php | 2 +- maintenance/findMissingFiles.php | 2 +- maintenance/findOrphanedFiles.php | 2 +- maintenance/purgeChangedFiles.php | 2 +- 13 files changed, 40 insertions(+), 30 deletions(-) diff --git a/includes/api/ApiQueryAllImages.php b/includes/api/ApiQueryAllImages.php index 553995c781..8734f380bb 100644 --- a/includes/api/ApiQueryAllImages.php +++ b/includes/api/ApiQueryAllImages.php @@ -44,10 +44,10 @@ class ApiQueryAllImages extends ApiQueryGeneratorBase { * which may not necessarily be the same as the local DB. * * TODO: allow querying non-local repos. - * @return Database + * @return IDatabase */ protected function getDB() { - return $this->mRepo->getSlaveDB(); + return $this->mRepo->getReplicaDB(); } public function execute() { diff --git a/includes/filerepo/ForeignDBRepo.php b/includes/filerepo/ForeignDBRepo.php index 7fb7a0e6da..f49ef88c5c 100644 --- a/includes/filerepo/ForeignDBRepo.php +++ b/includes/filerepo/ForeignDBRepo.php @@ -89,7 +89,7 @@ class ForeignDBRepo extends LocalRepo { /** * @return IDatabase */ - function getSlaveDB() { + function getReplicaDB() { return $this->getMasterDB(); } diff --git a/includes/filerepo/ForeignDBViaLBRepo.php b/includes/filerepo/ForeignDBViaLBRepo.php index 129d55aa2a..a9cd030869 100644 --- a/includes/filerepo/ForeignDBViaLBRepo.php +++ b/includes/filerepo/ForeignDBViaLBRepo.php @@ -65,7 +65,7 @@ class ForeignDBViaLBRepo extends LocalRepo { /** * @return IDatabase */ - function getSlaveDB() { + function getReplicaDB() { return wfGetLB( $this->wiki )->getConnectionRef( DB_REPLICA, [], $this->wiki ); } diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index c4730d73ec..d49ae7bf4b 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -200,7 +200,7 @@ class LocalRepo extends FileRepo { $memcKey, $expiry, function ( $oldValue, &$ttl, array &$setOpts ) use ( $method, $title ) { - $dbr = $this->getSlaveDB(); // possibly remote DB + $dbr = $this->getReplicaDB(); // possibly remote DB $setOpts += Database::getCacheSetOptions( $dbr ); @@ -298,7 +298,7 @@ class LocalRepo extends FileRepo { } }; - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); // Query image table $imgNames = []; @@ -368,7 +368,7 @@ class LocalRepo extends FileRepo { * @return File[] */ function findBySha1( $hash ) { - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); $res = $dbr->select( 'image', LocalFile::selectFields(), @@ -400,7 +400,7 @@ class LocalRepo extends FileRepo { return []; // empty parameter } - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); $res = $dbr->select( 'image', LocalFile::selectFields(), @@ -430,7 +430,7 @@ class LocalRepo extends FileRepo { $selectOptions = [ 'ORDER BY' => 'img_name', 'LIMIT' => intval( $limit ) ]; // Query database - $dbr = $this->getSlaveDB(); + $dbr = $this->getReplicaDB(); $res = $dbr->select( 'image', LocalFile::selectFields(), @@ -452,10 +452,20 @@ class LocalRepo extends FileRepo { * Get a connection to the replica DB * @return IDatabase */ - function getSlaveDB() { + function getReplicaDB() { return wfGetDB( DB_REPLICA ); } + /** + * Alias for getReplicaDB() + * + * @return IDatabase + * @deprecated Since 1.29 + */ + function getSlaveDB() { + return $this->getReplicaDB(); + } + /** * Get a connection to the master DB * @return IDatabase diff --git a/includes/filerepo/file/ForeignDBFile.php b/includes/filerepo/file/ForeignDBFile.php index c041deaac0..df50a670a2 100644 --- a/includes/filerepo/file/ForeignDBFile.php +++ b/includes/filerepo/file/ForeignDBFile.php @@ -136,7 +136,7 @@ class ForeignDBFile extends LocalFile { return false; } - $touched = $this->repo->getSlaveDB()->selectField( + $touched = $this->repo->getReplicaDB()->selectField( 'page', 'page_touched', [ @@ -179,7 +179,7 @@ class ForeignDBFile extends LocalFile { * @since 1.27 */ public function getDescriptionShortUrl() { - $dbr = $this->repo->getSlaveDB(); + $dbr = $this->repo->getReplicaDB(); $pageId = $dbr->selectField( 'page', 'page_id', diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index d3a14fa5a4..011ba87ee7 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -174,7 +174,7 @@ class LocalFile extends File { * @return bool|LocalFile */ static function newFromKey( $sha1, $repo, $timestamp = false ) { - $dbr = $repo->getSlaveDB(); + $dbr = $repo->getReplicaDB(); $conds = [ 'img_sha1' => $sha1 ]; if ( $timestamp ) { @@ -259,7 +259,7 @@ class LocalFile extends File { $key, $cache::TTL_WEEK, function ( $oldValue, &$ttl, array &$setOpts ) use ( $cache ) { - $setOpts += Database::getCacheSetOptions( $this->repo->getSlaveDB() ); + $setOpts += Database::getCacheSetOptions( $this->repo->getReplicaDB() ); $this->loadFromDB( self::READ_NORMAL ); @@ -390,7 +390,7 @@ class LocalFile extends File { $dbr = ( $flags & self::READ_LATEST ) ? $this->repo->getMasterDB() - : $this->repo->getSlaveDB(); + : $this->repo->getReplicaDB(); $row = $dbr->selectRow( 'image', $this->getCacheFields( 'img_' ), [ 'img_name' => $this->getName() ], $fname ); @@ -412,7 +412,7 @@ class LocalFile extends File { # Unconditionally set loaded=true, we don't want the accessors constantly rechecking $this->extraDataLoaded = true; - $fieldMap = $this->loadFieldsWithTimestamp( $this->repo->getSlaveDB(), $fname ); + $fieldMap = $this->loadFieldsWithTimestamp( $this->repo->getReplicaDB(), $fname ); if ( !$fieldMap ) { $fieldMap = $this->loadFieldsWithTimestamp( $this->repo->getMasterDB(), $fname ); } @@ -490,7 +490,7 @@ class LocalFile extends File { $decoded['timestamp'] = wfTimestamp( TS_MW, $decoded['timestamp'] ); - $decoded['metadata'] = $this->repo->getSlaveDB()->decodeBlob( $decoded['metadata'] ); + $decoded['metadata'] = $this->repo->getReplicaDB()->decodeBlob( $decoded['metadata'] ); if ( empty( $decoded['major_mime'] ) ) { $decoded['mime'] = 'unknown/unknown'; @@ -1037,7 +1037,7 @@ class LocalFile extends File { * @return OldLocalFile[] */ function getHistory( $limit = null, $start = null, $end = null, $inc = true ) { - $dbr = $this->repo->getSlaveDB(); + $dbr = $this->repo->getReplicaDB(); $tables = [ 'oldimage' ]; $fields = OldLocalFile::selectFields(); $conds = $opts = $join_conds = []; @@ -1091,7 +1091,7 @@ class LocalFile extends File { # Polymorphic function name to distinguish foreign and local fetches $fname = get_class( $this ) . '::' . __FUNCTION__; - $dbr = $this->repo->getSlaveDB(); + $dbr = $this->repo->getReplicaDB(); if ( $this->historyLine == 0 ) { // called for the first time, return line from cur $this->historyRes = $dbr->select( 'image', @@ -1917,7 +1917,7 @@ class LocalFile extends File { 'page_namespace' => $this->title->getNamespace(), 'page_title' => $this->title->getDBkey() ]; - $touched = $this->repo->getSlaveDB()->selectField( 'page', 'page_touched', $cond, __METHOD__ ); + $touched = $this->repo->getReplicaDB()->selectField( 'page', 'page_touched', $cond, __METHOD__ ); $this->descriptionTouched = $touched ? wfTimestamp( TS_MW, $touched ) : false; } diff --git a/includes/filerepo/file/OldLocalFile.php b/includes/filerepo/file/OldLocalFile.php index 06fef4f6f0..dfaae731c1 100644 --- a/includes/filerepo/file/OldLocalFile.php +++ b/includes/filerepo/file/OldLocalFile.php @@ -86,7 +86,7 @@ class OldLocalFile extends LocalFile { * @return bool|OldLocalFile */ static function newFromKey( $sha1, $repo, $timestamp = false ) { - $dbr = $repo->getSlaveDB(); + $dbr = $repo->getReplicaDB(); $conds = [ 'oi_sha1' => $sha1 ]; if ( $timestamp ) { @@ -179,7 +179,7 @@ class OldLocalFile extends LocalFile { $dbr = ( $flags & self::READ_LATEST ) ? $this->repo->getMasterDB() - : $this->repo->getSlaveDB(); + : $this->repo->getReplicaDB(); $conds = [ 'oi_name' => $this->getName() ]; if ( is_null( $this->requestedTime ) ) { @@ -201,7 +201,7 @@ class OldLocalFile extends LocalFile { */ protected function loadExtraFromDB() { $this->extraDataLoaded = true; - $dbr = $this->repo->getSlaveDB(); + $dbr = $this->repo->getReplicaDB(); $conds = [ 'oi_name' => $this->getName() ]; if ( is_null( $this->requestedTime ) ) { $conds['oi_archive_name'] = $this->archive_name; diff --git a/includes/page/WikiFilePage.php b/includes/page/WikiFilePage.php index c478550d0b..74566cba35 100644 --- a/includes/page/WikiFilePage.php +++ b/includes/page/WikiFilePage.php @@ -205,7 +205,7 @@ class WikiFilePage extends WikiPage { /** @var LocalRepo $repo */ $repo = $file->getRepo(); - $dbr = $repo->getSlaveDB(); + $dbr = $repo->getReplicaDB(); $res = $dbr->select( [ 'page', 'categorylinks' ], diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index b7160b3ba8..48477f8faa 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -432,7 +432,7 @@ class UploadStash { . ' No user is logged in, files must belong to users' ); } - $dbr = $this->repo->getSlaveDB(); + $dbr = $this->repo->getReplicaDB(); $res = $dbr->select( 'uploadstash', 'us_key', @@ -511,7 +511,7 @@ class UploadStash { // sometimes reading from the master is necessary, if there's replication lag. $dbr = $this->repo->getMasterDB(); } else { - $dbr = $this->repo->getSlaveDB(); + $dbr = $this->repo->getReplicaDB(); } $row = $dbr->selectRow( diff --git a/maintenance/cleanupUploadStash.php b/maintenance/cleanupUploadStash.php index cd7a8420f9..95bbe3d3ff 100644 --- a/maintenance/cleanupUploadStash.php +++ b/maintenance/cleanupUploadStash.php @@ -47,7 +47,7 @@ class UploadStashCleanup extends Maintenance { $repo = RepoGroup::singleton()->getLocalRepo(); $tempRepo = $repo->getTempRepo(); - $dbr = $repo->getSlaveDB(); + $dbr = $repo->getReplicaDB(); // how far back should this look for files to delete? $cutoff = time() - $wgUploadStashMaxAge; diff --git a/maintenance/findMissingFiles.php b/maintenance/findMissingFiles.php index c06a72e3a3..7979e7d3c1 100644 --- a/maintenance/findMissingFiles.php +++ b/maintenance/findMissingFiles.php @@ -36,7 +36,7 @@ class FindMissingFiles extends Maintenance { $lastName = $this->getOption( 'start', '' ); $repo = RepoGroup::singleton()->getLocalRepo(); - $dbr = $repo->getSlaveDB(); + $dbr = $repo->getReplicaDB(); $be = $repo->getBackend(); $mtime1 = $dbr->timestampOrNull( $this->getOption( 'mtimeafter', null ) ); diff --git a/maintenance/findOrphanedFiles.php b/maintenance/findOrphanedFiles.php index abd170b304..5980631d03 100644 --- a/maintenance/findOrphanedFiles.php +++ b/maintenance/findOrphanedFiles.php @@ -75,7 +75,7 @@ class FindOrphanedFiles extends Maintenance { return; } - $dbr = $repo->getSlaveDB(); + $dbr = $repo->getReplicaDB(); $curNames = []; $oldNames = []; diff --git a/maintenance/purgeChangedFiles.php b/maintenance/purgeChangedFiles.php index 615d1fe9a2..3c0fc7e572 100644 --- a/maintenance/purgeChangedFiles.php +++ b/maintenance/purgeChangedFiles.php @@ -210,7 +210,7 @@ class PurgeChangedFiles extends Maintenance { } protected function purgeFromArchiveTable( LocalRepo $repo, LocalFile $file ) { - $dbr = $repo->getSlaveDB(); + $dbr = $repo->getReplicaDB(); $res = $dbr->select( 'filearchive', [ 'fa_archive_name' ], -- 2.20.1