jenkins-bot has submitted this change and it was merged.

Change subject: Make LockManager use StatusValue and move classes to /libs
......................................................................


Make LockManager use StatusValue and move classes to /libs

Change-Id: Ifa41fc2939f3515d4a056746b0fcbff79786d25b
---
M autoload.php
M includes/filebackend/FileBackend.php
M includes/filebackend/lockmanager/DBLockManager.php
M includes/filebackend/lockmanager/MemcLockManager.php
M includes/filebackend/lockmanager/MySqlLockManager.php
M includes/filebackend/lockmanager/PostgreSqlLockManager.php
M includes/filebackend/lockmanager/RedisLockManager.php
M includes/libs/StatusValue.php
R includes/libs/lockmanager/FSLockManager.php
R includes/libs/lockmanager/LockManager.php
A includes/libs/lockmanager/NullLockManager.php
R includes/libs/lockmanager/QuorumLockManager.php
12 files changed, 71 insertions(+), 48 deletions(-)

Approvals:
  Gergő Tisza: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index a07df96..ff7d488 100644
--- a/autoload.php
+++ b/autoload.php
@@ -438,7 +438,7 @@
        'FSFileBackendFileList' => __DIR__ . 
'/includes/filebackend/FSFileBackend.php',
        'FSFileBackendList' => __DIR__ . 
'/includes/filebackend/FSFileBackend.php',
        'FSFileOpHandle' => __DIR__ . '/includes/filebackend/FSFileBackend.php',
-       'FSLockManager' => __DIR__ . 
'/includes/filebackend/lockmanager/FSLockManager.php',
+       'FSLockManager' => __DIR__ . 
'/includes/libs/lockmanager/FSLockManager.php',
        'FSRepo' => __DIR__ . '/includes/filerepo/FSRepo.php',
        'FakeAuthTemplate' => __DIR__ . 
'/includes/specialpage/LoginSignupSpecialPage.php',
        'FakeConverter' => __DIR__ . '/languages/FakeConverter.php',
@@ -747,7 +747,7 @@
        'LocalSettingsGenerator' => __DIR__ . 
'/includes/installer/LocalSettingsGenerator.php',
        'LocalisationCache' => __DIR__ . 
'/includes/cache/localisation/LocalisationCache.php',
        'LocalisationCacheBulkLoad' => __DIR__ . 
'/includes/cache/localisation/LocalisationCacheBulkLoad.php',
-       'LockManager' => __DIR__ . 
'/includes/filebackend/lockmanager/LockManager.php',
+       'LockManager' => __DIR__ . '/includes/libs/lockmanager/LockManager.php',
        'LockManagerGroup' => __DIR__ . 
'/includes/filebackend/lockmanager/LockManagerGroup.php',
        'LogEntry' => __DIR__ . '/includes/logging/LogEntry.php',
        'LogEntryBase' => __DIR__ . '/includes/logging/LogEntry.php',
@@ -979,7 +979,7 @@
        'NullFileOp' => __DIR__ . '/includes/filebackend/FileOp.php',
        'NullIndexField' => __DIR__ . '/includes/search/NullIndexField.php',
        'NullJob' => __DIR__ . '/includes/jobqueue/jobs/NullJob.php',
-       'NullLockManager' => __DIR__ . 
'/includes/filebackend/lockmanager/LockManager.php',
+       'NullLockManager' => __DIR__ . 
'/includes/libs/lockmanager/NullLockManager.php',
        'NullRepo' => __DIR__ . '/includes/filerepo/NullRepo.php',
        'NullStatsdDataFactory' => __DIR__ . 
'/includes/libs/stats/NullStatsdDataFactory.php',
        'NumericUppercaseCollation' => __DIR__ . 
'/includes/collation/NumericUppercaseCollation.php',
@@ -1110,7 +1110,7 @@
        'PurgeParserCache' => __DIR__ . '/maintenance/purgeParserCache.php',
        'QueryPage' => __DIR__ . '/includes/specialpage/QueryPage.php',
        'QuickTemplate' => __DIR__ . '/includes/skins/QuickTemplate.php',
-       'QuorumLockManager' => __DIR__ . 
'/includes/filebackend/lockmanager/QuorumLockManager.php',
+       'QuorumLockManager' => __DIR__ . 
'/includes/libs/lockmanager/QuorumLockManager.php',
        'RCCacheEntry' => __DIR__ . '/includes/changes/RCCacheEntry.php',
        'RCCacheEntryFactory' => __DIR__ . 
