Merge "Reset scoped session for upload jobs after deferred updates"
[lhc/web/wiklou.git] / includes / filebackend / lockmanager / QuorumLockManager.php
index 749e934..108b846 100644 (file)
  * @since 1.20
  */
 abstract class QuorumLockManager extends LockManager {
-       /** @var Array Map of bucket indexes to peer server lists */
-       protected $srvsByBucket = array(); // (bucket index => (lsrv1, lsrv2, ...))
-       /** @var Array Map of degraded buckets */
-       protected $degradedBuckets = array(); // (buckey index => UNIX timestamp)
+       /** @var array Map of bucket indexes to peer server lists */
+       protected $srvsByBucket = []; // (bucket index => (lsrv1, lsrv2, ...))
+
+       /** @var array Map of degraded buckets */
+       protected $degradedBuckets = []; // (buckey index => UNIX timestamp)
 
        final protected function doLock( array $paths, $type ) {
-               return $this->doLockByType( array( $type => $paths ) );
+               return $this->doLockByType( [ $type => $paths ] );
        }
 
        final protected function doUnlock( array $paths, $type ) {
-               return $this->doUnlockByType( array( $type => $paths ) );
+               return $this->doUnlockByType( [ $type => $paths ] );
        }
 
        protected function doLockByType( array $pathsByType ) {
                $status = Status::newGood();
 
-               $pathsToLock = array(); // (bucket => type => paths)
+               $pathsToLock = []; // (bucket => type => paths)
                // Get locks that need to be acquired (buckets => locks)...
                foreach ( $pathsByType as $type => $paths ) {
                        foreach ( $paths as $path ) {
@@ -58,7 +59,7 @@ abstract class QuorumLockManager extends LockManager {
                        }
                }
 
-               $lockedPaths = array(); // files locked in this attempt (type => paths)
+               $lockedPaths = []; // files locked in this attempt (type => paths)
                // Attempt to acquire these locks...
                foreach ( $pathsToLock as $bucket => $pathsToLockByType ) {
                        // Try to acquire the locks for this bucket
@@ -84,7 +85,7 @@ abstract class QuorumLockManager extends LockManager {
        protected function doUnlockByType( array $pathsByType ) {
                $status = Status::newGood();
 
-               $pathsToUnlock = array(); // (bucket => type => paths)
+               $pathsToUnlock = []; // (bucket => type => paths)
                foreach ( $pathsByType as $type => $paths ) {
                        foreach ( $paths as $path ) {
                                if ( !isset( $this->locksHeld[$path][$type] ) ) {
@@ -111,7 +112,7 @@ abstract class QuorumLockManager extends LockManager {
                }
                if ( !count( $this->locksHeld ) ) {
                        $status->merge( $this->releaseAllLocks() );
-                       $this->degradedBuckets = array(); // safe to retry the normal quorum
+                       $this->degradedBuckets = []; // safe to retry the normal quorum
                }
 
                return $status;
@@ -121,7 +122,7 @@ abstract class QuorumLockManager extends LockManager {
         * Attempt to acquire locks with the peers for a bucket.
         * This is all or nothing; if any key is locked then this totally fails.
         *
-        * @param $bucket integer
+        * @param int $bucket
         * @param array $pathsByType Map of LockManager::LOCK_* constants to lists of paths
         * @return Status
         */
@@ -163,7 +164,7 @@ abstract class QuorumLockManager extends LockManager {
        /**
         * Attempt to release locks with the peers for a bucket
         *
-        * @param $bucket integer
+        * @param int $bucket
         * @param array $pathsByType Map of LockManager::LOCK_* constants to lists of paths
         * @return Status
         */
@@ -177,8 +178,8 @@ abstract class QuorumLockManager extends LockManager {
                foreach ( $this->srvsByBucket[$bucket] as $lockSrv ) {
                        if ( !$this->isServerUp( $lockSrv ) ) {
                                $status->warning( 'lockmanager-fail-svr-release', $lockSrv );
-                       // Attempt to release the lock on this peer
                        } else {
+                               // Attempt to release the lock on this peer
                                $status->merge( $this->freeLocksOnServer( $lockSrv, $pathsByType ) );
                                ++$yesVotes; // success for this peer
                                // Normally the first peers form the quorum, and the others are ignored.
@@ -199,8 +200,8 @@ abstract class QuorumLockManager extends LockManager {
         * Get the bucket for resource path.
         * This should avoid throwing any exceptions.
         *
-        * @param $path string
-        * @return integer
+        * @param string $path
+        * @return int
         */
        protected function getBucketFromPath( $path ) {
                $prefix = substr( sha1( $path ), 0, 2 ); // first 2 hex chars (8 bits)
@@ -211,7 +212,7 @@ abstract class QuorumLockManager extends LockManager {
         * Check if a lock server is up.
         * This should process cache results to reduce RTT.
         *
-        * @param $lockSrv string
+        * @param string $lockSrv
         * @return bool
         */
        abstract protected function isServerUp( $lockSrv );
@@ -219,7 +220,7 @@ abstract class QuorumLockManager extends LockManager {
        /**
         * Get a connection to a lock server and acquire locks
         *
-        * @param $lockSrv string
+        * @param string $lockSrv
         * @param array $pathsByType Map of LockManager::LOCK_* constants to lists of paths
         * @return Status
         */
@@ -230,7 +231,7 @@ abstract class QuorumLockManager extends LockManager {
         *
         * Subclasses must effectively implement this or releaseAllLocks().
         *
-        * @param $lockSrv string
+        * @param string $lockSrv
         * @param array $pathsByType Map of LockManager::LOCK_* constants to lists of paths
         * @return Status
         */