Remove "@author Aaron Schulz" annotations
[lhc/web/wiklou.git] / includes / libs / lockmanager / LockManager.php
index 42391a0..a6257bf 100644 (file)
@@ -4,6 +4,7 @@
  * @ingroup FileBackend
  */
 use Psr\Log\LoggerInterface;
+use Wikimedia\WaitConditionLoop;
 
 /**
  * Resource locking handling.
@@ -25,7 +26,6 @@ use Psr\Log\LoggerInterface;
  *
  * @file
  * @ingroup LockManager
- * @author Aaron Schulz
  */
 
 /**
@@ -33,7 +33,7 @@ use Psr\Log\LoggerInterface;
  *
  * Locks on resource keys can either be shared or exclusive.
  *
- * Implementations must keep track of what is locked by this proccess
+ * Implementations must keep track of what is locked by this process
  * in-memory and support nested locking calls (using reference counting).
  * At least LOCK_UW and LOCK_EX must be implemented. LOCK_SH can be a no-op.
  * Locks should either be non-blocking or have low wait timeouts.
@@ -68,6 +68,9 @@ abstract class LockManager {
        const LOCK_UW = 2; // shared lock (for reads used to write elsewhere)
        const LOCK_EX = 3; // exclusive lock (for writes)
 
+       /** @var int Max expected lock expiry in any context */
+       const MAX_LOCK_TTL = 7200; // 2 hours
+
        /**
         * Construct a new instance from configuration
         *
@@ -87,6 +90,11 @@ abstract class LockManager {
                        $this->lockTTL = max( 5 * 60, 2 * (int)$met );
                }
 
+               // Upper bound on how long to keep lock structures around. This is useful when setting
+               // TTLs, as the "lockTTL" value may vary based on CLI mode and app server group. This is
+               // a "safe" value that can be used to avoid clobbering other locks that use high TTLs.
+               $this->lockTTL = min( $this->lockTTL, self::MAX_LOCK_TTL );
+
                $random = [];
                for ( $i = 1; $i <= 5; ++$i ) {
                        $random[] = mt_rand( 0, 0xFFFFFFF );
@@ -161,7 +169,7 @@ abstract class LockManager {
        /**
         * Get the base 36 SHA-1 of a string, padded to 31 digits.
         * Before hashing, the path will be prefixed with the domain ID.
-        * This should be used interally for lock key or file names.
+        * This should be used internally for lock key or file names.
         *
         * @param string $path
         * @return string
@@ -173,7 +181,7 @@ abstract class LockManager {
        /**
         * Get the base 16 SHA-1 of a string, padded to 31 digits.
         * Before hashing, the path will be prefixed with the domain ID.
-        * This should be used interally for lock key or file names.
+        * This should be used internally for lock key or file names.
         *
         * @param string $path
         * @return string