Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/174645
Change subject: Made $timeout in BagOStuff::lock() actually work ...................................................................... Made $timeout in BagOStuff::lock() actually work * Also added a separate $expiry option for things that take a long time Change-Id: Ie5f81dea031f3c3f3ca8d61ad4cb322a5b876f61 --- M includes/objectcache/BagOStuff.php M includes/objectcache/MultiWriteBagOStuff.php 2 files changed, 9 insertions(+), 7 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/45/174645/1 diff --git a/includes/objectcache/BagOStuff.php b/includes/objectcache/BagOStuff.php index 1978c3e..0a23446 100644 --- a/includes/objectcache/BagOStuff.php +++ b/includes/objectcache/BagOStuff.php @@ -173,13 +173,14 @@ /** * @param string $key - * @param int $timeout [optional] + * @param int $timeout Lock wait timeout [optional] + * @param int $expiry Lock expiry [optional] * @return bool Success */ - public function lock( $key, $timeout = 6 ) { + public function lock( $key, $timeout = 6, $expiry = 6 ) { $this->clearLastError(); $timestamp = microtime( true ); // starting UNIX timestamp - if ( $this->add( "{$key}:lock", 1, $timeout ) ) { + if ( $this->add( "{$key}:lock", 1, $expiry ) ) { return true; } elseif ( $this->getLastError() ) { return false; @@ -198,11 +199,11 @@ } usleep( $sleep ); // back off $this->clearLastError(); - $locked = $this->add( "{$key}:lock", 1, $timeout ); + $locked = $this->add( "{$key}:lock", 1, $expiry ); if ( $this->getLastError() ) { return false; } - } while ( !$locked ); + } while ( !$locked && ( microtime( true ) - $timestamp ) < $timeout ); return $locked; } diff --git a/includes/objectcache/MultiWriteBagOStuff.php b/includes/objectcache/MultiWriteBagOStuff.php index 6a69137..c2a4a27 100644 --- a/includes/objectcache/MultiWriteBagOStuff.php +++ b/includes/objectcache/MultiWriteBagOStuff.php @@ -136,12 +136,13 @@ /** * @param string $key * @param int $timeout + * @param int $expiry * @return bool */ - public function lock( $key, $timeout = 0 ) { + public function lock( $key, $timeout = 6, $expiry = 6 ) { // Lock only the first cache, to avoid deadlocks if ( isset( $this->caches[0] ) ) { - return $this->caches[0]->lock( $key, $timeout ); + return $this->caches[0]->lock( $key, $timeout, $expiry ); } else { return true; } -- To view, visit https://gerrit.wikimedia.org/r/174645 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie5f81dea031f3c3f3ca8d61ad4cb322a5b876f61 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits