Merge "Removed old "noPush" config hacks from FileBackendMultiWrite"
[lhc/web/wiklou.git] / includes / filebackend / FileBackendMultiWrite.php
index f2d13ee..10e5a1e 100644 (file)
  * Only use this class when transitioning from one storage system to another.
  *
  * Read operations are only done on the 'master' backend for consistency.
- * Write operations are performed on all backends, in the order defined.
- * If an operation fails on one backend it will be rolled back from the others.
+ * Write operations are performed on all backends, starting with the master.
+ * This makes a best-effort to have transactional semantics, but since requests
+ * may sometimes fail, the use of "autoResync" or background scripts to fix
+ * inconsistencies is important.
  *
  * @ingroup FileBackend
  * @since 1.19
  */
 class FileBackendMultiWrite extends FileBackend {
-       /** @var array Prioritized list of FileBackendStore objects.
-        * array of (backend index => backends)
-        */
+       /** @var FileBackendStore[] Prioritized list of FileBackendStore objects */
        protected $backends = array();
 
        /** @var int Index of master backend */
@@ -54,12 +54,6 @@ class FileBackendMultiWrite extends FileBackend {
        /** @var string|bool */
        protected $autoResync = false;
 
-       /** @var array */
-       protected $noPushDirConts = array();
-
-       /** @var bool */
-       protected $noPushQuickOps = false;
-
        /* Possible internal backend consistency checks */
        const CHECK_SIZE = 1;
        const CHECK_TIME = 2;
@@ -88,8 +82,6 @@ class FileBackendMultiWrite extends FileBackend {
         *                      Use "conservative" to limit resyncing to copying newer master
         *                      backend files over older (or non-existing) clone backend files.
         *                      Cases that cannot be handled will result in operation abortion.
-        *   - noPushQuickOps : (hack) Only apply doQuickOperations() to the master backend.
-        *   - noPushDirConts : (hack) Only apply directory functions to the master backend.
         *
         * @param array $config
         * @throws FileBackendError
@@ -102,12 +94,6 @@ class FileBackendMultiWrite extends FileBackend {
                $this->autoResync = isset( $config['autoResync'] )
                        ? $config['autoResync']
                        : false;
-               $this->noPushQuickOps = isset( $config['noPushQuickOps'] )
-                       ? $config['noPushQuickOps']
-                       : false;
-               $this->noPushDirConts = isset( $config['noPushDirConts'] )
-                       ? $config['noPushDirConts']
-                       : array();
                // Construct backends here rather than via registration
                // to keep these backends hidden from outside the proxy.
                $namesUsed = array();
@@ -154,6 +140,7 @@ class FileBackendMultiWrite extends FileBackend {
                // Try to lock those files for the scope of this function...
                if ( empty( $opts['nonLocking'] ) ) {
                        // Try to lock those files for the scope of this function...
+                       /** @noinspection PhpUnusedLocalVariableInspection */
                        $scopeLock = $this->getScopedLocksForOps( $ops, $status );
                        if ( !$status->isOK() ) {
                                return $status; // abort
@@ -328,8 +315,8 @@ class FileBackendMultiWrite extends FileBackend {
                                $cStat = $cBackend->getFileStat( array( 'src' => $cPath, 'latest' => true ) );
                                if ( $cStat === null || ( $cSha1 !== false && !$cStat ) ) { // sanity
                                        $status->fatal( 'backend-fail-internal', $cBackend->getName() );
-                                       wfDebugLog( 'FileOperation', __METHOD__
-                                       . ': File is not available on the clone backend' );
+                                       wfDebugLog( 'FileOperation', __METHOD__ .
+                                               ': File is not available on the clone backend' );
                                        continue; // file is not available on the clone backend...
                                }
                                if ( $mSha1 === $cSha1 ) {
@@ -433,7 +420,7 @@ class FileBackendMultiWrite extends FileBackend {
         */
        protected function substPaths( $paths, FileBackendStore $backend ) {
                return preg_replace(
-                       '!^mwstore://' . preg_quote( $this->name ) . '/!',
+                       '!^mwstore://' . preg_quote( $this->name, '!' ) . '/!',
                        StringUtils::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ),
                        $paths // string or array
                );
@@ -460,12 +447,10 @@ class FileBackendMultiWrite extends FileBackend {
                $masterStatus = $this->backends[$this->masterIndex]->doQuickOperations( $realOps );
                $status->merge( $masterStatus );
                // Propagate the operations to the clone backends...
-               if ( !$this->noPushQuickOps ) {
-                       foreach ( $this->backends as $index => $backend ) {
-                               if ( $index !== $this->masterIndex ) { // not done already
-                                       $realOps = $this->substOpBatchPaths( $ops, $backend );
-                                       $status->merge( $backend->doQuickOperations( $realOps ) );
-                               }
+               foreach ( $this->backends as $index => $backend ) {
+                       if ( $index !== $this->masterIndex ) { // not done already
+                               $realOps = $this->substOpBatchPaths( $ops, $backend );
+                               $status->merge( $backend->doQuickOperations( $realOps ) );
                        }
                }
                // Make 'success', 'successCount', and 'failCount' fields reflect
@@ -478,24 +463,11 @@ class FileBackendMultiWrite extends FileBackend {
                return $status;
        }
 
-       /**
-        * @param string $path Storage path
-        * @return bool Path container should have dir changes pushed to all backends
-        */
-       protected function replicateContainerDirChanges( $path ) {
-               list( , $shortCont, ) = self::splitStoragePath( $path );
-
-               return !in_array( $shortCont, $this->noPushDirConts );
-       }
-
        protected function doPrepare( array $params ) {
                $status = Status::newGood();
-               $replicate = $this->replicateContainerDirChanges( $params['dir'] );
                foreach ( $this->backends as $index => $backend ) {
-                       if ( $replicate || $index == $this->masterIndex ) {
-                               $realParams = $this->substOpPaths( $params, $backend );
-                               $status->merge( $backend->doPrepare( $realParams ) );
-                       }
+                       $realParams = $this->substOpPaths( $params, $backend );
+                       $status->merge( $backend->doPrepare( $realParams ) );
                }
 
                return $status;
@@ -503,12 +475,9 @@ class FileBackendMultiWrite extends FileBackend {
 
        protected function doSecure( array $params ) {
                $status = Status::newGood();
-               $replicate = $this->replicateContainerDirChanges( $params['dir'] );
                foreach ( $this->backends as $index => $backend ) {
-                       if ( $replicate || $index == $this->masterIndex ) {
-                               $realParams = $this->substOpPaths( $params, $backend );
-                               $status->merge( $backend->doSecure( $realParams ) );
-                       }
+                       $realParams = $this->substOpPaths( $params, $backend );
+                       $status->merge( $backend->doSecure( $realParams ) );
                }
 
                return $status;
@@ -516,12 +485,9 @@ class FileBackendMultiWrite extends FileBackend {
 
        protected function doPublish( array $params ) {
                $status = Status::newGood();
-               $replicate = $this->replicateContainerDirChanges( $params['dir'] );
                foreach ( $this->backends as $index => $backend ) {
-                       if ( $replicate || $index == $this->masterIndex ) {
-                               $realParams = $this->substOpPaths( $params, $backend );
-                               $status->merge( $backend->doPublish( $realParams ) );
-                       }
+                       $realParams = $this->substOpPaths( $params, $backend );
+                       $status->merge( $backend->doPublish( $realParams ) );
                }
 
                return $status;
@@ -529,12 +495,9 @@ class FileBackendMultiWrite extends FileBackend {
 
        protected function doClean( array $params ) {
                $status = Status::newGood();
-               $replicate = $this->replicateContainerDirChanges( $params['dir'] );
                foreach ( $this->backends as $index => $backend ) {
-                       if ( $replicate || $index == $this->masterIndex ) {
-                               $realParams = $this->substOpPaths( $params, $backend );
-                               $status->merge( $backend->doClean( $realParams ) );
-                       }
+                       $realParams = $this->substOpPaths( $params, $backend );
+                       $status->merge( $backend->doClean( $realParams ) );
                }
 
                return $status;
@@ -688,6 +651,6 @@ class FileBackendMultiWrite extends FileBackend {
                );
 
                // Actually acquire the locks
-               return array( $this->getScopedFileLocks( $pbPaths, 'mixed', $status ) );
+               return $this->getScopedFileLocks( $pbPaths, 'mixed', $status );
        }
 }