Documentation ¶
Overview ¶
package zksync provides synchronization primitives backed by ZooKeeper.
Index ¶
Constants ¶
const ( Fatal severity = iota Error Warning Info Debug Trace )
Variables ¶
var ( ErrMalformedLock = errors.New("not a valid lock") ErrNoLockPresent = errors.New("not currently holding a lock") )
Functions ¶
func SetVerbosity ¶
func SetVerbosity(v severity)
Types ¶
type Barrier ¶
type Barrier struct {
// contains filtered or unexported fields
}
Bariers block processing on until a condition is met, at which time all processes blocked on the barrier are allowed to proceed.
Barriers are implemented by setting a znode in ZooKeeper. If the znode exists, the barrier is in place.
func NewBarrier ¶
NewBarrier instantiates a Barrier struct. It doesn't actually create anything in ZooKeeper or communicate with ZooKeeper in any way. If the path doesn't exist when `Barrier.Set()` is called, then it will be created, along with any parent nodes, using the provided ACL.
func (*Barrier) Set ¶
Set places the barrier, blocking any callers of b.Wait(). Returns an error if the barrier exists; callers can handle the zk.ErrNodeExists themselves.
type DoubleBarrier ¶
type DoubleBarrier struct {
// contains filtered or unexported fields
}
Double barriers enable clients to synchronize the beginning and the end of a computation. When enough processes have joined the barrier, processes start their computation and leave the barrier once they have finished.
Double barrier clients register with an ID string which is used to know which clients have not started or finished a computation.
Double barrier clients need to know how many client processes are participating in order to know when all clients are ready.
func NewDoubleBarrier ¶
NewDoubleBarrier creates a DoubleBarrier using the provided connection to ZooKeeper. The barrier is registered under the given path, and the client will identify itself with the given ID. When Enter or Exit are called, it will block until n clients have similarly entered or exited. The acl is used when creating any znodes.
func (*DoubleBarrier) CancelEnter ¶
func (db *DoubleBarrier) CancelEnter()
CancelEnter aborts an Enter call and cleans up as it aborts. This can be used in conjunction with a timeout to exit early from a Double Barrier.
func (*DoubleBarrier) Enter ¶
func (db *DoubleBarrier) Enter() (err error)
Enter joins the computation. It registers this client at the znode, and then blocks until all n clients have registered. If the path does not exist, then it is created, along with any of its parents if they don't exist.
func (*DoubleBarrier) Exit ¶
func (db *DoubleBarrier) Exit() error
Exit reports this client as done with the computation. It deregisters this node from ZooKeeper, then blocks until all nodes have deregistered.
type RWMutex ¶
type RWMutex struct {
// contains filtered or unexported fields
}
RWMutex provides a read-write lock backed by ZooKeeper. Multiple clients can use the lock as long as they use the same path on the same ZooKeeper ensemble.
Access is provided on a first-come, first-serve basis. Readers are granted the lock if there are no current writers (so reads can happen concurrently). Writers are only granted the lock exclusively.
It is important to release the lock with `Unlock`, of course.
In case of an unexpected disconnection from ZooKeeper, any locks will be released because the Session Timeout will expire, but its the caller's responsibilty to halt any computation in this case. This can be done by listening to the Event channel provided by zk.Connect (https://godoc.org/github.com/samuel/go-zookeeper/zk#Connect).
RWMutexes are not safe for shared local use across goroutines.
func NewRWMutex ¶
NewRWMutex creates a new RWMutex object. It doesn't actually perform any locking or communicate with ZooKeeper in any way. If the path does not exist, it will be created when RLock or WLock are called, as will any of its parents, using the provided ACL.
func (*RWMutex) RLock ¶
RLock acquires a read lock on a znode. This will block if there are any write locks already on that znode until the write locks are released.