X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;ds=sidebyside;f=includes%2Ffilebackend%2Flockmanager%2FMemcLockManager.php;h=81ce424b502e83996fc006ebc9f6be04d0cf0cf7;hb=32a1630ff2d6cda85d283df0cff3b0b805c67e27;hp=cb5266acd858df3d5c3ea2cc569ab0794b425824;hpb=fc1ca75323b5f424a9f8d28d42d85a311ed2f721;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/filebackend/lockmanager/MemcLockManager.php b/includes/filebackend/lockmanager/MemcLockManager.php index cb5266acd8..81ce424b50 100644 --- a/includes/filebackend/lockmanager/MemcLockManager.php +++ b/includes/filebackend/lockmanager/MemcLockManager.php @@ -90,7 +90,7 @@ class MemcLockManager extends QuorumLockManager { // @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 @@ class MemcLockManager extends QuorumLockManager { // @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 ) ); @@ -126,10 +126,10 @@ class MemcLockManager extends QuorumLockManager { * @param string $lockSrv * @param array $paths * @param string $type - * @return Status + * @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 @@ -202,10 +202,10 @@ class MemcLockManager extends QuorumLockManager { * @param string $lockSrv * @param array $paths * @param string $type - * @return Status + * @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 @@ -254,10 +254,10 @@ class MemcLockManager extends QuorumLockManager { /** * @see QuorumLockManager::releaseAllLocks() - * @return Status + * @return StatusValue */ protected function releaseAllLocks() { - return Status::newGood(); // not supported + return StatusValue::newGood(); // not supported } /** @@ -276,6 +276,7 @@ class MemcLockManager extends QuorumLockManager { * @return MemcachedBagOStuff|null */ protected function getCache( $lockSrv ) { + /** @var BagOStuff $memc */ $memc = null; if ( isset( $this->bagOStuffs[$lockSrv] ) ) { $memc = $this->bagOStuffs[$lockSrv]; @@ -337,20 +338,21 @@ class MemcLockManager extends QuorumLockManager { // Try to quickly loop to acquire the keys, but back off after a few rounds. // This reduces memcached spam, especially in the rare case where a server acquires // some lock keys and dies without releasing them. Lock keys expire after a few minutes. - $rounds = 0; - $start = microtime( true ); - do { - if ( ( ++$rounds % 4 ) == 0 ) { - usleep( 1000 * 50 ); // 50 ms - } - foreach ( array_diff( $keys, $lockedKeys ) as $key ) { - if ( $memc->add( "$key:mutex", 1, 180 ) ) { // lock record - $lockedKeys[] = $key; - } else { - continue; // acquire in order + $loop = new WaitConditionLoop( + function () use ( $memc, $keys, &$lockedKeys ) { + foreach ( array_diff( $keys, $lockedKeys ) as $key ) { + if ( $memc->add( "$key:mutex", 1, 180 ) ) { // lock record + $lockedKeys[] = $key; + } } - } - } while ( count( $lockedKeys ) < count( $keys ) && ( microtime( true ) - $start ) <= 3 ); + + return array_diff( $keys, $lockedKeys ) + ? WaitConditionLoop::CONDITION_CONTINUE + : true; + }, + 3.0 // timeout + ); + $loop->invoke(); if ( count( $lockedKeys ) != count( $keys ) ) { $this->releaseMutexes( $memc, $lockedKeys ); // failed; release what was locked