server

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2020 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RoleCandidate represents a candidate
	RoleCandidate = Role(0)

	// RoleFollower represents a follower
	RoleFollower = Role(1)

	// RoleLeader represents a leader
	RoleLeader = Role(2)

	// RoleUnstable represents an unstable elector, which indicate that the user who request
	// the elector's role may retry later.
	// NOTE: the RoleUnstable is NOT a role of elector-state-machine, it is only used
	// for replying user requests when the leader is in leaderBootstrapState state.
	RoleUnstable = Role(5)
)

Variables

This section is empty.

Functions

func NewMasterSlave

func NewMasterSlave(
	stfile string,
	rsIp, rsPort, rsUnixPath string,
	localEleIp, localElePort string,
	remoteEleIp, remoteElePort string,
	opts ...electorOption,
) *msElector

NewmsElector is the constructor of msElector

func NewSinglePoint

func NewSinglePoint(stfile, rsIp, rsPort, rsUnixPath string) *spElector

NewSinglePoint is the constructor of spElector

func WithLeaderTimeout

func WithLeaderTimeout(timeout uint) electorOption

WithLeaderTimeout set how long we thought the leader is unreachable

func WithPingPeriod

func WithPingPeriod(period uint) electorOption

WithPingPeriod set the period among sending ping

func WithProtectionPeriod

func WithProtectionPeriod(period uint) electorOption

WithProtectionPeriod set the period of leader protection

func WithRetryPeriod

func WithRetryPeriod(retryPeriod uint) electorOption

WithRetryPeriod set the retry period for re-connection

Types

type ClusterElector

type ClusterElector struct {
	// contains filtered or unexported fields
}

ClusterElector is used in cluster mode

func NewClusterElector

func NewClusterElector(path, rsIp, rsPort, rsUnixPath string, zkHost []string, zkLeaderDir string, opts ...electorOption) *ClusterElector

NewClusterElector is the constructor of ClusterElector

func (*ClusterElector) Abdicate

func (e *ClusterElector) Abdicate()

Abdicate the leadership

func (*ClusterElector) Info

func (e *ClusterElector) Info() ElectorInfo

Info the elector

func (*ClusterElector) Promote

func (e *ClusterElector) Promote()

Promote as a leader

func (*ClusterElector) Role

func (e *ClusterElector) Role() Role

Role return the role of the elector

func (*ClusterElector) Start

func (e *ClusterElector) Start() error

Start the elector

func (*ClusterElector) Stop

func (e *ClusterElector) Stop() error

Stop the elector

type Elector

type Elector interface {
	Start() error
	Stop() error
	Info() ElectorInfo
	Abdicate()
	Promote()
}

Elector is the interface of all kinds of electors

type ElectorInfo

type ElectorInfo struct {
	// contains filtered or unexported fields
}

ElectorInfo represent basic info for a elector

func (ElectorInfo) String

func (ei ElectorInfo) String() string

type Role

type Role int32

Role represents the role of the elector

func (Role) String

func (r Role) String() string

func (Role) StringShort

func (r Role) StringShort() string

StringShort return a short-form of String()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL