Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Ganeti.Locking.Allocation
Description
Implementation of lock allocation.
Synopsis
- data LockAllocation a b
- emptyAllocation :: (Ord a, Ord b) => LockAllocation a b
- data OwnerState
- lockOwners :: Ord b => LockAllocation a b -> [b]
- listLocks :: Ord b => b -> LockAllocation a b -> Map a OwnerState
- listAllLocks :: Ord b => LockAllocation a b -> [a]
- listAllLocksOwners :: LockAllocation a b -> [(a, [(b, OwnerState)])]
- holdsLock :: (Ord a, Ord b) => b -> a -> OwnerState -> LockAllocation a b -> Bool
- data LockRequest a = LockRequest {
- lockAffected :: a
- lockRequestType :: Maybe OwnerState
- requestExclusive :: a -> LockRequest a
- requestShared :: a -> LockRequest a
- requestRelease :: a -> LockRequest a
- updateLocks :: (Lock a, Ord b) => b -> [LockRequest a] -> LockAllocation a b -> (LockAllocation a b, Result (Set b))
- freeLocks :: (Lock a, Ord b) => LockAllocation a b -> b -> LockAllocation a b
Documentation
data LockAllocation a b #
Representation of a Lock allocation
To keep queries for locks efficient, we keep two associations, with the invariant that they fit together: the association from locks to their allocation state, and the association from an owner to the set of locks owned. As we do not export the constructor, the problem of keeping this invariant reduces to only exporting functions that keep the invariant.
Instances
(Show a, Show b) => Show (LockAllocation a b) # | |
Defined in Ganeti.Locking.Allocation Methods showsPrec :: Int -> LockAllocation a b -> ShowS show :: LockAllocation a b -> String showList :: [LockAllocation a b] -> ShowS | |
(Eq a, Eq b) => Eq (LockAllocation a b) # | |
Defined in Ganeti.Locking.Allocation Methods (==) :: LockAllocation a b -> LockAllocation a b -> Bool (/=) :: LockAllocation a b -> LockAllocation a b -> Bool | |
(Lock a, JSON a, Ord b, JSON b, Show b) => JSON (LockAllocation a b) # | |
Defined in Ganeti.Locking.Allocation Methods readJSON :: JSValue -> Result (LockAllocation a b) showJSON :: LockAllocation a b -> JSValue readJSONs :: JSValue -> Result [LockAllocation a b] showJSONs :: [LockAllocation a b] -> JSValue |
emptyAllocation :: (Ord a, Ord b) => LockAllocation a b #
A state with all locks being free.
data OwnerState #
Data type describing the way a lock can be owned.
Constructors
OwnShared | |
OwnExclusive |
Instances
Show OwnerState # | |
Defined in Ganeti.Locking.Allocation Methods showsPrec :: Int -> OwnerState -> ShowS show :: OwnerState -> String showList :: [OwnerState] -> ShowS | |
Eq OwnerState # | |
Defined in Ganeti.Locking.Allocation | |
Ord OwnerState # | |
Defined in Ganeti.Locking.Allocation Methods compare :: OwnerState -> OwnerState -> Ordering (<) :: OwnerState -> OwnerState -> Bool (<=) :: OwnerState -> OwnerState -> Bool (>) :: OwnerState -> OwnerState -> Bool (>=) :: OwnerState -> OwnerState -> Bool max :: OwnerState -> OwnerState -> OwnerState min :: OwnerState -> OwnerState -> OwnerState | |
JSON OwnerState # | Serializaiton of Lock Allocations To serialize a lock allocation, we only remember which owner holds which locks at which level (shared or exclusive). From this information, everything else can be reconstructed, simply using updateLocks. |
Defined in Ganeti.Locking.Allocation Methods readJSON :: JSValue -> Result OwnerState showJSON :: OwnerState -> JSValue readJSONs :: JSValue -> Result [OwnerState] showJSONs :: [OwnerState] -> JSValue |
lockOwners :: Ord b => LockAllocation a b -> [b] #
Obtain the list of all owners holding at least a single lock.
listLocks :: Ord b => b -> LockAllocation a b -> Map a OwnerState #
Obtain the locks held by a given owner. The locks are reported as a map from the owned locks to the form of ownership (OwnShared or OwnExclusive).
listAllLocks :: Ord b => LockAllocation a b -> [a] #
List all locks currently (directly or indirectly) owned by someone.
listAllLocksOwners :: LockAllocation a b -> [(a, [(b, OwnerState)])] #
List all locks currently (directly of indirectly) in use together with the direct owners.
holdsLock :: (Ord a, Ord b) => b -> a -> OwnerState -> LockAllocation a b -> Bool #
Returns True
if the given owner holds the given lock at the given
ownership level or higher. This means that querying for a shared lock
returns True
of the owner holds the lock in shared or exlusive mode.
data LockRequest a #
Data Type describing a change request on a single lock.
Constructors
LockRequest | |
Fields
|
Instances
Show a => Show (LockRequest a) # | |
Defined in Ganeti.Locking.Allocation Methods showsPrec :: Int -> LockRequest a -> ShowS show :: LockRequest a -> String showList :: [LockRequest a] -> ShowS | |
Eq a => Eq (LockRequest a) # | |
Defined in Ganeti.Locking.Allocation | |
Ord a => Ord (LockRequest a) # | |
Defined in Ganeti.Locking.Allocation Methods compare :: LockRequest a -> LockRequest a -> Ordering (<) :: LockRequest a -> LockRequest a -> Bool (<=) :: LockRequest a -> LockRequest a -> Bool (>) :: LockRequest a -> LockRequest a -> Bool (>=) :: LockRequest a -> LockRequest a -> Bool max :: LockRequest a -> LockRequest a -> LockRequest a min :: LockRequest a -> LockRequest a -> LockRequest a | |
JSON a => JSON (LockRequest a) # | |
Defined in Ganeti.Locking.Allocation Methods readJSON :: JSValue -> Result (LockRequest a) showJSON :: LockRequest a -> JSValue readJSONs :: JSValue -> Result [LockRequest a] showJSONs :: [LockRequest a] -> JSValue |
requestExclusive :: a -> LockRequest a #
Lock request for an exclusive lock.
requestShared :: a -> LockRequest a #
Lock request for a shared lock.
requestRelease :: a -> LockRequest a #
Request to release a lock.
updateLocks :: (Lock a, Ord b) => b -> [LockRequest a] -> LockAllocation a b -> (LockAllocation a b, Result (Set b)) #
Update the locks of an owner according to the given request. Return the pair of the new state and the result of the operation, which is the the set of owners on which the operation was blocked on. so an empty set is success, and the state is updated if, and only if, the returned set is emtpy. In that way, it can be used in atomicModifyIORef.
freeLocks :: (Lock a, Ord b) => LockAllocation a b -> b -> LockAllocation a b #
Compute the state after an onwer releases all its locks.