'/includes/changes/RCCacheEntryFactory.php',
        'RCDatabaseLogEntry' => __DIR__ . '/includes/logging/LogEntry.php',
diff --git a/includes/filebackend/FileBackend.php 
b/includes/filebackend/FileBackend.php
index 1f91b3f..ed2bdcc 100644
--- a/includes/filebackend/FileBackend.php
+++ b/includes/filebackend/FileBackend.php
@@ -1260,7 +1260,7 @@
        final public function lockFiles( array $paths, $type, $timeout = 0 ) {
                $paths = array_map( 'FileBackend::normalizeStoragePath', $paths 
);
 
-               return $this->lockManager->lock( $paths, $type, $timeout );
+               return $this->wrapStatus( $this->lockManager->lock( $paths, 
$type, $timeout ) );
        }
 
        /**
@@ -1273,7 +1273,7 @@
        final public function unlockFiles( array $paths, $type ) {
                $paths = array_map( 'FileBackend::normalizeStoragePath', $paths 
);
 
-               return $this->lockManager->unlock( $paths, $type );
+               return $this->wrapStatus( $this->lockManager->unlock( $paths, 
$type ) );
        }
 
        /**
diff --git a/includes/filebackend/lockmanager/DBLockManager.php 
b/includes/filebackend/lockmanager/DBLockManager.php
index cccf71a..4667dde 100644
--- a/includes/filebackend/lockmanager/DBLockManager.php
+++ b/includes/filebackend/lockmanager/DBLockManager.php
@@ -104,7 +104,7 @@
 
        // @todo change this code to work in one batch
        protected function getLocksOnServer( $lockSrv, array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
                foreach ( $pathsByType as $type => $paths ) {
                        $status->merge( $this->doGetLocksOnServer( $lockSrv, 
$paths, $type ) );
                }
@@ -115,7 +115,7 @@
        abstract protected function doGetLocksOnServer( $lockSrv, array $paths, 
$type );
 
        protected function freeLocksOnServer( $lockSrv, array $pathsByType ) {
-               return Status::newGood();
+               return StatusValue::newGood();
        }
 
        /**
diff --git a/includes/filebackend/lockmanager/MemcLockManager.php 
b/includes/filebackend/lockmanager/MemcLockManager.php
index 2e2d0a3..81ce424 100644
--- a/includes/filebackend/lockmanager/MemcLockManager.php
+++ b/includes/filebackend/lockmanager/MemcLockManager.php
@@ -90,7 +90,7 @@
 
        // @todo Change this code to work in one batch
        protected function getLocksOnServer( $lockSrv, array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $lockedPaths = [];
                foreach ( $pathsByType as $type => $paths ) {
@@ -112,7 +112,7 @@
 
        // @todo Change this code to work in one batch
        protected function freeLocksOnServer( $lockSrv, array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                foreach ( $pathsByType as $type => $paths ) {
                        $status->merge( $this->doFreeLocksOnServer( $lockSrv, 
$paths, $type ) );
@@ -129,7 +129,7 @@
         * @return StatusValue
         */
        protected function doGetLocksOnServer( $lockSrv, array $paths, $type ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $memc = $this->getCache( $lockSrv );
                $keys = array_map( [ $this, 'recordKeyForPath' ], $paths ); // 
lock records
@@ -205,7 +205,7 @@
         * @return StatusValue
         */
        protected function doFreeLocksOnServer( $lockSrv, array $paths, $type ) 
{
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $memc = $this->getCache( $lockSrv );
                $keys = array_map( [ $this, 'recordKeyForPath' ], $paths ); // 
lock records
@@ -257,7 +257,7 @@
         * @return StatusValue
         */
        protected function releaseAllLocks() {
-               return Status::newGood(); // not supported
+               return StatusValue::newGood(); // not supported
        }
 
        /**
diff --git a/includes/filebackend/lockmanager/MySqlLockManager.php 
b/includes/filebackend/lockmanager/MySqlLockManager.php
index 896e0ff..124d410 100644
--- a/includes/filebackend/lockmanager/MySqlLockManager.php
+++ b/includes/filebackend/lockmanager/MySqlLockManager.php
@@ -38,7 +38,7 @@
         * @return StatusValue
         */
        protected function doGetLocksOnServer( $lockSrv, array $paths, $type ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $db = $this->getConnection( $lockSrv ); // checked in 
isServerUp()
 
@@ -108,7 +108,7 @@
         * @return StatusValue
         */
        protected function releaseAllLocks() {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                foreach ( $this->conns as $lockDb => $db ) {
                        if ( $db->trxLevel() ) { // in transaction
diff --git a/includes/filebackend/lockmanager/PostgreSqlLockManager.php 
b/includes/filebackend/lockmanager/PostgreSqlLockManager.php
index 307c1644..d6b1ce8 100644
--- a/includes/filebackend/lockmanager/PostgreSqlLockManager.php
+++ b/includes/filebackend/lockmanager/PostgreSqlLockManager.php
@@ -14,7 +14,7 @@
        ];
 
        protected function doGetLocksOnServer( $lockSrv, array $paths, $type ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
                if ( !count( $paths ) ) {
                        return $status; // nothing to lock
                }
@@ -64,7 +64,7 @@
         * @return StatusValue
         */
        protected function releaseAllLocks() {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                foreach ( $this->conns as $lockDb => $db ) {
                        try {
diff --git a/includes/filebackend/lockmanager/RedisLockManager.php 
b/includes/filebackend/lockmanager/RedisLockManager.php
index 4121ecb..6fd819d 100644
--- a/includes/filebackend/lockmanager/RedisLockManager.php
+++ b/includes/filebackend/lockmanager/RedisLockManager.php
@@ -79,7 +79,7 @@
        }
 
        protected function getLocksOnServer( $lockSrv, array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $pathList = call_user_func_array( 'array_merge', array_values( 
$pathsByType ) );
 
@@ -172,7 +172,7 @@
        }
 
        protected function freeLocksOnServer( $lockSrv, array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $pathList = call_user_func_array( 'array_merge', array_values( 
$pathsByType ) );
 
@@ -242,7 +242,7 @@
        }
 
        protected function releaseAllLocks() {
-               return Status::newGood(); // not supported
+               return StatusValue::newGood(); // not supported
        }
 
        protected function isServerUp( $lockSrv ) {
diff --git a/includes/libs/StatusValue.php b/includes/libs/StatusValue.php
index 45185c5..bff9abd 100644
--- a/includes/libs/StatusValue.php
+++ b/includes/libs/StatusValue.php
@@ -58,7 +58,7 @@
         * Factory function for fatal errors
         *
         * @param string|MessageSpecifier $message Message key or object
-        * @return StatusValue
+        * @return static
         */
        public static function newFatal( $message /*, parameters...*/ ) {
                $params = func_get_args();
@@ -71,7 +71,7 @@
         * Factory function for good results
         *
         * @param mixed $value
-        * @return StatusValue
+        * @return static
         */
        public static function newGood( $value = null ) {
                $result = new static();
diff --git a/includes/filebackend/lockmanager/FSLockManager.php 
b/includes/libs/lockmanager/FSLockManager.php
similarity index 96%
rename from includes/filebackend/lockmanager/FSLockManager.php
rename to includes/libs/lockmanager/FSLockManager.php
index b6629aa..7f33a0a 100644
--- a/includes/filebackend/lockmanager/FSLockManager.php
+++ b/includes/libs/lockmanager/FSLockManager.php
@@ -70,7 +70,7 @@
         * @return StatusValue
         */
        protected function doLock( array $paths, $type ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $lockedPaths = []; // files locked in this attempt
                foreach ( $paths as $path ) {
@@ -95,7 +95,7 @@
         * @return StatusValue
         */
        protected function doUnlock( array $paths, $type ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                foreach ( $paths as $path ) {
                        $status->merge( $this->doSingleUnlock( $path, $type ) );
@@ -112,7 +112,7 @@
         * @return StatusValue
         */
        protected function doSingleLock( $path, $type ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                if ( isset( $this->locksHeld[$path][$type] ) ) {
                        ++$this->locksHeld[$path][$type];
@@ -157,7 +157,7 @@
         * @return StatusValue
         */
        protected function doSingleUnlock( $path, $type ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                if ( !isset( $this->locksHeld[$path] ) ) {
                        $status->warning( 'lockmanager-notlocked', $path );
@@ -200,7 +200,7 @@
         * @return StatusValue
         */
        private function closeLockHandles( $path, array $handlesToClose ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
                foreach ( $handlesToClose as $handle ) {
                        if ( !flock( $handle, LOCK_UN ) ) {
                                $status->fatal( 'lockmanager-fail-releaselock', 
$path );
@@ -218,7 +218,7 @@
         * @return StatusValue
         */
        private function pruneKeyLockFiles( $path ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
                if ( !isset( $this->locksHeld[$path] ) ) {
                        # No locks are held for the lock file anymore
                        if ( !unlink( $this->getLockPath( $path ) ) ) {
diff --git a/includes/filebackend/lockmanager/LockManager.php 
b/includes/libs/lockmanager/LockManager.php
similarity index 95%
rename from includes/filebackend/lockmanager/LockManager.php
rename to includes/libs/lockmanager/LockManager.php
index e7f37ed..80add5b 100644
--- a/includes/filebackend/lockmanager/LockManager.php
+++ b/includes/libs/lockmanager/LockManager.php
@@ -191,7 +191,7 @@
         * @since 1.22
         */
        protected function doLockByType( array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
                $lockedByType = []; // map of (type => paths)
                foreach ( $pathsByType as $type => $paths ) {
                        $status->merge( $this->doLock( $paths, $type ) );
@@ -225,7 +225,7 @@
         * @since 1.22
         */
        protected function doUnlockByType( array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
                foreach ( $pathsByType as $type => $paths ) {
                        $status->merge( $this->doUnlock( $paths, $type ) );
                }
@@ -241,18 +241,4 @@
         * @return StatusValue
         */
        abstract protected function doUnlock( array $paths, $type );
-}
-
-/**
- * Simple version of LockManager that does nothing
- * @since 1.19
- */
-class NullLockManager extends LockManager {
-       protected function doLock( array $paths, $type ) {
-               return Status::newGood();
-       }
-
-       protected function doUnlock( array $paths, $type ) {
-               return Status::newGood();
-       }
 }
diff --git a/includes/libs/lockmanager/NullLockManager.php 
b/includes/libs/lockmanager/NullLockManager.php
new file mode 100644
index 0000000..5ad558f
--- /dev/null
+++ b/includes/libs/lockmanager/NullLockManager.php
@@ -0,0 +1,37 @@
+<?php
+/**
+ * Resource locking handling.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup LockManager
+ * @author Aaron Schulz
+ */
+
+/**
+ * Simple version of LockManager that does nothing
+ * @since 1.19
+ */
+class NullLockManager extends LockManager {
+       protected function doLock( array $paths, $type ) {
+               return StatusValue::newGood();
+       }
+
+       protected function doUnlock( array $paths, $type ) {
+               return StatusValue::newGood();
+       }
+}
diff --git a/includes/filebackend/lockmanager/QuorumLockManager.php 
b/includes/libs/lockmanager/QuorumLockManager.php
similarity index 97%
rename from includes/filebackend/lockmanager/QuorumLockManager.php
rename to includes/libs/lockmanager/QuorumLockManager.php
index 0db9e81..8b5e7fd 100644
--- a/includes/filebackend/lockmanager/QuorumLockManager.php
+++ b/includes/libs/lockmanager/QuorumLockManager.php
@@ -44,7 +44,7 @@
        }
 
        protected function doLockByType( array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $pathsToLock = []; // (bucket => type => paths)
                // Get locks that need to be acquired (buckets => locks)...
@@ -83,7 +83,7 @@
        }
 
        protected function doUnlockByType( array $pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $pathsToUnlock = []; // (bucket => type => paths)
                foreach ( $pathsByType as $type => $paths ) {
@@ -127,7 +127,7 @@
         * @return StatusValue
         */
        final protected function doLockingRequestBucket( $bucket, array 
$pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $yesVotes = 0; // locks made on trustable servers
                $votesLeft = count( $this->srvsByBucket[$bucket] ); // 
remaining peers
@@ -169,7 +169,7 @@
         * @return StatusValue
         */
        final protected function doUnlockingRequestBucket( $bucket, array 
$pathsByType ) {
-               $status = Status::newGood();
+               $status = StatusValue::newGood();
 
                $yesVotes = 0; // locks freed on trustable servers
                $votesLeft = count( $this->srvsByBucket[$bucket] ); // 
remaining peers

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ifa41fc2939f3515d4a056746b0fcbff79786d25b
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>
Gerrit-Reviewer: Gergő Tisza <gti...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to