Aaron Schulz has uploaded a new change for review.

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

Change subject: Depedencency cleanups to SwiftFileBackend
......................................................................

Depedencency cleanups to SwiftFileBackend

Change-Id: I359da1ad77c62880ea799b65cd3a16ad673a64eb
---
M includes/filebackend/FileBackendGroup.php
M includes/filebackend/SwiftFileBackend.php
M includes/libs/filebackend/FileBackend.php
M includes/libs/filebackend/FileBackendStore.php
4 files changed, 43 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/35/312135/1

diff --git a/includes/filebackend/FileBackendGroup.php 
b/includes/filebackend/FileBackendGroup.php
index db28d6e..da6bd6c 100644
--- a/includes/filebackend/FileBackendGroup.php
+++ b/includes/filebackend/FileBackendGroup.php
@@ -168,6 +168,7 @@
                                ? FileJournal::factory( $config['fileJournal'], 
$name )
                                : FileJournal::factory( [ 'class' => 
'NullFileJournal' ], $name );
                        $config['wanCache'] = ObjectCache::getMainWANInstance();
+                       $config['srvCache'] = 
ObjectCache::getLocalServerInstance( 'hash' );
                        $config['statusWrapper'] = [ 'Status', 'wrap' ];
                        $config['logger'] = LoggerFactory::getInstance( 
'FileOperation' );
                        $config['profiler'] = Profiler::instance();
diff --git a/includes/filebackend/SwiftFileBackend.php 
b/includes/filebackend/SwiftFileBackend.php
index a0027e4..def24e2 100644
--- a/includes/filebackend/SwiftFileBackend.php
+++ b/includes/filebackend/SwiftFileBackend.php
@@ -134,14 +134,8 @@
                // Process cache for container info
                $this->containerStatCache = new ProcessCacheLRU( 300 );
                // Cache auth token information to avoid RTTs
