HappyDoc Generated Documentation unidist/sharedlock.py

unidist / sharedlock.py 

sharedlock

Shared Locking module. Get access to shared locks for any program using this procblock module's state.

NOTE(g): Locks are never stored for process restarts. If a process goes down, assume all locks are lost and must be restored. There is no way to determine the effect that the process restarting will have on a lock, so the assumption must be made that the locks have been lost.

Only distributed locking can solve this, so that any given nodes loss of locks means nothing, because a quorum (N/2+1) must be reached before a new lock will be acquired, and so the restart of this lock databes node means nothing in itself, as a minimum of 3 nodes must be present for a quorum to decide on a lock.

An individual node's code will restart as well, so the code will proceed as if no locks are already set, and start requesting locks. This appears to be the right way to handle this.

TODO(g): Allow quorum-locking for multi-region locks. This isn't about implementation in this module, it's about creating the method for how to link a number of locks together so that inside an entire system the first to get the (N/2)+1 locks is the victor, and all other locks are undone and given to the victor. Other lock attempts must block until the quorum releases the lock and allows another (N/2)+1 locks to be made.

Distributed lock systems allow flexibility on lock servers coming and going for large scale systems. No system can be the master in this environment and a majority quorum must be met to enforce any lock. Each lock server should attempt to gain the quorum lock before locking itself.

There is a dual-layer of locking here. The attempt-lock and the actual-lock. The attempt lock is this node only, the actual-lock is when a quorum has been reached. Attempt locks are blocked by actual locks.

All distributed locks must have a timeout specified so that the network does not come to a halt.

To avoid dead-locks, locks must have a unique priority, so a lock name must register it's unique priority. To get a lower lock, you must attain higher locks first, and only go from low to high. This allows dead-locks to be avoided by design. Locks must be designed as a priority so a high lock is never requested before a low-lock.

This can be enforced by using credentials for locks, so a node request sessions has a crendential, and the credentials are tracked, and any requests from that credential must come in order, or will be rejected due to creating a possible dead-lock scenario.

Functions   
  Acquire 
Acquire (
        name,
        timeout=None,
        save=False,
        )

Acquire the lock.

Args: name: string, name of the lock. Use naming convertion like: "top.middle.bottom" or other layered naming convertion to be able to maintain specific resource locks. time: float or None (optional), if float, number of seconds until timeout save: boolean, if True this lock will be saved to disk on restart, so the resource is still locked or unlocked after sharedlock's module has been reloaded TODO(g): Use state and not module, or maybe in addition to module...

Returns: boolean, success of lock (only False if timeout is set and exceeded)

  SharedControl_Release 
SharedControl_Release ()

Lock the shared control access to locks. This way we can safely acquire an individual lock or create a new lock without a race condition.

  FindAllLocked 
FindAllLocked ()

Returns a list of strings, for the names of all the locks currentl locked.

  IsLocked 
IsLocked ( name )

Returns boolean if this named lock is locked. If doesnt exist, still False

Args: name: string, name of lock

  Release 
Release ( name )

Acquire the lock.

TODO(g): Could have optional secret to enforce who can release this lock...

Args: name: string, name of the lock. Use naming convertion like: "top.middle.bottom" or other layered naming convertion to be able to maintain specific resource locks. time: float or None (optional), if float, number of seconds until timeout

Exceptions   

LockDoesntExist( name )

  SharedControl_Lock 
SharedControl_Lock ()

Lock the shared control access to locks. This way we can safely acquire an individual lock or create a new lock without a race condition.

Classes   

LockDoesntExist

This lock does not exist, so it cant be released.


This document was automatically generated Tue Aug 17 15:20:25 2010 by HappyDoc version 3.1