Tim Starling has submitted this change and it was merged.

Change subject: [LockManager] Refactor lock TTL code to base class.
......................................................................


[LockManager] Refactor lock TTL code to base class.

* Also made the TTL configurable.

Change-Id: I713979267fe7bd92ac6cd5fe4d4168d20e539c75
---
M includes/filebackend/lockmanager/LockManager.php
M includes/filebackend/lockmanager/MemcLockManager.php
2 files changed, 14 insertions(+), 7 deletions(-)

Approvals:
  Tim Starling: Verified; Looks good to me, approved



diff --git a/includes/filebackend/lockmanager/LockManager.php 
b/includes/filebackend/lockmanager/LockManager.php
index 6d155df..0512a01 100644
--- a/includes/filebackend/lockmanager/LockManager.php
+++ b/includes/filebackend/lockmanager/LockManager.php
@@ -54,6 +54,7 @@
        protected $locksHeld = array();
 
        protected $domain; // string; domain (usually wiki ID)
+       protected $lockTTL; // integer; maximum time locks can be held
 
        /* Lock types; stronger locks have higher values */
        const LOCK_SH = 1; // shared lock (for reads)
@@ -64,12 +65,22 @@
         * Construct a new instance from configuration
         *
         * $config paramaters include:
-        *   - domain : Domain (usually wiki ID) that all resources are 
relative to [optional]
+        *   - domain  : Domain (usually wiki ID) that all resources are 
relative to [optional]
+        *   - lockTTL : Age (in seconds) at which resource locks should expire.
+        *               This only applies if locks are not tied to a 
connection/process.
         *
         * @param $config Array
         */
        public function __construct( array $config ) {
                $this->domain = isset( $config['domain'] ) ? $config['domain'] 
: wfWikiID();
+               if ( isset( $config['lockTTL'] ) ) {
+                       $this->lockTTL = max( 1, $config['lockTTL'] );
+               } elseif ( PHP_SAPI === 'cli' ) {
+                       $this->lockTTL = 2*3600;
+               } else {
+                       $met = ini_get( 'max_execution_time' ); // this is 0 in 
CLI mode
+                       $this->lockTTL = max( 5*60, 2*(int)$met );
+               }
        }
 
        /**
diff --git a/includes/filebackend/lockmanager/MemcLockManager.php 
b/includes/filebackend/lockmanager/MemcLockManager.php
index 8131f81..fafc588 100644
--- a/includes/filebackend/lockmanager/MemcLockManager.php
+++ b/includes/filebackend/lockmanager/MemcLockManager.php
@@ -48,7 +48,6 @@
        /** @var Array */
        protected $serversUp = array(); // (server name => bool)
 
-       protected $lockExpiry; // integer; maximum time locks can be held
        protected $session = ''; // string; random UUID
 
        /**
@@ -85,9 +84,6 @@
                                        'Only MemcachedBagOStuff classes are 
supported by MemcLockManager.' );
                        }
                }
-
-               $met = ini_get( 'max_execution_time' ); // this is 0 in CLI mode
-               $this->lockExpiry = $met ? 2*(int)$met : 2*3600;
 
                $this->session = wfRandomString( 32 );
        }
@@ -138,7 +134,7 @@
                        }
                        if ( $status->isOK() ) {
                                // Register the session in the lock record array
-                               $locksHeld[$type][$this->session] = $now + 
$this->lockExpiry;
+                               $locksHeld[$type][$this->session] = $now + 
$this->lockTTL;
                                // We will update this record if none of the 
other locks conflict
                                $lockRecords[$locksKey] = $locksHeld;
                        }
@@ -242,7 +238,7 @@
                if ( isset( $this->bagOStuffs[$lockSrv] ) ) {
                        $memc = $this->bagOStuffs[$lockSrv];
                        if ( !isset( $this->serversUp[$lockSrv] ) ) {
-                               $this->serversUp[$lockSrv] = $memc->set( 
'MemcLockManager:ping', 1, 1 );
+                               $this->serversUp[$lockSrv] = $memc->set( 
__CLASS__ . ':ping', 1, 1 );
                                if ( !$this->serversUp[$lockSrv] ) {
                                        trigger_error( __METHOD__ . ": Could 
not contact $lockSrv.", E_USER_WARNING );
                                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I713979267fe7bd92ac6cd5fe4d4168d20e539c75
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to