-               if ( !empty( $config['cacheAuthInfo'] ) ) {
-                       if ( PHP_SAPI === 'cli' ) {
-                               // Preferrably memcached
-                               $this->srvCache = 
ObjectCache::getLocalClusterInstance();
-                       } else {
-                               // Look for APC, XCache, WinCache, ect...
-                               $this->srvCache = 
ObjectCache::getLocalServerInstance( CACHE_NONE );
-                       }
+               if ( !empty( $config['cacheAuthInfo'] ) && isset( 
$config['srvCache'] ) ) {
+                       $this->srvCache = $config['srvCache'];
                } else {
                        $this->srvCache = new EmptyBagOStuff();
                }
@@ -576,7 +570,7 @@
                        return $status; // already there
                } elseif ( $stat === null ) {
                        $status->fatal( 'backend-fail-internal', $this->name );
-                       wfDebugLog( 'SwiftBackend', __METHOD__ . ': cannot get 
container stat' );
+                       $this->logger->error( __METHOD__ . ': cannot get 
container stat' );
 
                        return $status;
                }
@@ -608,7 +602,7 @@
                        $status->fatal( 'backend-fail-usable', $params['dir'] );
                } else {
                        $status->fatal( 'backend-fail-internal', $this->name );
-                       wfDebugLog( 'SwiftBackend', __METHOD__ . ': cannot get 
container stat' );
+                       $this->logger->error( __METHOD__ . ': cannot get 
container stat' );
                }
 
                return $status;
@@ -629,7 +623,7 @@
                        $status->fatal( 'backend-fail-usable', $params['dir'] );
                } else {
                        $status->fatal( 'backend-fail-internal', $this->name );
-                       wfDebugLog( 'SwiftBackend', __METHOD__ . ': cannot get 
container stat' );
+                       $this->logger->error( __METHOD__ . ': cannot get 
container stat' );
                }
 
                return $status;
@@ -649,7 +643,7 @@
                        return $status; // ok, nothing to do
                } elseif ( !is_array( $stat ) ) {
                        $status->fatal( 'backend-fail-internal', $this->name );
-                       wfDebugLog( 'SwiftBackend', __METHOD__ . ': cannot get 
container stat' );
+                       $this->logger->error( __METHOD__ . ': cannot get 
container stat' );
 
                        return $status;
                }
@@ -704,8 +698,8 @@
                }
 
                /** @noinspection PhpUnusedLocalVariableInspection */
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
-               wfDebugLog( 'SwiftBackend', __METHOD__ . ": $path was not 
stored with SHA-1 metadata." );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
+               $this->logger->error( __METHOD__ . ": $path was not stored with 
SHA-1 metadata." );
 
                $objHdrs['x-object-meta-sha1base36'] = false;
 
@@ -745,7 +739,7 @@
                        }
                }
 
-               wfDebugLog( 'SwiftBackend', __METHOD__ . ": unable to set SHA-1 
metadata for $path" );
+               $this->logger->error( __METHOD__ . ": unable to set SHA-1 
metadata for $path" );
 
                return $objHdrs; // failed
        }
@@ -848,14 +842,14 @@
                        return $dirs; // nothing more
                }
 
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                $prefix = ( $dir == '' ) ? null : "{$dir}/";
                // Non-recursive: only list dirs right under $dir
                if ( !empty( $params['topOnly'] ) ) {
                        $status = $this->objectListing( $fullCont, 'names', 
$limit, $after, $prefix, '/' );
                        if ( !$status->isOK() ) {
-                               throw new FileBackendError( "Iterator page I/O 
error: {$status->getMessage()}" );
+                               throw new FileBackendError( "Iterator page I/O 
error." );
                        }
                        $objects = $status->value;
                        foreach ( $objects as $object ) { // files and 
directories
@@ -874,7 +868,7 @@
                        $status = $this->objectListing( $fullCont, 'names', 
$limit, $after, $prefix );
 
                        if ( !$status->isOK() ) {
-                               throw new FileBackendError( "Iterator page I/O 
error: {$status->getMessage()}" );
+                               throw new FileBackendError( "Iterator page I/O 
error." );
                        }
 
                        $objects = $status->value;
@@ -928,7 +922,7 @@
                        return $files; // nothing more
                }
 
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                $prefix = ( $dir == '' ) ? null : "{$dir}/";
                // $objects will contain a list of unfiltered names or 
CF_Object items
@@ -950,7 +944,7 @@
 
                // Reformat this list into a list of (name, stat array or null) 
entries
                if ( !$status->isOK() ) {
-                       throw new FileBackendError( "Iterator page I/O error: 
{$status->getMessage()}" );
+                       throw new FileBackendError( "Iterator page I/O error." 
);
                }
 
                $objects = $status->value;
@@ -1079,7 +1073,7 @@
 
                if ( empty( $params['allowOB'] ) ) {
                        // Cancel output buffering and gzipping if set
-                       wfResetOutputBuffers();
+                       call_user_func( $this->obResetFunc );
                }
 
                $handle = fopen( 'php://output', 'wb' );
@@ -1109,6 +1103,7 @@
        }
 
        protected function doGetLocalCopyMulti( array $params ) {
+               /** @var TempFSFile[] $tmpFiles */
                $tmpFiles = [];
 
                $auth = $this->getAuthentication();
@@ -1216,14 +1211,14 @@
                                ) );
                                // See 
http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html.
                                // Note: adding a newline for empty 
CanonicalizedAmzHeaders does not work.
-                               return wfAppendQuery(
-                                       str_replace( '/swift/v1', '', // S3 API 
is the rgw default
-                                               $this->storageUrl( $auth ) . 
$spath ),
-                                       [
+                               // Note: S3 API is the rgw default; remove the 
/swift/ URL bit.
+                               return str_replace( '/swift/v1', '', 
$this->storageUrl( $auth ) . $spath ) .
+                                       '?' .
+                                       http_build_query( [
                                                'Signature' => $signature,
                                                'Expires' => $expires,
-                                               'AWSAccessKeyId' => 
$this->rgwS3AccessKey ]
-                               );
+                                               'AWSAccessKeyId' => 
$this->rgwS3AccessKey
+                                       ] );
                        }
                }
 
@@ -1257,6 +1252,7 @@
         * @return StatusValue[]
         */
        protected function doExecuteOpHandlesInternal( array $fileOpHandles ) {
+               /** @var $statuses StatusValue[] */
                $statuses = [];
 
                $auth = $this->getAuthentication();
@@ -1271,6 +1267,7 @@
                // Split the HTTP requests into stages that can be done 
concurrently
                $httpReqsByStage = []; // map of (stage => index => HTTP 
request)
                foreach ( $fileOpHandles as $index => $fileOpHandle ) {
+                       /** @var SwiftFileOpHandle $fileOpHandle */
                        $reqs = $fileOpHandle->httpOp;
                        // Convert the 'url' parameter to an actual URL using 
$auth
                        foreach ( $reqs as $stage => &$req ) {
@@ -1348,7 +1345,7 @@
 
                if ( $rcode != 204 && $rcode !== 202 ) {
                        $status->fatal( 'backend-fail-internal', $this->name );
-                       wfDebugLog( 'SwiftBackend', __METHOD__ . ': unexpected 
rcode value (' . $rcode . ')' );
+                       $this->logger->error( __METHOD__ . ': unexpected rcode 
value (' . $rcode . ')' );
                }
 
                return $status;
@@ -1363,7 +1360,7 @@
         * @return array|bool|null False on 404, null on failure
         */
        protected function getContainerStat( $container, $bypassCache = false ) 
{
-               $ps = Profiler::instance()->scopedProfileIn( __METHOD__ . 
"-{$this->name}" );
+               $ps = $this->scopedProfileSection( __METHOD__ . 
"-{$this->name}" );
 
                if ( $bypassCache ) { // purge cache
                        $this->containerStatCache->clear( $container );
@@ -1755,7 +1752,7 @@
                if ( $code == 401 ) { // possibly a stale token
                        $this->srvCache->delete( $this->getCredsCacheKey( 
$this->swiftUser ) );
                }
-               wfDebugLog( 'SwiftBackend',
+               $this->logger->error(
                        "HTTP $code ($desc) in '{$func}' (given '" . 
FormatJson::encode( $params ) . "')" .
                        ( $err ? ": $err" : "" )
                );
diff --git a/includes/libs/filebackend/FileBackend.php 
b/includes/libs/filebackend/FileBackend.php
index 7e26fee..31796a5 100644
--- a/includes/libs/filebackend/FileBackend.php
+++ b/includes/libs/filebackend/FileBackend.php
@@ -174,7 +174,9 @@
                $this->concurrency = isset( $config['concurrency'] )
                        ? (int)$config['concurrency']
                        : 50;
-               $this->obResetFunc = isset( $params['obResetFunc'] ) ? 
$params['obResetFunc'] : null;
+               $this->obResetFunc = isset( $params['obResetFunc'] )
+                       ? $params['obResetFunc']
+                       : [ $this, 'resetOutputBuffer' ];
                $this->streamMimeFunc = isset( $params['streamMimeFunc'] ) ? 
$params['streamMimeFunc'] : null;
                $this->statusWrapper = isset( $config['statusWrapper'] ) ? 
$config['statusWrapper'] : null;
 
@@ -1611,4 +1613,14 @@
 
                return null;
        }
+
+       protected function resetOutputBuffer() {
+               while ( ob_get_status() ) {
+                       if ( !ob_end_clean() ) {
+                               // Could not remove output buffer handler; 
abort now
+                               // to avoid getting in some kind of infinite 
loop.
+                               break;
+                       }
+               }
+       }
 }
diff --git a/includes/libs/filebackend/FileBackendStore.php 
b/includes/libs/filebackend/FileBackendStore.php
index 637d4a8..8870505 100644
--- a/includes/libs/filebackend/FileBackendStore.php
+++ b/includes/libs/filebackend/FileBackendStore.php
@@ -58,6 +58,7 @@
        /**
         * @see FileBackend::__construct()
         * Additional $config params include:
+        *   - srvCache     : BagOStuff cache to APC/XCache or the like.
         *   - wanCache     : WANObjectCache object to use for persistent 
caching.
         *   - mimeCallback : Callback that takes (storage path, content, file 
system path) and
         *                    returns the MIME type of the file or 
'unknown/unknown'. The file
@@ -70,6 +71,7 @@
                $this->mimeCallback = isset( $config['mimeCallback'] )
                        ? $config['mimeCallback']
                        : null;
+               $this->srvCache = new EmptyBagOStuff(); // disabled by default
                $this->memCache = WANObjectCache::newEmpty(); // disabled by 
default
                $this->cheapCache = new ProcessCacheLRU( self::CACHE_CHEAP_SIZE 
);
                $this->expensiveCache = new ProcessCacheLRU( 
self::CACHE_EXPENSIVE_SIZE );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I359da1ad77c62880ea799b65cd3a16ad673a64eb
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