dépôts
/
lhc
/
web
/
wiklou.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge "Make DBAccessBase use DBConnRef, rename $wiki, and hide getLoadBalancer()"
[lhc/web/wiklou.git]
/
includes
/
libs
/
lockmanager
/
QuorumLockManager.php
diff --git
a/includes/libs/lockmanager/QuorumLockManager.php
b/includes/libs/lockmanager/QuorumLockManager.php
index
950b283
..
6478a61
100644
(file)
--- a/
includes/libs/lockmanager/QuorumLockManager.php
+++ b/
includes/libs/lockmanager/QuorumLockManager.php
@@
-38,7
+38,7
@@
abstract class QuorumLockManager extends LockManager {
final protected function doLockByType( array $pathsByType ) {
$status = StatusValue::newGood();
final protected function doLockByType( array $pathsByType ) {
$status = StatusValue::newGood();
- $paths
ToLock
= []; // (bucket => type => paths)
+ $paths
ByTypeByBucket
= []; // (bucket => type => paths)
// Get locks that need to be acquired (buckets => locks)...
foreach ( $pathsByType as $type => $paths ) {
foreach ( $paths as $path ) {
// Get locks that need to be acquired (buckets => locks)...
foreach ( $pathsByType as $type => $paths ) {
foreach ( $paths as $path ) {
@@
-46,23
+46,27
@@
abstract class QuorumLockManager extends LockManager {
++$this->locksHeld[$path][$type];
} else {
$bucket = $this->getBucketFromPath( $path );
++$this->locksHeld[$path][$type];
} else {
$bucket = $this->getBucketFromPath( $path );
- $paths
ToLock
[$bucket][$type][] = $path;
+ $paths
ByTypeByBucket
[$bucket][$type][] = $path;
}
}
}
}
}
}
+ // Acquire locks in each bucket in bucket order to reduce contention. Any blocking
+ // mutexes during the acquisition step will not involve circular waiting on buckets.
+ ksort( $pathsByTypeByBucket );
+
$lockedPaths = []; // files locked in this attempt (type => paths)
// Attempt to acquire these locks...
$lockedPaths = []; // files locked in this attempt (type => paths)
// Attempt to acquire these locks...
- foreach ( $paths
ToLock as $bucket => $pathsToLock
ByType ) {
+ foreach ( $paths
ByTypeByBucket as $bucket => $bucketPaths
ByType ) {
// Try to acquire the locks for this bucket
// Try to acquire the locks for this bucket
- $status->merge( $this->doLockingRequestBucket( $bucket, $
pathsToLock
ByType ) );
+ $status->merge( $this->doLockingRequestBucket( $bucket, $
bucketPaths
ByType ) );
if ( !$status->isOK() ) {
$status->merge( $this->doUnlockByType( $lockedPaths ) );
return $status;
}
// Record these locks as active
if ( !$status->isOK() ) {
$status->merge( $this->doUnlockByType( $lockedPaths ) );
return $status;
}
// Record these locks as active
- foreach ( $
pathsToLock
ByType as $type => $paths ) {
+ foreach ( $
bucketPaths
ByType as $type => $paths ) {
foreach ( $paths as $path ) {
$this->locksHeld[$path][$type] = 1; // locked
// Keep track of what locks were made in this attempt
foreach ( $paths as $path ) {
$this->locksHeld[$path][$type] = 1; // locked
// Keep track of what locks were made in this attempt
@@
-77,7
+81,7
@@
abstract class QuorumLockManager extends LockManager {
protected function doUnlockByType( array $pathsByType ) {
$status = StatusValue::newGood();
protected function doUnlockByType( array $pathsByType ) {
$status = StatusValue::newGood();
- $paths
ToUnlock
= []; // (bucket => type => paths)
+ $paths
ByTypeByBucket
= []; // (bucket => type => paths)
foreach ( $pathsByType as $type => $paths ) {
foreach ( $paths as $path ) {
if ( !isset( $this->locksHeld[$path][$type] ) ) {
foreach ( $pathsByType as $type => $paths ) {
foreach ( $paths as $path ) {
if ( !isset( $this->locksHeld[$path][$type] ) ) {
@@
-88,7
+92,7
@@
abstract class QuorumLockManager extends LockManager {
if ( $this->locksHeld[$path][$type] <= 0 ) {
unset( $this->locksHeld[$path][$type] );
$bucket = $this->getBucketFromPath( $path );
if ( $this->locksHeld[$path][$type] <= 0 ) {
unset( $this->locksHeld[$path][$type] );
$bucket = $this->getBucketFromPath( $path );
- $paths
ToUnlock
[$bucket][$type][] = $path;
+ $paths
ByTypeByBucket
[$bucket][$type][] = $path;
}
if ( $this->locksHeld[$path] === [] ) {
unset( $this->locksHeld[$path] ); // no SH or EX locks left for key
}
if ( $this->locksHeld[$path] === [] ) {
unset( $this->locksHeld[$path] ); // no SH or EX locks left for key
@@
-99,8
+103,8
@@
abstract class QuorumLockManager extends LockManager {
// Remove these specific locks if possible, or at least release
// all locks once this process is currently not holding any locks.
// Remove these specific locks if possible, or at least release
// all locks once this process is currently not holding any locks.
- foreach ( $paths
ToUnlock as $bucket => $pathsToUnlock
ByType ) {
- $status->merge( $this->doUnlockingRequestBucket( $bucket, $
pathsToUnlock
ByType ) );
+ foreach ( $paths
ByTypeByBucket as $bucket => $bucketPaths
ByType ) {
+ $status->merge( $this->doUnlockingRequestBucket( $bucket, $
bucketPaths
ByType ) );
}
if ( $this->locksHeld === [] ) {
$status->merge( $this->releaseAllLocks() );
}
if ( $this->locksHeld === [] ) {
$status->merge( $this->releaseAllLocks() );