Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackendMultiWrite.php |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | } |
86 | 86 | |
87 | 87 | // Try to lock those files for the scope of this function... |
88 | | - $scopedLock = $this->getScopedLock( $filesToLock, $status ); |
| 88 | + $scopedLock = $this->getScopedFileLocks( $filesToLock, $status ); |
89 | 89 | if ( !$status->isOK() ) { |
90 | 90 | return $status; // abort |
91 | 91 | } |
Index: branches/FileBackend/phase3/includes/filerepo/backend/LockManager.php |
— | — | @@ -38,15 +38,16 @@ |
39 | 39 | * Unlock the resources at the given abstract paths |
40 | 40 | * |
41 | 41 | * @param $paths Array List of storage paths |
| 42 | + * @param $type integer LockManager::LOCK_EX, LockManager::LOCK_SH |
42 | 43 | * @return Status |
43 | 44 | */ |
44 | | - final public function unlock( array $paths ) { |
| 45 | + final public function unlock( array $paths, $type = self::LOCK_EX ) { |
45 | 46 | $keys = array_unique( array_map( 'sha1', $paths ) ); |
46 | | - return $this->doUnlock( $keys, 0 ); |
| 47 | + return $this->doUnlock( $keys, $type ); |
47 | 48 | } |
48 | 49 | |
49 | 50 | /** |
50 | | - * Lock a resource with the given key |
| 51 | + * Lock resources with the given keys and lock type |
51 | 52 | * |
52 | 53 | * @param $key Array List of keys to lock (40 char hex hashes) |
53 | 54 | * @param $type integer LockManager::LOCK_EX, LockManager::LOCK_SH |
— | — | @@ -55,11 +56,10 @@ |
56 | 57 | abstract protected function doLock( array $keys, $type ); |
57 | 58 | |
58 | 59 | /** |
59 | | - * Unlock a resource with the given key. |
60 | | - * If $type is given, then only locks of that type should be cleared. |
| 60 | + * Unlock resources with the given keys and lock type |
61 | 61 | * |
62 | 62 | * @param $key Array List of keys to unlock (40 char hex hashes) |
63 | | - * @param $type integer LockManager::LOCK_EX, LockManager::LOCK_SH, or 0 |
| 63 | + * @param $type integer LockManager::LOCK_EX, LockManager::LOCK_SH |
64 | 64 | * @return string |
65 | 65 | */ |
66 | 66 | abstract protected function doUnlock( array $keys, $type ); |
— | — | @@ -173,25 +173,20 @@ |
174 | 174 | |
175 | 175 | if ( !isset( $this->locksHeld[$key] ) ) { |
176 | 176 | $status->warning( 'lockmanager-notlocked', $key ); |
177 | | - } elseif ( $type && !isset( $this->locksHeld[$key][$type] ) ) { |
| 177 | + } elseif ( !isset( $this->locksHeld[$key][$type] ) ) { |
178 | 178 | $status->warning( 'lockmanager-notlocked', $key ); |
179 | 179 | } else { |
180 | 180 | $handlesToClose = array(); |
181 | | - foreach ( $this->locksHeld[$key] as $lockType => $count ) { |
182 | | - if ( $type && $lockType != $type ) { |
183 | | - continue; // only unlock locks of type $type |
| 181 | + --$this->locksHeld[$key][$type]; |
| 182 | + if ( $this->locksHeld[$key][$type] <= 0 ) { |
| 183 | + unset( $this->locksHeld[$key][$type] ); |
| 184 | + // If a LOCK_SH comes in while we have a LOCK_EX, we don't |
| 185 | + // actually add a handler, so check for handler existence. |
| 186 | + if ( isset( $this->handles[$key][$type] ) ) { |
| 187 | + // Mark this handle to be unlocked and closed |
| 188 | + $handlesToClose[] = $this->handles[$key][$type]; |
| 189 | + unset( $this->handles[$key][$type] ); |
184 | 190 | } |
185 | | - --$this->locksHeld[$key][$lockType]; |
186 | | - if ( $this->locksHeld[$key][$lockType] <= 0 ) { |
187 | | - unset( $this->locksHeld[$key][$lockType] ); |
188 | | - // If a LOCK_SH comes in while we have a LOCK_EX, we don't |
189 | | - // actually add a handler, so check for handler existence. |
190 | | - if ( isset( $this->handles[$key][$lockType] ) ) { |
191 | | - // Mark this handle to be unlocked and closed |
192 | | - $handlesToClose[] = $this->handles[$key][$lockType]; |
193 | | - unset( $this->handles[$key][$lockType] ); |
194 | | - } |
195 | | - } |
196 | 191 | } |
197 | 192 | // Unlock handles to release locks and delete |
198 | 193 | // any lock files that end up with no locks on them... |
— | — | @@ -391,17 +386,12 @@ |
392 | 387 | foreach ( $keys as $key ) { |
393 | 388 | if ( !isset( $this->locksHeld[$key] ) ) { |
394 | 389 | $status->warning( 'lockmanager-notlocked', $key ); |
395 | | - } elseif ( $type && !isset( $this->locksHeld[$key][$type] ) ) { |
| 390 | + } elseif ( !isset( $this->locksHeld[$key][$type] ) ) { |
396 | 391 | $status->warning( 'lockmanager-notlocked', $key ); |
397 | 392 | } else { |
398 | | - foreach ( $this->locksHeld[$key] as $lockType => $count ) { |
399 | | - if ( $type && $lockType != $type ) { |
400 | | - continue; // only unlock locks of type $type |
401 | | - } |
402 | | - --$this->locksHeld[$key][$lockType]; |
403 | | - if ( $this->locksHeld[$key][$lockType] <= 0 ) { |
404 | | - unset( $this->locksHeld[$key][$lockType] ); |
405 | | - } |
| 393 | + --$this->locksHeld[$key][$type]; |
| 394 | + if ( $this->locksHeld[$key][$type] <= 0 ) { |
| 395 | + unset( $this->locksHeld[$key][$type] ); |
406 | 396 | } |
407 | 397 | if ( !count( $this->locksHeld[$key] ) ) { |
408 | 398 | unset( $this->locksHeld[$key] ); // no SH or EX locks left for key |
Index: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php |
— | — | @@ -253,11 +253,11 @@ |
254 | 254 | * |
255 | 255 | * Avoid using this function outside of FileBackendScopedLock. |
256 | 256 | * |
257 | | - * @param $sources Array Source storage paths |
| 257 | + * @param $paths Array Storage paths |
258 | 258 | * @return Status |
259 | 259 | */ |
260 | 260 | final public function lockFiles( array $paths ) { |
261 | | - return $this->lockManager->lock( $paths ); |
| 261 | + return $this->lockManager->lock( $paths, LockManager::LOCK_EX ); |
262 | 262 | } |
263 | 263 | |
264 | 264 | /** |
— | — | @@ -265,11 +265,11 @@ |
266 | 266 | * |
267 | 267 | * Avoid using this function outside of FileBackendScopedLock. |
268 | 268 | * |
269 | | - * @param $sources Array Source storage paths |
| 269 | + * @param $paths Array Storage paths |
270 | 270 | * @return Status |
271 | 271 | */ |
272 | 272 | final public function unlockFiles( array $paths ) { |
273 | | - return $this->lockManager->unlock( $paths ); |
| 273 | + return $this->lockManager->unlock( $paths, LockManager::LOCK_EX ); |
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
— | — | @@ -280,11 +280,11 @@ |
281 | 281 | * Once the return value goes out scope, the locks will be released and |
282 | 282 | * the status updated. Unlock fatals will not change the status "OK" value. |
283 | 283 | * |
284 | | - * @param $sources Array Source storage paths |
| 284 | + * @param $paths Array Storage paths |
285 | 285 | * @param $status Status Status to update on lock/unlock |
286 | 286 | * @return FileBackendScopedLock|null Returns null on failure |
287 | 287 | */ |
288 | | - final public function getScopedLock( array $paths, Status $status ) { |
| 288 | + final public function getScopedFileLocks( array $paths, Status $status ) { |
289 | 289 | return FileBackendScopedLock::factory( $this, $paths, $status ); |
290 | 290 | } |
291 | 291 | } |
— | — | @@ -499,7 +499,7 @@ |
500 | 500 | } |
501 | 501 | |
502 | 502 | // Try to lock those files for the scope of this function... |
503 | | - $scopedLock = $this->getScopedLock( $filesToLock, $status ); |
| 503 | + $scopedLock = $this->getScopedFileLocks( $filesToLock, $status ); |
504 | 504 | if ( !$status->isOK() ) { |
505 | 505 | return $status; // abort |
506 | 506 | } |