https://www.mediawiki.org/wiki/Special:Code/MediaWiki/105491
Revision: 105491 Author: aaron Date: 2011-12-07 23:48:46 +0000 (Wed, 07 Dec 2011) Log Message: ----------- * Renamed getScopedLock() => getScopedFileLocks() * Made unlock() functions require a $type param and avoided bug with lock nesting (outer function locks getting released by innter function if one did an SH lock on a key and another an EX lock) * More documentation fixes Modified Paths: -------------- branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php branches/FileBackend/phase3/includes/filerepo/backend/FileBackendMultiWrite.php branches/FileBackend/phase3/includes/filerepo/backend/LockManager.php Modified: branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php =================================================================== --- branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php 2011-12-07 23:37:21 UTC (rev 105490) +++ branches/FileBackend/phase3/includes/filerepo/backend/FileBackend.php 2011-12-07 23:48:46 UTC (rev 105491) @@ -253,11 +253,11 @@ * * Avoid using this function outside of FileBackendScopedLock. * - * @param $sources Array Source storage paths + * @param $paths Array Storage paths * @return Status */ final public function lockFiles( array $paths ) { - return $this->lockManager->lock( $paths ); + return $this->lockManager->lock( $paths, LockManager::LOCK_EX ); } /** @@ -265,11 +265,11 @@ * * Avoid using this function outside of FileBackendScopedLock. * - * @param $sources Array Source storage paths + * @param $paths Array Storage paths * @return Status */ final public function unlockFiles( array $paths ) { - return $this->lockManager->unlock( $paths ); + return $this->lockManager->unlock( $paths, LockManager::LOCK_EX ); } /** @@ -280,11 +280,11 @@ * Once the return value goes out scope, the locks will be released and * the status updated. Unlock fatals will not change the status "OK" value. * - * @param $sources Array Source storage paths + * @param $paths Array Storage paths * @param $status Status Status to update on lock/unlock * @return FileBackendScopedLock|null Returns null on failure */ - final public function getScopedLock( array $paths, Status $status ) { + final public function getScopedFileLocks( array $paths, Status $status ) { return FileBackendScopedLock::factory( $this, $paths, $status ); } } @@ -499,7 +499,7 @@ } // Try to lock those files for the scope of this function... - $scopedLock = $this->getScopedLock( $filesToLock, $status ); + $scopedLock = $this->getScopedFileLocks( $filesToLock, $status ); if ( !$status->isOK() ) { return $status; // abort } Modified: branches/FileBackend/phase3/includes/filerepo/backend/FileBackendMultiWrite.php =================================================================== --- branches/FileBackend/phase3/includes/filerepo/backend/FileBackendMultiWrite.php 2011-12-07 23:37:21 UTC (rev 105490) +++ branches/FileBackend/phase3/includes/filerepo/backend/FileBackendMultiWrite.php 2011-12-07 23:48:46 UTC (rev 105491) @@ -84,7 +84,7 @@ } // Try to lock those files for the scope of this function... - $scopedLock = $this->getScopedLock( $filesToLock, $status ); + $scopedLock = $this->getScopedFileLocks( $filesToLock, $status ); if ( !$status->isOK() ) { return $status; // abort } Modified: branches/FileBackend/phase3/includes/filerepo/backend/LockManager.php =================================================================== --- branches/FileBackend/phase3/includes/filerepo/backend/LockManager.php 2011-12-07 23:37:21 UTC (rev 105490) +++ branches/FileBackend/phase3/includes/filerepo/backend/LockManager.php 2011-12-07 23:48:46 UTC (rev 105491) @@ -38,15 +38,16 @@ * Unlock the resources at the given abstract paths * * @param $paths Array List of storage paths + * @param $type integer LockManager::LOCK_EX, LockManager::LOCK_SH * @return Status */ - final public function unlock( array $paths ) { + final public function unlock( array $paths, $type = self::LOCK_EX ) { $keys = array_unique( array_map( 'sha1', $paths ) ); - return $this->doUnlock( $keys, 0 ); + return $this->doUnlock( $keys, $type ); } /** - * Lock a resource with the given key + * Lock resources with the given keys and lock type * * @param $key Array List of keys to lock (40 char hex hashes) * @param $type integer LockManager::LOCK_EX, LockManager::LOCK_SH @@ -55,11 +56,10 @@ abstract protected function doLock( array $keys, $type ); /** - * Unlock a resource with the given key. - * If $type is given, then only locks of that type should be cleared. + * Unlock resources with the given keys and lock type * * @param $key Array List of keys to unlock (40 char hex hashes) - * @param $type integer LockManager::LOCK_EX, LockManager::LOCK_SH, or 0 + * @param $type integer LockManager::LOCK_EX, LockManager::LOCK_SH * @return string */ abstract protected function doUnlock( array $keys, $type ); @@ -173,25 +173,20 @@ if ( !isset( $this->locksHeld[$key] ) ) { $status->warning( 'lockmanager-notlocked', $key ); - } elseif ( $type && !isset( $this->locksHeld[$key][$type] ) ) { + } elseif ( !isset( $this->locksHeld[$key][$type] ) ) { $status->warning( 'lockmanager-notlocked', $key ); } else { $handlesToClose = array(); - foreach ( $this->locksHeld[$key] as $lockType => $count ) { - if ( $type && $lockType != $type ) { - continue; // only unlock locks of type $type + --$this->locksHeld[$key][$type]; + if ( $this->locksHeld[$key][$type] <= 0 ) { + unset( $this->locksHeld[$key][$type] ); + // If a LOCK_SH comes in while we have a LOCK_EX, we don't + // actually add a handler, so check for handler existence. + if ( isset( $this->handles[$key][$type] ) ) { + // Mark this handle to be unlocked and closed + $handlesToClose[] = $this->handles[$key][$type]; + unset( $this->handles[$key][$type] ); } - --$this->locksHeld[$key][$lockType]; - if ( $this->locksHeld[$key][$lockType] <= 0 ) { - unset( $this->locksHeld[$key][$lockType] ); - // If a LOCK_SH comes in while we have a LOCK_EX, we don't - // actually add a handler, so check for handler existence. - if ( isset( $this->handles[$key][$lockType] ) ) { - // Mark this handle to be unlocked and closed - $handlesToClose[] = $this->handles[$key][$lockType]; - unset( $this->handles[$key][$lockType] ); - } - } } // Unlock handles to release locks and delete // any lock files that end up with no locks on them... @@ -391,17 +386,12 @@ foreach ( $keys as $key ) { if ( !isset( $this->locksHeld[$key] ) ) { $status->warning( 'lockmanager-notlocked', $key ); - } elseif ( $type && !isset( $this->locksHeld[$key][$type] ) ) { + } elseif ( !isset( $this->locksHeld[$key][$type] ) ) { $status->warning( 'lockmanager-notlocked', $key ); } else { - foreach ( $this->locksHeld[$key] as $lockType => $count ) { - if ( $type && $lockType != $type ) { - continue; // only unlock locks of type $type - } - --$this->locksHeld[$key][$lockType]; - if ( $this->locksHeld[$key][$lockType] <= 0 ) { - unset( $this->locksHeld[$key][$lockType] ); - } + --$this->locksHeld[$key][$type]; + if ( $this->locksHeld[$key][$type] <= 0 ) { + unset( $this->locksHeld[$key][$type] ); } if ( !count( $this->locksHeld[$key] ) ) { unset( $this->locksHeld[$key] ); // no SH or EX locks left for key _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs