@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Parameterize PhabricatorGlobalLock

Summary:
Ref T13096. Currently, we do a fair amount of clever digesting and string manipulation to build lock names which are less than 64 characters long while still being reasonably readable.

Instead, do more of this automatically. This will let lock acquisition become simpler and make it more possible to build a useful lock log.

Test Plan: Ran `bin/repository update`, saw a reasonable lock acquire and release.

Maniphest Tasks: T13096

Differential Revision: https://secure.phabricator.com/D19173

+32 -17
+5 -6
src/applications/repository/engine/PhabricatorRepositoryEngine.php
··· 56 56 $lock_key, 57 57 $lock_device_only) { 58 58 59 - $lock_parts = array(); 60 - $lock_parts[] = $lock_key; 61 - $lock_parts[] = $repository->getID(); 59 + $lock_parts = array( 60 + 'repositoryPHID' => $repository->getPHID(), 61 + ); 62 62 63 63 if ($lock_device_only) { 64 64 $device = AlmanacKeys::getLiveDevice(); 65 65 if ($device) { 66 - $lock_parts[] = $device->getID(); 66 + $lock_parts['devicePHID'] = $device->getPHID(); 67 67 } 68 68 } 69 69 70 - $lock_name = implode(':', $lock_parts); 71 - return PhabricatorGlobalLock::newLock($lock_name); 70 + return PhabricatorGlobalLock::newLock($lock_key, $lock_parts); 72 71 } 73 72 74 73
+27 -11
src/infrastructure/util/PhabricatorGlobalLock.php
··· 28 28 */ 29 29 final class PhabricatorGlobalLock extends PhutilLock { 30 30 31 + private $parameters; 31 32 private $conn; 32 33 private $isExternalConnection = false; 33 34 ··· 37 38 /* -( Constructing Locks )------------------------------------------------- */ 38 39 39 40 40 - public static function newLock($name) { 41 + public static function newLock($name, $parameters = array()) { 41 42 $namespace = PhabricatorLiskDAO::getStorageNamespace(); 42 43 $namespace = PhabricatorHash::digestToLength($namespace, 20); 43 44 44 - $full_name = 'ph:'.$namespace.':'.$name; 45 + $parts = array(); 46 + ksort($parameters); 47 + foreach ($parameters as $key => $parameter) { 48 + if (!preg_match('/^[a-zA-Z0-9]+\z/', $key)) { 49 + throw new Exception( 50 + pht( 51 + 'Lock parameter key "%s" must be alphanumeric.', 52 + $key)); 53 + } 45 54 46 - $length_limit = 64; 47 - if (strlen($full_name) > $length_limit) { 48 - throw new Exception( 49 - pht( 50 - 'Lock name "%s" is too long (full lock name is "%s"). The '. 51 - 'full lock name must not be longer than %s bytes.', 52 - $name, 53 - $full_name, 54 - new PhutilNumber($length_limit))); 55 + if (!is_scalar($parameter) && !is_null($parameter)) { 56 + throw new Exception( 57 + pht( 58 + 'Lock parameter for key "%s" must be a scalar.', 59 + $key)); 60 + } 61 + 62 + $value = phutil_json_encode($parameter); 63 + $parts[] = "{$key}={$value}"; 55 64 } 65 + $parts = implode(', ', $parts); 56 66 67 + $local = "{$name}({$parts})"; 68 + $local = PhabricatorHash::digestToLength($local, 20); 69 + 70 + $full_name = "ph:{$namespace}:{$local}"; 57 71 $lock = self::getLock($full_name); 58 72 if (!$lock) { 59 73 $lock = new PhabricatorGlobalLock($full_name); 60 74 self::registerLock($lock); 75 + 76 + $lock->parameters = $parameters; 61 77 } 62 78 63 79 return $lock;