/ unidist / sharedstate.py
sharedstate
Shared State module. Get access to shared state.
All state has a namespace, and then the state id. sharecounter is used to
procure new state ids, so it can be incremented atomically and shared with
other procblock programs.
TODO(g): Implement serialization, archiving, snapshotting, and replication to
sharestate. This will allow us flexibility in many things. This is not
necessarily going to be the best scaling solution, but it will work and provide
a way to keep state and distribute. Name spaces should have this specified
individually. If not specified, state will not be archived, serialized,
snapshotted or replicated.
Functions
|
|
|
SetIfDoesntExist
|
SetIfDoesntExist (
bucket,
key,
value,
)
Returns boolean, whether the value was set or not.
Args:
bucket: string, name of bucket for state variables
key: string or any, key to store data against. Any valid dict key.
value: any, any object to be stored in shared state
|
|
Set
|
Set (
bucket,
key,
value,
)
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. Args:
bucket: string, name of bucket for state variables
key: string or any, key to store data against. Any valid dict key.
value: any, any object to be stored in shared state
|
|
_EnsureBucketExists
|
_EnsureBucketExists ( bucket )
|
|
Get
|
Get (
bucket,
key,
default=StateKeyNotFound,
)
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. Args:
bucket: string, name of bucket for state variables
key: string or any, key to store data against. Any valid dict key.
default: any value (optional), if set and there is no data in this key,
then this value will be set in the key and returned.
Exceptions
|
|
StateBucketDoesntExist( 'Bucket doesnt exist: %s' % bucket )
|
|
|
BucketExists
|
BucketExists ( bucket )
A bucket exists.
Args:
bucket: string, name of bucket for state variables
|
|
_LockState
|
_LockState ( bucket )
|
|
_UnlockState
|
_UnlockState ( bucket )
Exceptions
|
|
StateDoesntExist( 'Not found: %s' % bucket )
|
|
|
GetBucketKeys
|
GetBucketKeys ( bucket )
Returns the keys in a bucket.
Args:
bucket: string, name of bucket for state variables
NOTE(g): Having a "GetKeys()" function is rejected, due to it being confusing.
Exceptions
|
|
StateBucketDoesntExist( 'Bucket doesnt exist: %s' % bucket )
|
|
|
GetSet
|
GetSet (
bucket,
key,
value,
)
Returns boolean if this named lock is locked. If doesnt exist, still False
Args:
bucket: string, name of bucket for state variables
key: string or any, key to store data against. Any valid dict key.
value: any, any object to be stored in shared state
|
|
KeyExists
|
KeyExists ( bucket, key )
A key exists inside a bucket.
Args:
bucket: string, name of bucket for state variables
key: string or any, key to store data against. Any valid dict key.
Exceptions
|
|
StateBucketDoesntExist( 'Bucket doesnt exist: %s' % bucket )
|
|
|
|