[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/lib/classes/lock/ -> postgres_lock_factory.php (summary)

Postgres advisory locking factory.

Copyright: Damyon Wiese 2013
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 243 lines (8 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

postgres_lock_factory:: (11 methods):
  get_unique_db_instance_id()
  __construct()
  is_available()
  supports_timeout()
  supports_auto_release()
  supports_recursion()
  get_index_from_key()
  get_lock()
  release_lock()
  extend_lock()
  auto_release()


Class: postgres_lock_factory  - X-Ref

Postgres advisory locking factory.

Postgres locking implementation using advisory locks. Some important points. Postgres has
2 different forms of lock functions, some accepting a single int, and some accepting 2 ints. This implementation
uses the 2 int version so that it uses a separate namespace from the session locking. The second note,
is because postgres uses integer keys for locks, we first need to map strings to a unique integer. This is
done by storing the strings in the lock_db table and using the auto-id returned. There is a static cache for
id's in this function.

get_unique_db_instance_id()   X-Ref
Calculate a unique instance id based on the database name and prefix.

return: int.

__construct($type)   X-Ref
Almighty constructor.

param: string $type - Used to prefix lock keys.

is_available()   X-Ref
Is available.

return: boolean - True if this lock type is available in this environment.

supports_timeout()   X-Ref
Return information about the blocking behaviour of the lock type on this platform.

return: boolean - Defer to the DB driver.

supports_auto_release()   X-Ref
Will this lock type will be automatically released when a process ends.

return: boolean - Via shutdown handler.

supports_recursion()   X-Ref
Multiple locks for the same resource can be held by a single process.

return: boolean - Defer to the DB driver.

get_index_from_key($key)   X-Ref
This function generates the unique index for a specific lock key.
Once an index is assigned to a key, it never changes - so this is
statically cached.

param: string $key
return: int

get_lock($resource, $timeout, $maxlifetime = 86400)   X-Ref
Create and get a lock

param: string $resource - The identifier for the lock. Should use frankenstyle prefix.
param: int $timeout - The number of seconds to wait for a lock before giving up.
param: int $maxlifetime - Unused by this lock type.
return: boolean - true if a lock was obtained.

release_lock(lock $lock)   X-Ref
Release a lock that was previously obtained with @lock.

param: lock $lock - a lock obtained from this factory.
return: boolean - true if the lock is no longer held (including if it was never held).

extend_lock(lock $lock, $maxlifetime = 86400)   X-Ref
Extend a lock that was previously obtained with @lock.

param: lock $lock - a lock obtained from this factory.
param: int $maxlifetime - the new lifetime for the lock (in seconds).
return: boolean - true if the lock was extended.

auto_release()   X-Ref
Auto release any open locks on shutdown.
This is required, because we may be using persistent DB connections.




Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1