// @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 ) {
// @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 ) );
* @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
* @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
/**
* @see QuorumLockManager::releaseAllLocks()
- * @return Status
+ * @return StatusValue
*/
protected function releaseAllLocks() {
- return Status::newGood(); // not supported
+ return StatusValue::newGood(); // not supported
}
/**
* @return MemcachedBagOStuff|null
*/
protected function getCache( $lockSrv ) {
+ /** @var BagOStuff $memc */
$memc = null;
if ( isset( $this->bagOStuffs[$lockSrv] ) ) {
$memc = $this->bagOStuffs[$lockSrv];
// 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