Documentation
¶
Overview ¶
Master election algorithm which uses Doozer as a lock server to determine whether or not a process is master.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MasterElectionClient ¶
type MasterElectionClient struct {
// contains filtered or unexported fields
}
Client for the master election procedure using a Doozer lock server. This can be used both in participating mode, where the process can become master, or in passive mode, where the current master may be discovered through the API and master elections may be forced, but the process will not participate in master elections and thus never itself become master.
func NewMasterElectionClient ¶
func NewMasterElectionClient(conn *doozer.Conn, name string, addr net.Addr, participating bool, callback MasterElectionEventReceiver) ( *MasterElectionClient, error)
Create a new master election client for the elections with the given "name". The host and port of the master will be set to "addr". If "participating" is set to true, the client will participate in master elections, otherwise the client will just listen for changes of the current master.
All notifications of being a master or slave will be done on the specified "callback".
func (*MasterElectionClient) ForceMasterElection ¶
func (m *MasterElectionClient) ForceMasterElection() error
Force a master election to take place right now.
func (*MasterElectionClient) GetCurrentMaster ¶
func (m *MasterElectionClient) GetCurrentMaster() string
Get what we think is currently the master. This is a very cheap operation which only reads local state.
Please note that there is no guarantee that the data will still be valid at the time it is used.
func (*MasterElectionClient) ReadCurrentMaster ¶
func (m *MasterElectionClient) ReadCurrentMaster() (string, error)
Force a read of the current master from Doozer. This will not update the internal state as that would confuse the notion of whether we're currently the master or a slave. This operation is rather expensive and GetCurrentMaster should be preferred when possible.
Please note that there is no guarantee that the data will still be valid at the time it is used.
func (*MasterElectionClient) SyncWait ¶
func (m *MasterElectionClient) SyncWait()
Wait synchronously for the master election to exit (basically never).
type MasterElectionEventReceiver ¶
type MasterElectionEventReceiver interface {
// BecomeMaster() will be invoked when the process has been elected as
// master. If an error is returned by BecomeMaster(), a new master
// election will be forced.
BecomeMaster() error
// BecomeSlave() will be invoked every time the master election is lost.
// It may also be invoked right before BecomeMaster() in case a master
// election is forced. The name of the new master will be passed as
// a host:port pair.
//
// It will also be inoked even if the process is already a slave, but
// another master election has taken place. Due to this property,
// BecomeSlave() may be used to receive notifications about changes
// of the master.
BecomeSlave(new_master string)
// This callback will be invoked to report non-fatal errors in the
// master election process to the client.
ElectionError(err error)
// This callback will be invoked to report fatal errors in the master
// election process to the client.
ElectionFatal(err error)
}
Interface for notifying the caller about changes in the master state.
Directories
¶
| Path | Synopsis |
|---|---|
|
Runs a command when a given process becomes master or slave.
|
Runs a command when a given process becomes master or slave. |