Merge "Add .gitignore to the /skins directory"
[lhc/web/wiklou.git] / includes / filebackend / lockmanager / RedisLockManager.php
index e8e5996..9d5612a 100644 (file)
@@ -38,7 +38,7 @@
  * @since 1.22
  */
 class RedisLockManager extends QuorumLockManager {
-       /** @var Array Mapping of lock types to the type actually used */
+       /** @var array Mapping of lock types to the type actually used */
        protected $lockTypeMap = array(
                self::LOCK_SH => self::LOCK_SH,
                self::LOCK_UW => self::LOCK_SH,
@@ -47,21 +47,21 @@ class RedisLockManager extends QuorumLockManager {
 
        /** @var RedisConnectionPool */
        protected $redisPool;
-       /** @var Array Map server names to hostname/IP and port numbers */
+
+       /** @var array Map server names to hostname/IP and port numbers */
        protected $lockServers = array();
 
-       protected $session = ''; // string; random UUID
+       /** @var string random UUID */
+       protected $session = '';
 
        /**
         * Construct a new instance from configuration.
         *
-        * $config paramaters include:
+        * @param array $config Parameters include:
         *   - lockServers  : Associative array of server names to "<IP>:<port>" strings.
         *   - srvsByBucket : Array of 1-16 consecutive integer keys, starting from 0,
         *                    each having an odd-numbered list of server names (peers) as values.
         *   - redisConfig  : Configuration for RedisConnectionPool::__construct().
-        *
-        * @param Array $config
         * @throws MWException
         */
        public function __construct( array $config ) {
@@ -78,7 +78,40 @@ class RedisLockManager extends QuorumLockManager {
                $this->session = wfRandomString( 32 );
        }
 
-       protected function getLocksOnServer( $lockSrv, array $paths, $type ) {
+       // @TODO: change this code to work in one batch
+       protected function getLocksOnServer( $lockSrv, array $pathsByType ) {
+               $status = Status::newGood();
+
+               $lockedPaths = array();
+               foreach ( $pathsByType as $type => $paths ) {
+                       $status->merge( $this->doGetLocksOnServer( $lockSrv, $paths, $type ) );
+                       if ( $status->isOK() ) {
+                               $lockedPaths[$type] = isset( $lockedPaths[$type] )
+                                       ? array_merge( $lockedPaths[$type], $paths )
+                                       : $paths;
+                       } else {
+                               foreach ( $lockedPaths as $lType => $lPaths ) {
+                                       $status->merge( $this->doFreeLocksOnServer( $lockSrv, $lPaths, $lType ) );
+                               }
+                               break;
+                       }
+               }
+
+               return $status;
+       }
+
+       // @todo Change this code to work in one batch
+       protected function freeLocksOnServer( $lockSrv, array $pathsByType ) {
+               $status = Status::newGood();
+
+               foreach ( $pathsByType as $type => $paths ) {
+                       $status->merge( $this->doFreeLocksOnServer( $lockSrv, $paths, $type ) );
+               }
+
+               return $status;
+       }
+
+       protected function doGetLocksOnServer( $lockSrv, array $paths, $type ) {
                $status = Status::newGood();
 
                $server = $this->lockServers[$lockSrv];
@@ -87,6 +120,7 @@ class RedisLockManager extends QuorumLockManager {
                        foreach ( $paths as $path ) {
                                $status->fatal( 'lockmanager-fail-acquirelock', $path );
                        }
+
                        return $status;
                }
 
@@ -162,7 +196,7 @@ LUA;
                return $status;
        }
 
-       protected function freeLocksOnServer( $lockSrv, array $paths, $type ) {
+       protected function doFreeLocksOnServer( $lockSrv, array $paths, $type ) {
                $status = Status::newGood();
 
                $server = $this->lockServers[$lockSrv];
@@ -171,6 +205,7 @@ LUA;
                        foreach ( $paths as $path ) {
                                $status->fatal( 'lockmanager-fail-releaselock', $path );
                        }
+
                        return $status;
                }
 
@@ -234,7 +269,7 @@ LUA;
        }
 
        /**
-        * @param $path string
+        * @param string $path
         * @return string
         */
        protected function recordKeyForPath( $path ) {