Documentation ¶
Index ¶
- Variables
- func CandidateIdCompare(a CandidateId, b CandidateId) int
- type CandidateId
- func (i CandidateId) Clone() (clone CandidateId)
- func (i CandidateId) Compare(x CandidateId) int
- func (i CandidateId) Equal(x CandidateId) bool
- func (i CandidateId) MarshalBSONValue() (bsontype.Type, []byte, error)
- func (i CandidateId) MarshalJSON() ([]byte, error)
- func (i *CandidateId) MarshalText() ([]byte, error)
- func (i CandidateId) String() string
- func (i *CandidateId) UnmarshalBSONValue(t bsontype.Type, raw []byte) error
- func (i *CandidateId) UnmarshalJSON(data []byte) (err error)
- func (i *CandidateId) UnmarshalText(text []byte) error
- type ElectedLeader
- type Elector
- type ElectorOptions
- type ElectorStatus
- type FollowerWorker
- type LeaderWorker
Constants ¶
This section is empty.
Variables ¶
var ManagedIndexes = []mongostore.Index{ { CollectionName: collectionName, Id: "ttlExpire_ttl", Version: 0, Model: mongo.IndexModel{ Options: options.Index().SetExpireAfterSeconds(0), Keys: bson.D{ {Key: "ttlExpire", Value: mongostore.ASC}, }, }, }, }
var ZeroCandidateId = CandidateId(primitive.NilObjectID)
Functions ¶
func CandidateIdCompare ¶
func CandidateIdCompare(a CandidateId, b CandidateId) int
CandidateIdCompare returns an integer comparing two CandidateIds. The result will be 0 if a == b, -1 if a < b, and +1 if a > b.
Types ¶
type CandidateId ¶
func CandidateIdPointerSliceToSlice ¶
func CandidateIdPointerSliceToSlice(inputSlice []*CandidateId) (outputSlice []CandidateId)
func MakeCandidateId ¶
func MakeCandidateId() CandidateId
func OrganizationidSliceToPointerSlice ¶
func OrganizationidSliceToPointerSlice(inputSlice []CandidateId) (outputSlice []*CandidateId)
func (CandidateId) Clone ¶
func (i CandidateId) Clone() (clone CandidateId)
func (CandidateId) Compare ¶
func (i CandidateId) Compare(x CandidateId) int
Compare returns an integer comparing two CandidateIds. The result will be 0 if this == x, -1 if this < x, and +1 if this > x.
func (CandidateId) Equal ¶
func (i CandidateId) Equal(x CandidateId) bool
func (CandidateId) MarshalBSONValue ¶
func (i CandidateId) MarshalBSONValue() (bsontype.Type, []byte, error)
func (CandidateId) MarshalJSON ¶
func (i CandidateId) MarshalJSON() ([]byte, error)
func (*CandidateId) MarshalText ¶
func (i *CandidateId) MarshalText() ([]byte, error)
func (CandidateId) String ¶
func (i CandidateId) String() string
func (*CandidateId) UnmarshalBSONValue ¶
func (i *CandidateId) UnmarshalBSONValue(t bsontype.Type, raw []byte) error
func (*CandidateId) UnmarshalJSON ¶
func (i *CandidateId) UnmarshalJSON(data []byte) (err error)
func (*CandidateId) UnmarshalText ¶
func (i *CandidateId) UnmarshalText(text []byte) error
type ElectedLeader ¶
type ElectedLeader struct { Boundary string `bson:"_id" json:"boundary"` // boundary TTLExpire time.Time `bson:"ttlExpire" json:"ttlExpire"` // the leader must reset this value before it expires and another node wins the election LeaderUUID CandidateId `bson:"leaderUUID" json:"leaderUUID"` // unique id generated by each Elector node at startup LeaderHostname string `bson:"leaderHostname" json:"leaderHostname"` // hostname of the leader used by followers to connect to the leader for whatever service it provides LeaderPort uint64 `bson:"leaderPort" json:"leaderPort"` // port of the leader used by followers to connect to the leader for whatever service it provides }
func (ElectedLeader) ConnectionString ¶
func (el ElectedLeader) ConnectionString() string
type Elector ¶
type Elector struct {
// contains filtered or unexported fields
}
func NewElector ¶
func NewElector( ctx context.Context, database *mongostore.DataStore, boundary string, leaderWorker LeaderWorker, followerWorker FollowerWorker, thisInstanceLeaderHostname string, thisInstanceLeaderPort uint64, options ElectorOptions, ) (e *Elector, err error)
NewElector Creates a new instance of Elector for the given boundary. boundary - a unique case-sensitive string (conventionally a path). Only one election can take place in a boundary at a time. database - a mongodb database. Must be shared by all Electors in a boundary. Should be shared by all Electors across all boundaries. leaderWorker - leaderWorker.Start() is called when this instance wins an election. leaderWorker.Close() is called when this instance loses an election followerWorker - followerWorker.Start() is called when this instance loses an election. followerWorker.Close() is called when this instance wins an election thisInstanceLeaderHostname - a hostname that will be passed to followers they can use to connect to a service on the leader, can be empty thisInstanceLeaderPort - a port that will be passed to followers they can use to connect to a service on the leader, can be empty
func (*Elector) GetElectedLeader ¶
func (e *Elector) GetElectedLeader() *ElectedLeader
func (*Elector) Status ¶
func (e *Elector) Status() (status *ElectorStatus)
type ElectorOptions ¶
func NewElectorOptions ¶
func NewElectorOptions() ElectorOptions
type ElectorStatus ¶
type ElectorStatus struct { Id CandidateId `json:"id"` Boundary string `json:"boundary"` Hostname string `json:"hostname"` Port uint64 `json:"port"` IsLeader bool `json:"isLeader"` ElectedLeader *ElectedLeader `json:"electedLeader"` Running bool `json:"running"` }
type FollowerWorker ¶
type FollowerWorker interface { // Start the worker. May be called multiple times in a row. Start(ctx context.Context, thisLeaderUUID CandidateId) // Stop the worker. May be called multiple times in a row. Stop() }
type LeaderWorker ¶
type LeaderWorker interface { // Start the worker and return. You are responsible for managing your own go routine. May be called multiple times in a row. Start(ctx context.Context) // Stop the worker and return. You are responsible for managing your own go routine. May be called multiple times in a row. Stop() }