package concurrency
import "github.com/coreos/etcd/clientv3/concurrency"
Package concurrency implements concurrency operations on top of etcd such as distributed locks, barriers, and elections.
Index ¶
- Variables
- func NewLocker(client *v3.Client, pfx string) sync.Locker
- func NewSTMReadCommitted(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error)
- func NewSTMRepeatable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error)
- func NewSTMSerializable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error)
- type Election
- func NewElection(client *v3.Client, pfx string) *Election
- func (e *Election) Campaign(ctx context.Context, val string) error
- func (e *Election) Key() string
- func (e *Election) Leader(ctx context.Context) (string, error)
- func (e *Election) Observe(ctx context.Context) <-chan v3.GetResponse
- func (e *Election) Proclaim(ctx context.Context, val string) error
- func (e *Election) Resign(ctx context.Context) (err error)
- type Mutex
- func NewMutex(client *v3.Client, pfx string) *Mutex
- func (m *Mutex) IsOwner() v3.Cmp
- func (m *Mutex) Key() string
- func (m *Mutex) Lock(ctx context.Context) error
- func (m *Mutex) Unlock(ctx context.Context) error
- type STM
- type Session
Variables ¶
var ( ErrElectionNotLeader = errors.New("election: not leader") ErrElectionNoLeader = errors.New("election: no leader") )
Functions ¶
func NewLocker ¶
NewLocker creates a sync.Locker backed by an etcd mutex.
func NewSTMReadCommitted ¶
func NewSTMReadCommitted(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error)
NewSTMReadCommitted initiates a new read committed transaction.
func NewSTMRepeatable ¶
func NewSTMRepeatable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error)
NewSTMRepeatable initiates new repeatable read transaction; reads within the same transaction attempt always return the same data.
func NewSTMSerializable ¶
func NewSTMSerializable(ctx context.Context, c *v3.Client, apply func(STM) error) (*v3.TxnResponse, error)
NewSTMSerializable initiates a new serialized transaction; reads within the same transactiona attempt return data from the revision of the first read.
Types ¶
type Election ¶
type Election struct {
// contains filtered or unexported fields
}
func NewElection ¶
NewElection returns a new election on a given key prefix.
func (*Election) Campaign ¶
Campaign puts a value as eligible for the election. It blocks until it is elected, an error occurs, or the context is cancelled.
func (*Election) Key ¶
Key returns the leader key if elected, empty string otherwise.
func (*Election) Leader ¶
Leader returns the leader value for the current election.
func (*Election) Observe ¶
func (e *Election) Observe(ctx context.Context) <-chan v3.GetResponse
Observe returns a channel that observes all leader proposal values as GetResponse values on the current leader key. The channel closes when the context is cancelled or the underlying watcher is otherwise disrupted.
func (*Election) Proclaim ¶
Proclaim lets the leader announce a new value without another election.
func (*Election) Resign ¶
Resign lets a leader start a new election.
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
Mutex implements the sync Locker interface with etcd
func NewMutex ¶
func (*Mutex) IsOwner ¶
func (*Mutex) Key ¶
func (*Mutex) Lock ¶
Lock locks the mutex with a cancellable context. If the context is cancelled while trying to acquire the lock, the mutex tries to clean its stale lock entry.
func (*Mutex) Unlock ¶
type STM ¶
type STM interface { // Get returns the value for a key and inserts the key in the txn's read set. // If Get fails, it aborts the transaction with an error, never returning. Get(key string) string // Put adds a value for a key to the write set. Put(key, val string, opts ...v3.OpOption) // Rev returns the revision of a key in the read set. Rev(key string) int64 // Del deletes a key. Del(key string) // contains filtered or unexported methods }
STM is an interface for software transactional memory.
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session represents a lease kept alive for the lifetime of a client. Fault-tolerant applications may use sessions to reason about liveness.
func NewSession ¶
NewSession gets the leased session for a client.
func (*Session) Close ¶
Close orphans the session and revokes the session lease.
func (*Session) Done ¶
func (s *Session) Done() <-chan struct{}
Done returns a channel that closes when the lease is orphaned, expires, or is otherwise no longer being refreshed.
func (*Session) Lease ¶
Lease is the lease ID for keys bound to the session.
func (*Session) Orphan ¶
func (s *Session) Orphan()
Orphan ends the refresh for the session lease. This is useful in case the state of the client connection is indeterminate (revoke would fail) or when transferring lease ownership.
Source Files ¶
doc.go election.go key.go mutex.go session.go stm.go
- Version
- v3.0.6+incompatible
- Published
- Aug 19, 2016
- Platform
- linux/amd64
- Imports
- 7 packages
- Last checked
- 7 minutes ago –
Tools for package owners.