Page MenuHomeIsabelle/Phabricator

final class PhabricatorGlobalLock
Phabricator Technical Documentation ()

Global, MySQL-backed lock. This is a high-reliability, low-performance global lock.

The lock is maintained by using GET_LOCK() in MySQL, and automatically released when the connection terminates. Thus, this lock can safely be used to control access to shared resources without implementing any sort of timeout or override logic: the lock can't normally be stuck in a locked state with no process actually holding the lock.

However, acquiring the lock is moderately expensive (several network roundtrips). This makes it unsuitable for tasks where lock performance is important.

$lock = PhabricatorGlobalLock::newLock('example');
$lock->lock();
  do_contentious_things();
$lock->unlock();
NOTE: This lock is not completely global; it is namespaced to the active storage namespace so that unit tests running in separate table namespaces are isolated from one another.

Tasks

Constructing Locks

No methods for this task.

Implementation

No methods for this task.

Other Methods

Methods

public static function newLock($name, $parameters)

This method is not documented.
Parameters
$name
$parameters
Return
wild

public function useSpecificConnection($conn)

Use a specific database connection for locking.

By default, PhabricatorGlobalLock will lock on the "repository" database (somewhat arbitrarily). In most cases this is fine, but this method can be used to lock on a specific connection.

Parameters
AphrontDatabaseConnection$conn
Return
this

public function setDisableLogging($disable)

This method is not documented.
Parameters
$disable
Return
wild

protected function doLock($wait)

This method is not documented.
Parameters
$wait
Return
wild

protected function doUnlock()

This method is not documented.
Return
wild

private function shouldLogLock()

This method is not documented.
Return
wild

private function newLockContext()

This method is not documented.
Return
wild

private function newHint($lock_name, $wait)

This method is not documented.
Parameters
$lock_name
$wait
Return
wild