*/
class RedisLockManager extends QuorumLockManager {
/** @var array Mapping of lock types to the type actually used */
- protected $lockTypeMap = array(
+ protected $lockTypeMap = [
self::LOCK_SH => self::LOCK_SH,
self::LOCK_UW => self::LOCK_SH,
self::LOCK_EX => self::LOCK_EX
- );
+ ];
/** @var RedisConnectionPool */
protected $redisPool;
/** @var array Map server names to hostname/IP and port numbers */
- protected $lockServers = array();
+ protected $lockServers = [];
/** @var string Random UUID */
protected $session = '';
}
protected function getLocksOnServer( $lockSrv, array $pathsByType ) {
- $status = Status::newGood();
+ $status = StatusValue::newGood();
+
+ $pathList = call_user_func_array( 'array_merge', array_values( $pathsByType ) );
$server = $this->lockServers[$lockSrv];
$conn = $this->redisPool->getConnection( $server );
if ( !$conn ) {
- foreach ( array_merge( array_values( $pathsByType ) ) as $path ) {
+ foreach ( $pathList as $path ) {
$status->fatal( 'lockmanager-fail-acquirelock', $path );
}
return $status;
}
- $pathsByKey = array(); // (type:hash => path) map
+ $pathsByKey = []; // (type:hash => path) map
foreach ( $pathsByType as $type => $paths ) {
$typeString = ( $type == LockManager::LOCK_SH ) ? 'SH' : 'EX';
foreach ( $paths as $path ) {
$res = $conn->luaEval( $script,
array_merge(
array_keys( $pathsByKey ), // KEYS[0], KEYS[1],...,KEYS[N]
- array(
+ [
$this->session, // ARGV[1]
$this->lockTTL, // ARGV[2]
time() // ARGV[3]
- )
+ ]
),
count( $pathsByKey ) # number of first argument(s) that are keys
);
}
if ( $res === false ) {
- foreach ( array_merge( array_values( $pathsByType ) ) as $path ) {
+ foreach ( $pathList as $path ) {
$status->fatal( 'lockmanager-fail-acquirelock', $path );
}
} else {
}
protected function freeLocksOnServer( $lockSrv, array $pathsByType ) {
- $status = Status::newGood();
+ $status = StatusValue::newGood();
+
+ $pathList = call_user_func_array( 'array_merge', array_values( $pathsByType ) );
$server = $this->lockServers[$lockSrv];
$conn = $this->redisPool->getConnection( $server );
if ( !$conn ) {
- foreach ( array_merge( array_values( $pathsByType ) ) as $path ) {
+ foreach ( $pathList as $path ) {
$status->fatal( 'lockmanager-fail-releaselock', $path );
}
return $status;
}
- $pathsByKey = array(); // (type:hash => path) map
+ $pathsByKey = []; // (type:hash => path) map
foreach ( $pathsByType as $type => $paths ) {
$typeString = ( $type == LockManager::LOCK_SH ) ? 'SH' : 'EX';
foreach ( $paths as $path ) {
$res = $conn->luaEval( $script,
array_merge(
array_keys( $pathsByKey ), // KEYS[0], KEYS[1],...,KEYS[N]
- array(
+ [
$this->session, // ARGV[1]
- )
+ ]
),
count( $pathsByKey ) # number of first argument(s) that are keys
);
}
if ( $res === false ) {
- foreach ( array_merge( array_values( $pathsByType ) ) as $path ) {
+ foreach ( $pathList as $path ) {
$status->fatal( 'lockmanager-fail-releaselock', $path );
}
} else {
}
protected function releaseAllLocks() {
- return Status::newGood(); // not supported
+ return StatusValue::newGood(); // not supported
}
protected function isServerUp( $lockSrv ) {
*/
protected function recordKeyForPath( $path, $type ) {
return implode( ':',
- array( __CLASS__, 'locks', "$type:" . $this->sha1Base36Absolute( $path ) ) );
+ [ __CLASS__, 'locks', "$type:" . $this->sha1Base36Absolute( $path ) ] );
}
/**
*/
function __destruct() {
while ( count( $this->locksHeld ) ) {
- $pathsByType = array();
+ $pathsByType = [];
foreach ( $this->locksHeld as $path => $locks ) {
foreach ( $locks as $type => $count ) {
$pathsByType[$type][] = $path;