Rename getSlaveDB() FileRepo method to getReplicaDB()
authorAaron Schulz <aschulz@wikimedia.org>
Fri, 18 Nov 2016 15:42:39 +0000 (07:42 -0800)
committerAaron Schulz <aschulz@wikimedia.org>
Fri, 18 Nov 2016 15:42:39 +0000 (07:42 -0800)
The old name is left as an alias.

Change-Id: I60ab2cd5ce05df4247d5e25b017d2debee56554e

13 files changed:
includes/api/ApiQueryAllImages.php
includes/filerepo/ForeignDBRepo.php
includes/filerepo/ForeignDBViaLBRepo.php
includes/filerepo/LocalRepo.php
includes/filerepo/file/ForeignDBFile.php
includes/filerepo/file/LocalFile.php
includes/filerepo/file/OldLocalFile.php
includes/page/WikiFilePage.php
includes/upload/UploadStash.php
maintenance/cleanupUploadStash.php
maintenance/findMissingFiles.php
maintenance/findOrphanedFiles.php
maintenance/purgeChangedFiles.php

index 553995c..8734f38 100644 (file)
@@ -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() {
index 7fb7a0e..f49ef88 100644 (file)
@@ -89,7 +89,7 @@ class ForeignDBRepo extends LocalRepo {
        /**
         * @return IDatabase
         */
-       function getSlaveDB() {
+       function getReplicaDB() {
                return $this->getMasterDB();
        }
 
index 129d55a..a9cd030 100644 (file)
@@ -65,7 +65,7 @@ class ForeignDBViaLBRepo extends LocalRepo {
        /**
         * @return IDatabase
         */
-       function getSlaveDB() {
+       function getReplicaDB() {
                return wfGetLB( $this->wiki )->getConnectionRef( DB_REPLICA, [], $this->wiki );
        }
 
index c4730d7..d49ae7b 100644 (file)
@@ -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
index c041dea..df50a67 100644 (file)
@@ -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',
index d3a14fa..011ba87 100644 (file)
@@ -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;
                }
 
index 06fef4f..dfaae73 100644 (file)
@@ -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;
index c478550..74566cb 100644 (file)
@@ -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' ],
index b7160b3..48477f8 100644 (file)
@@ -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(
index cd7a842..95bbe3d 100644 (file)
@@ -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;
index c06a72e..7979e7d 100644 (file)
@@ -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 ) );
index abd170b..5980631 100644 (file)
@@ -75,7 +75,7 @@ class FindOrphanedFiles extends Maintenance {
                        return;
                }
 
-               $dbr = $repo->getSlaveDB();
+               $dbr = $repo->getReplicaDB();
 
                $curNames = [];
                $oldNames = [];
index 615d1fe..3c0fc7e 100644 (file)
@@ -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' ],