Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/311353

Change subject: Dependency cleanups to FileBackendStore
......................................................................

Dependency cleanups to FileBackendStore

* Inject a PSR logger in place of wf* logging methods.
* Replace wfTimestamp() call with ConvertableTimestamp.
* Inject the Profiler object.
* Rename $wiki => $domain to avoid "wiki" mentions.

Change-Id: I3e3a43d36506bec341dc5727b52f5f5a5d32bff5
---
M includes/filebackend/FileBackendGroup.php
M includes/filebackend/FileBackendMultiWrite.php
M includes/filebackend/FileBackendStore.php
M includes/filebackend/FileOpBatch.php
M includes/libs/filebackend/FileBackend.php
5 files changed, 102 insertions(+), 54 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/53/311353/1

diff --git a/includes/filebackend/FileBackendGroup.php 
b/includes/filebackend/FileBackendGroup.php
index 0bae5ff..8abe794 100644
--- a/includes/filebackend/FileBackendGroup.php
+++ b/includes/filebackend/FileBackendGroup.php
@@ -21,6 +21,7 @@
  * @ingroup FileBackend
  * @author Aaron Schulz
  */
+use \MediaWiki\Logger\LoggerFactory;
 
 /**
  * Class to handle file backend registration
@@ -168,6 +169,8 @@
                        $config['wanCache'] = ObjectCache::getMainWANInstance();
                        $config['mimeCallback'] = [ $this, 'guessMimeInternal' 
];
                        $config['statusWrapper'] = [ 'Status', 'wrap' ];
+                       $config['logger'] = LoggerFactory::getInstance( 
'FileOperation' );
+                       $config['profiler'] = Profiler::instance();
 
                        $this->backends[$name]['instance'] = new $class( 
$config );
                }
diff --git a/includes/filebackend/FileBackendMultiWrite.php 
b/includes/filebackend/FileBackendMultiWrite.php
index c1cc7bb..2ef3016 100644
--- a/includes/filebackend/FileBackendMultiWrite.php
+++ b/includes/filebackend/FileBackendMultiWrite.php
@@ -121,7 +121,7 @@
                        unset( $config['readOnly'] ); // use proxy backend 
setting
                        unset( $config['fileJournal'] ); // use proxy backend 
journal
                        unset( $config['lockManager'] ); // lock under proxy 
backend
-                       $config['wikiId'] = $this->wikiId; // use the proxy 
backend wiki ID
+                       $config['wikiId'] = $this->domainId; // use the proxy 
backend wiki ID
                        if ( !empty( $config['isMultiMaster'] ) ) {
                                if ( $this->masterIndex >= 0 ) {
                                        throw new FileBackendError( 'More than 
one master backend defined.' );
diff --git a/includes/filebackend/FileBackendStore.php 
b/includes/filebackend/FileBackendStore.php
index 4e25ce7..44966bb 100644
--- a/includes/filebackend/FileBackendStore.php
+++ b/includes/filebackend/FileBackendStore.php
@@ -116,7 +116,7 @@
         * @return StatusValue
         */
        final public function createInternal( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                if ( strlen( $params['content'] ) > 
$this->maxFileSizeInternal() ) {
                        $status = $this->newStatus( 'backend-fail-maxsize',
                                $params['dst'], $this->maxFileSizeInternal() );
@@ -157,7 +157,7 @@
         * @return StatusValue
         */
        final public function storeInternal( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                if ( filesize( $params['src'] ) > $this->maxFileSizeInternal() 
) {
                        $status = $this->newStatus( 'backend-fail-maxsize',
                                $params['dst'], $this->maxFileSizeInternal() );
@@ -199,7 +199,7 @@
         * @return StatusValue
         */
        final public function copyInternal( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->doCopyInternal( $params );
                $this->clearCache( [ $params['dst'] ] );
                if ( !isset( $params['dstExists'] ) || $params['dstExists'] ) {
@@ -231,7 +231,7 @@
         * @return StatusValue
         */
        final public function deleteInternal( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->doDeleteInternal( $params );
                $this->clearCache( [ $params['src'] ] );
                $this->deleteFileCache( $params['src'] ); // persistent cache
@@ -265,7 +265,7 @@
         * @return StatusValue
         */
        final public function moveInternal( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->doMoveInternal( $params );
                $this->clearCache( [ $params['src'], $params['dst'] ] );
                $this->deleteFileCache( $params['src'] ); // persistent cache
@@ -311,7 +311,7 @@
         * @return StatusValue
         */
        final public function describeInternal( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                if ( count( $params['headers'] ) ) {
                        $status = $this->doDescribeInternal( $params );
                        $this->clearCache( [ $params['src'] ] );
@@ -344,7 +344,7 @@
        }
 
        final public function concatenate( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->newStatus();
 
                // Try to lock the source files for the scope of this function
@@ -355,7 +355,7 @@
                        $status->merge( $this->doConcatenate( $params ) );
                        $sec = microtime( true ) - $start_time;
                        if ( !$status->isOK() ) {
-                               wfDebugLog( 'FileOperation', get_class( $this ) 
. "-{$this->name}" .
+                               $this->logger->error( get_class( $this ) . 
"-{$this->name}" .
                                        " failed to concatenate " . count( 
$params['srcs'] ) . " file(s) [$sec sec]" );
                        }
                }
@@ -437,7 +437,7 @@
        }
 
        final protected function doPrepare( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->newStatus();
 
                list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( 
$params['dir'] );
@@ -450,7 +450,7 @@
                if ( $shard !== null ) { // confined to a single container/shard
                        $status->merge( $this->doPrepareInternal( $fullCont, 
$dir, $params ) );
                } else { // directory is on several shards
-                       wfDebug( __METHOD__ . ": iterating over all container 
shards.\n" );
+                       $this->logger->debug( __METHOD__ . ": iterating over 
all container shards.\n" );
                        list( , $shortCont, ) = self::splitStoragePath( 
$params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as 
$suffix ) {
                                $status->merge( $this->doPrepareInternal( 
"{$fullCont}{$suffix}", $dir, $params ) );
@@ -472,7 +472,7 @@
        }
 
        final protected function doSecure( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->newStatus();
 
                list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( 
$params['dir'] );
@@ -485,7 +485,7 @@
                if ( $shard !== null ) { // confined to a single container/shard
                        $status->merge( $this->doSecureInternal( $fullCont, 
$dir, $params ) );
                } else { // directory is on several shards
-                       wfDebug( __METHOD__ . ": iterating over all container 
shards.\n" );
+                       $this->logger->debug( __METHOD__ . ": iterating over 
all container shards.\n" );
                        list( , $shortCont, ) = self::splitStoragePath( 
$params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as 
$suffix ) {
                                $status->merge( $this->doSecureInternal( 
"{$fullCont}{$suffix}", $dir, $params ) );
@@ -507,7 +507,7 @@
        }
 
        final protected function doPublish( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->newStatus();
 
                list( $fullCont, $dir, $shard ) = $this->resolveStoragePath( 
$params['dir'] );
@@ -520,7 +520,7 @@
                if ( $shard !== null ) { // confined to a single container/shard
                        $status->merge( $this->doPublishInternal( $fullCont, 
$dir, $params ) );
                } else { // directory is on several shards
-                       wfDebug( __METHOD__ . ": iterating over all container 
shards.\n" );
+                       $this->logger->debug( __METHOD__ . ": iterating over 
all container shards.\n" );
                        list( , $shortCont, ) = self::splitStoragePath( 
$params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as 
$suffix ) {
                                $status->merge( $this->doPublishInternal( 
"{$fullCont}{$suffix}", $dir, $params ) );
@@ -542,7 +542,7 @@
        }
 
        final protected function doClean( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->newStatus();
 
                // Recursive: first delete all empty subdirs recursively
@@ -575,7 +575,7 @@
                        $status->merge( $this->doCleanInternal( $fullCont, 
$dir, $params ) );
                        $this->deleteContainerCache( $fullCont ); // purge cache
                } else { // directory is on several shards
-                       wfDebug( __METHOD__ . ": iterating over all container 
shards.\n" );
+                       $this->logger->debug( __METHOD__ . ": iterating over 
all container shards.\n" );
                        list( , $shortCont, ) = self::splitStoragePath( 
$params['dir'] );
                        foreach ( $this->getContainerSuffixes( $shortCont ) as 
$suffix ) {
                                $status->merge( $this->doCleanInternal( 
"{$fullCont}{$suffix}", $dir, $params ) );
@@ -598,21 +598,21 @@
        }
 
        final public function fileExists( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $stat = $this->getFileStat( $params );
 
                return ( $stat === null ) ? null : (bool)$stat; // null => 
failure
        }
 
        final public function getFileTimestamp( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $stat = $this->getFileStat( $params );
 
                return $stat ? $stat['mtime'] : false;
        }
 
        final public function getFileSize( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $stat = $this->getFileStat( $params );
 
                return $stat ? $stat['size'] : false;
@@ -623,7 +623,7 @@
                if ( $path === null ) {
                        return false; // invalid storage path
                }
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $latest = !empty( $params['latest'] ); // use latest data?
                if ( !$latest && !$this->cheapCache->has( $path, 'stat', 
self::CACHE_TTL ) ) {
                        $this->primeFileCache( [ $path ] ); // check persistent 
cache
@@ -661,9 +661,9 @@
                        $this->cheapCache->set( $path, 'stat', $latest ? 
'NOT_EXIST_LATEST' : 'NOT_EXIST' );
                        $this->cheapCache->set( $path, 'xattr', [ 'map' => 
false, 'latest' => $latest ] );
                        $this->cheapCache->set( $path, 'sha1', [ 'hash' => 
false, 'latest' => $latest ] );
-                       wfDebug( __METHOD__ . ": File $path does not exist.\n" 
);
+                       $this->logger->debug( __METHOD__ . ": File $path does 
not exist.\n" );
                } else { // an error occurred
-                       wfDebug( __METHOD__ . ": Could not stat file $path.\n" 
);
+                       $this->logger->warning( __METHOD__ . ": Could not stat 
file $path.\n" );
                }
 
                return $stat;
@@ -675,7 +675,7 @@
        abstract protected function doGetFileStat( array $params );
 
        public function getFileContentsMulti( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                $params = $this->setConcurrencyFlags( $params );
                $contents = $this->doGetFileContentsMulti( $params );
@@ -704,7 +704,7 @@
                if ( $path === null ) {
                        return false; // invalid storage path
                }
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $latest = !empty( $params['latest'] ); // use latest data?
                if ( $this->cheapCache->has( $path, 'xattr', self::CACHE_TTL ) 
) {
                        $stat = $this->cheapCache->get( $path, 'xattr' );
@@ -734,7 +734,7 @@
                if ( $path === null ) {
                        return false; // invalid storage path
                }
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $latest = !empty( $params['latest'] ); // use latest data?
                if ( $this->cheapCache->has( $path, 'sha1', self::CACHE_TTL ) ) 
{
                        $stat = $this->cheapCache->get( $path, 'sha1' );
@@ -765,7 +765,7 @@
        }
 
        final public function getFileProps( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $fsFile = $this->getLocalReference( $params );
                $props = $fsFile ? $fsFile->getProps() : 
FSFile::placeholderProps();
 
@@ -773,7 +773,7 @@
        }
 
        final public function getLocalReferenceMulti( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                $params = $this->setConcurrencyFlags( $params );
 
@@ -816,7 +816,7 @@
        }
 
        final public function getLocalCopyMulti( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                $params = $this->setConcurrencyFlags( $params );
                $tmpFiles = $this->doGetLocalCopyMulti( $params );
@@ -841,7 +841,7 @@
        }
 
        final public function streamFile( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->newStatus();
 
                // Always set some fields for subclass convenience
@@ -897,7 +897,7 @@
                if ( $shard !== null ) { // confined to a single container/shard
                        return $this->doDirectoryExists( $fullCont, $dir, 
$params );
                } else { // directory is on several shards
-                       wfDebug( __METHOD__ . ": iterating over all container 
shards.\n" );
+                       $this->logger->debug( __METHOD__ . ": iterating over 
all container shards.\n" );
                        list( , $shortCont, ) = self::splitStoragePath( 
$params['dir'] );
                        $res = false; // response
                        foreach ( $this->getContainerSuffixes( $shortCont ) as 
$suffix ) {
@@ -933,7 +933,7 @@
                        // File listing is confined to a single container/shard
                        return $this->getDirectoryListInternal( $fullCont, 
$dir, $params );
                } else {
-                       wfDebug( __METHOD__ . ": iterating over all container 
shards.\n" );
+                       $this->logger->debug( __METHOD__ . ": iterating over 
all container shards.\n" );
                        // File listing spans multiple containers/shards
                        list( , $shortCont, ) = self::splitStoragePath( 
$params['dir'] );
 
@@ -963,7 +963,7 @@
                        // File listing is confined to a single container/shard
                        return $this->getFileListInternal( $fullCont, $dir, 
$params );
                } else {
-                       wfDebug( __METHOD__ . ": iterating over all container 
shards.\n" );
+                       $this->logger->debug( __METHOD__ . ": iterating over 
all container shards.\n" );
                        // File listing spans multiple containers/shards
                        list( , $shortCont, ) = self::splitStoragePath( 
$params['dir'] );
 
@@ -1059,7 +1059,7 @@
        }
 
        final protected function doOperationsInternal( array $ops, array $opts 
) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->newStatus();
 
                // Fix up custom header name/value pairs...
@@ -1111,7 +1111,7 @@
                                $subStatus->success[$i] = false;
                                ++$subStatus->failCount;
                        }
-                       wfDebugLog( 'FileOperation', get_class( $this ) . 
"-{$this->name} " .
+                       $this->logger->error( 'FileOperation', get_class( $this 
) . "-{$this->name} " .
                                " stat failure; aborted operations: " . 
FormatJson::encode( $ops ) );
                }
 
@@ -1126,7 +1126,7 @@
        }
 
        final protected function doQuickOperationsInternal( array $ops ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $status = $this->newStatus();
 
                // Fix up custom header name/value pairs...
@@ -1193,7 +1193,7 @@
         * @return StatusValue[] Map of StatusValue objects
         */
        final public function executeOpHandlesInternal( array $fileOpHandles ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                foreach ( $fileOpHandles as $fileOpHandle ) {
                        if ( !( $fileOpHandle instanceof 
FileBackendStoreOpHandle ) ) {
@@ -1296,7 +1296,7 @@
        }
 
        final public function preloadFileStat( array $params ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
                $success = true; // no network errors
 
                $params['concurrency'] = ( $this->parallelize !== 'off' ) ? 
$this->concurrency : 1;
@@ -1332,10 +1332,10 @@
                                        [ 'map' => false, 'latest' => $latest ] 
);
                                $this->cheapCache->set( $path, 'sha1',
                                        [ 'hash' => false, 'latest' => $latest 
] );
-                               wfDebug( __METHOD__ . ": File $path does not 
exist.\n" );
+                               $this->logger->debug( __METHOD__ . ": File 
$path does not exist.\n" );
                        } else { // an error occurred
                                $success = false;
-                               wfDebug( __METHOD__ . ": Could not stat file 
$path.\n" );
+                               $this->logger->warning( __METHOD__ . ": Could 
not stat file $path.\n" );
                        }
                }
 
@@ -1565,8 +1565,8 @@
         * @return string
         */
        final protected function fullContainerName( $container ) {
-               if ( $this->wikiId != '' ) {
-                       return "{$this->wikiId}-$container";
+               if ( $this->domainId != '' ) {
+                       return "{$this->domainId}-$container";
                } else {
                        return $container;
                }
@@ -1605,7 +1605,7 @@
         * @return string
         */
        private function containerCacheKey( $container ) {
-               return 
"filebackend:{$this->name}:{$this->wikiId}:container:{$container}";
+               return 
"filebackend:{$this->name}:{$this->domainId}:container:{$container}";
        }
 
        /**
@@ -1638,7 +1638,7 @@
         * @param array $items
         */
        final protected function primeContainerCache( array $items ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                $paths = []; // list of storage paths
                $contNames = []; // (cache key => resolved container name)
@@ -1686,7 +1686,7 @@
         * @return string
         */
        private function fileCacheKey( $path ) {
-               return "filebackend:{$this->name}:{$this->wikiId}:file:" . 
sha1( $path );
+               return "filebackend:{$this->name}:{$this->domainId}:file:" . 
sha1( $path );
        }
 
        /**
@@ -1702,7 +1702,12 @@
                if ( $path === null ) {
                        return; // invalid storage path
                }
-               $mtime = wfTimestamp( TS_UNIX, $val['mtime'] );
+               try {
+                       $ct = new ConvertableTimestamp( $val['mtime'] );
+                       $mtime = $ct->getTimestamp( TS_UNIX );
+               } catch ( TimestampException $e ) {
+                       $mtime = false;
+               }
                $ttl = $this->memCache->adaptiveTTL( $mtime, 7 * 86400, 300, .1 
);
                $key = $this->fileCacheKey( $path );
                // Set the cache unless it is currently salted.
@@ -1735,7 +1740,7 @@
         * @param array $items List of storage paths
         */
        final protected function primeFileCache( array $items ) {
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                $paths = []; // list of storage paths
                $pathNames = []; // (cache key => storage path)
diff --git a/includes/filebackend/FileOpBatch.php 
b/includes/filebackend/FileOpBatch.php
index e34ad8c..71b5c7d 100644
--- a/includes/filebackend/FileOpBatch.php
+++ b/includes/filebackend/FileOpBatch.php
@@ -164,6 +164,7 @@
                        $statuses = [];
                        $opHandles = [];
                        // Get the backend; all sub-batch ops belong to a 
single backend
+                       /** @var FileBackendStore $backend */
                        $backend = reset( $performOpsBatch )->getBackend();
                        // Get the operation handles or actually do it if there 
is just one.
                        // If attemptAsync() returns a StatusValue, it was 
either due to an error
diff --git a/includes/libs/filebackend/FileBackend.php 
b/includes/libs/filebackend/FileBackend.php
index 4ff342f..ca7b2a3 100644
--- a/includes/libs/filebackend/FileBackend.php
+++ b/includes/libs/filebackend/FileBackend.php
@@ -28,6 +28,8 @@
  * @ingroup FileBackend
  * @author Aaron Schulz
  */
+use Psr\Log\LoggerAwareInterface;
+use Psr\Log\LoggerInterface;
 
 /**
  * @brief Base class for all file backend classes (including multi-write 
backends).
@@ -82,12 +84,12 @@
  * @ingroup FileBackend
  * @since 1.19
  */
-abstract class FileBackend {
+abstract class FileBackend implements LoggerAwareInterface {
        /** @var string Unique backend name */
        protected $name;
 
        /** @var string Unique wiki name */
-       protected $wikiId;
+       protected $domainId;
 
        /** @var string Read-only explanation message */
        protected $readOnly;
@@ -100,9 +102,12 @@
 
        /** @var LockManager */
        protected $lockManager;
-
        /** @var FileJournal */
        protected $fileJournal;
+       /** @var LoggerInterface */
+       protected $logger;
+       /** @var object|string Class name or object With profileIn/profileOut 
methods */
+       protected $profiler;
 
        /** @var callable */
        protected $statusWrapper;
@@ -134,14 +139,18 @@
         *   - parallelize : When to do file operations in parallel (when 
possible).
         *                   Allowed values are "implicit", "explicit" and 
"off".
         *   - concurrency : How many file operations can be done in parallel.
+        *   - logger      : Optional PSR logger object.
+        *   - profiler    : Optional class name or object With 
profileIn/profileOut methods.
         * @throws FileBackendException
         */
        public function __construct( array $config ) {
                $this->name = $config['name'];
-               $this->wikiId = $config['wikiId']; // e.g. "my_wiki-en_"
+               $this->domainId = isset( $config['domainId'] )
+                       ? $config['domainId'] // e.g. "my_wiki-en_"
+                       : $config['wikiId']; // b/c alias
                if ( !preg_match( '!^[a-zA-Z0-9-_]{1,255}$!', $this->name ) ) {
                        throw new FileBackendException( "Backend name 
'{$this->name}' is invalid." );
-               } elseif ( !is_string( $this->wikiId ) ) {
+               } elseif ( !is_string( $this->domainId ) ) {
                        throw new FileBackendException( "Backend wiki ID not 
provided for '{$this->name}'." );
                }
                $this->lockManager = isset( $config['lockManager'] )
@@ -159,7 +168,13 @@
                $this->concurrency = isset( $config['concurrency'] )
                        ? (int)$config['concurrency']
                        : 50;
+               $this->profiler = isset( $params['profiler'] ) ? 
$params['profiler'] : null;
+               $this->logger = isset( $config['logger'] ) ? $config['logger'] 
: new \Psr\Log\NullLogger();
                $this->statusWrapper = isset( $config['statusWrapper'] ) ? 
$config['statusWrapper'] : null;
+       }
+
+       public function setLogger( LoggerInterface $logger ) {
+               $this->logger = $logger;
        }
 
        /**
@@ -174,14 +189,25 @@
        }
 
        /**
-        * Get the wiki identifier used for this backend (possibly empty).
+        * Get the domain identifier used for this backend (possibly empty).
+        *
+        * @return string
+        * @since 1.28
+        */
+       final public function getDomainId() {
+               return $this->domainId;
+       }
+
+       /**
+        * Alias to getDomainId()
+        *
         * Note that this might *not* be in the same format as wfWikiID().
         *
         * @return string
         * @since 1.20
         */
        final public function getWikiId() {
-               return $this->wikiId;
+               return $this->getDomainId();
        }
 
        /**
@@ -1563,4 +1589,17 @@
        final protected function wrapStatus( StatusValue $sv ) {
                return $this->statusWrapper ? call_user_func( 
$this->statusWrapper, $sv ) : $sv;
        }
+
+       /**
+        * @param string $section
+        * @return ScopedCallback|null
+        */
+       protected function scopedProfileSection( $section ) {
+               if ( $this->profiler ) {
+                       call_user_func( [ $this->profiler, 'profileIn' ], 
$section );
+                       return new ScopedCallback( [ $this->profiler, 
'profileOut' ] );
+               }
+
+               return null;
+       }
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/311353
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e3a43d36506bec341dc5727b52f5f5a5d32bff5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to