Documentation
¶
Overview ¶
Package rink provides distributed role scheduling using etcd.
A scheduler instance allows arbitrary roles to be assumed by only a single member of a cluster of distributed processes. A cluster is maintained as a "distributed sticky ranked ring" using etcd which assigns a rank (order) to each member. Roles are consistently hashed to the mth (of n) member.
Etcd's concurrency.Session is used to identify members and act as liveliness proxy.
Etcd's concurrency.Election is used to elect a leader to maintain the cluster and broadcast state updates to the members.
Etcd's concurrency.Mutex is used to lock roles to prevent overlapping role assignment.
When members join or leave the cluster, the size (n) changes which results in roles being rebalanced.
Stickiness is provided by a configurable rebalance delay, allowing joining members to wait before triggering a rebalance of roles. If another member leaves while a member is waiting, its rank will be transferred immediately without affecting other members. If a member leaves and there are no waiting members, a rebalance is triggered affecting all instances.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*options)
func WithContext ¶
WithContext returns an option to override the default background context.
func WithHash ¶
func WithHash(hasher hasher) Option
WithHash returns an option to override the default 64-bit FNV-1a hash used to convert roles into keys for the consistent hash function.
func WithLogger ¶
func WithLogger(logger logger) Option
WithLogger returns an option to override the default jettison logger.
func WithRebalanceDelay ¶
WithRebalanceDelay returns an option to override the default rebalance delay of 60 secs. Rebalance delay specifies how long this member can wait on startup before a rank must be assigned to it. A rank may be assigned to it earlier if another member leaves.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler maps arbitrary roles to members of the cluster by consistent hashing to the mth of n member. It also maintains additional etcd mutex locks for each role this instance assumes. This ensures that overlapping roles is not possible.
func New ¶
func New(sess *concurrency.Session, clusterPrefix string, opts ...Option) *Scheduler
New returns a new scheduler linked to the session and cluster prefix. It also starts the underlying cluster. Closing the session releases all etcd resources and results in asynchronous release of all scheduler golang resources. Note that Scheduler.Close is a synchronous alternative.
func (*Scheduler) Await ¶
Await blocks until this scheduler can assign the role and returns a role context. The context will be closed when the role is assigned to another member of the cluster.
func (*Scheduler) Close ¶
Close closes the etcd session which releases all etcd resources or returns an error. It the session is closed, it also synchronously releases all golang resources.
func (*Scheduler) Get ¶
Get returns true and a role context if this scheduler can assume the role now. The context will be closed when the role is assigned to another member of the cluster. It returns false and a nil context if this scheduler cannot assume the role now.