cluster: add cluster package skeleton and LeaderElector interface

This commit is contained in:
Andras Banki-Horvath committed 2021-05-04 17:33:07 +02:00
1 parent 282618441d
commit e62dbca11a
3 files changed
+55

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
package cluster
import (
"context"
)
const (
// EtcdLeaderElector is the id used when constructing an
// etcdLeaderElector instance through the factory.
EtcdLeaderElector = "etcd"
)
// LeaderElector is a general interface implementing basic leader elections
// in a clustered environment.
type LeaderElector interface {
// Campaign starts a run for leadership. Campaign will block until
// the caller is elected as the leader.
Campaign(ctx context.Context) error
// Resign resigns from the leader role, allowing other election members
// to take on leadership.
Resign() error
// Leader returns the leader value for the current election.
Leader(ctx context.Context) (string, error)
}