Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15389974
D19173.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D19173.id.diff
View Options
diff --git a/src/applications/repository/engine/PhabricatorRepositoryEngine.php b/src/applications/repository/engine/PhabricatorRepositoryEngine.php
--- a/src/applications/repository/engine/PhabricatorRepositoryEngine.php
+++ b/src/applications/repository/engine/PhabricatorRepositoryEngine.php
@@ -56,19 +56,18 @@
$lock_key,
$lock_device_only) {
- $lock_parts = array();
- $lock_parts[] = $lock_key;
- $lock_parts[] = $repository->getID();
+ $lock_parts = array(
+ 'repositoryPHID' => $repository->getPHID(),
+ );
if ($lock_device_only) {
$device = AlmanacKeys::getLiveDevice();
if ($device) {
- $lock_parts[] = $device->getID();
+ $lock_parts['devicePHID'] = $device->getPHID();
}
}
- $lock_name = implode(':', $lock_parts);
- return PhabricatorGlobalLock::newLock($lock_name);
+ return PhabricatorGlobalLock::newLock($lock_key, $lock_parts);
}
diff --git a/src/infrastructure/util/PhabricatorGlobalLock.php b/src/infrastructure/util/PhabricatorGlobalLock.php
--- a/src/infrastructure/util/PhabricatorGlobalLock.php
+++ b/src/infrastructure/util/PhabricatorGlobalLock.php
@@ -28,6 +28,7 @@
*/
final class PhabricatorGlobalLock extends PhutilLock {
+ private $parameters;
private $conn;
private $isExternalConnection = false;
@@ -37,27 +38,42 @@
/* -( Constructing Locks )------------------------------------------------- */
- public static function newLock($name) {
+ public static function newLock($name, $parameters = array()) {
$namespace = PhabricatorLiskDAO::getStorageNamespace();
$namespace = PhabricatorHash::digestToLength($namespace, 20);
- $full_name = 'ph:'.$namespace.':'.$name;
-
- $length_limit = 64;
- if (strlen($full_name) > $length_limit) {
- throw new Exception(
- pht(
- 'Lock name "%s" is too long (full lock name is "%s"). The '.
- 'full lock name must not be longer than %s bytes.',
- $name,
- $full_name,
- new PhutilNumber($length_limit)));
+ $parts = array();
+ ksort($parameters);
+ foreach ($parameters as $key => $parameter) {
+ if (!preg_match('/^[a-zA-Z0-9]+\z/', $key)) {
+ throw new Exception(
+ pht(
+ 'Lock parameter key "%s" must be alphanumeric.',
+ $key));
+ }
+
+ if (!is_scalar($parameter) && !is_null($parameter)) {
+ throw new Exception(
+ pht(
+ 'Lock parameter for key "%s" must be a scalar.',
+ $key));
+ }
+
+ $value = phutil_json_encode($parameter);
+ $parts[] = "{$key}={$value}";
}
+ $parts = implode(', ', $parts);
+ $local = "{$name}({$parts})";
+ $local = PhabricatorHash::digestToLength($local, 20);
+
+ $full_name = "ph:{$namespace}:{$local}";
$lock = self::getLock($full_name);
if (!$lock) {
$lock = new PhabricatorGlobalLock($full_name);
self::registerLock($lock);
+
+ $lock->parameters = $parameters;
}
return $lock;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 16, 5:48 AM (3 w, 17 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7394701
Default Alt Text
D19173.id.diff (2 KB)
Attached To
Mode
D19173: Parameterize PhabricatorGlobalLock
Attached
Detach File
Event Timeline
Log In to Comment