foreach ( $paths as $path ) {
if ( isset( $this->locksHeld[$path][$type] ) ) {
++$this->locksHeld[$path][$type];
- } elseif ( isset( $this->locksHeld[$path][self::LOCK_EX] ) ) {
- $this->locksHeld[$path][$type] = 1;
} else {
- $bucket = $this->getBucketFromKey( $path );
+ $bucket = $this->getBucketFromPath( $path );
$pathsToLock[$bucket][] = $path;
}
}
// Reference count the locks held and release locks when zero
if ( $this->locksHeld[$path][$type] <= 0 ) {
unset( $this->locksHeld[$path][$type] );
- $bucket = $this->getBucketFromKey( $path );
+ $bucket = $this->getBucketFromPath( $path );
$pathsToUnlock[$bucket][] = $path;
}
if ( !count( $this->locksHeld[$path] ) ) {
* This is all or nothing; if any key is locked then this totally fails.
*
* @param $bucket integer
- * @param $paths Array List of resource keys to lock
+ * @param array $paths List of resource keys to lock
* @param $type integer LockManager::LOCK_EX or LockManager::LOCK_SH
* @return Status
*/
$yesVotes = 0; // locks made on trustable servers
$votesLeft = count( $this->srvsByBucket[$bucket] ); // remaining peers
- $quorum = floor( $votesLeft/2 + 1 ); // simple majority
+ $quorum = floor( $votesLeft / 2 + 1 ); // simple majority
// Get votes for each peer, in order, until we have enough...
foreach ( $this->srvsByBucket[$bucket] as $lockSrv ) {
if ( !$this->isServerUp( $lockSrv ) ) {
* Attempt to release locks with the peers for a bucket
*
* @param $bucket integer
- * @param $paths Array List of resource keys to lock
+ * @param array $paths List of resource keys to lock
* @param $type integer LockManager::LOCK_EX or LockManager::LOCK_SH
* @return Status
*/
* @param $path string
* @return integer
*/
- protected function getBucketFromKey( $path ) {
+ protected function getBucketFromPath( $path ) {
$prefix = substr( sha1( $path ), 0, 2 ); // first 2 hex chars (8 bits)
return (int)base_convert( $prefix, 16, 10 ) % count( $this->srvsByBucket );
}