election

package
v0.0.0-...-83adff0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrNotInit init fail
	ErrNotInit = errors.New("init first")
	//ErrFailConn fail to connect
	ErrFailConn = errors.New("fail to connect zk")
)

Functions

This section is empty.

Types

type ZkElection

type ZkElection struct {
	RootPath   string
	NodePath   string
	MasterPath string
	IsMaster   bool
	// wait for this channel, true means master, false means follower
	C <-chan bool
	// contains filtered or unexported fields
}

ZkElection election by zk

func New

func New(servers []string, dir string, timeout time.Duration) *ZkElection

New create new ZkElection

func (*ZkElection) Close

func (z *ZkElection) Close()

Close close the election

func (*ZkElection) Elect

func (z *ZkElection) Elect() (err error)

Elect elect for leader wait for the chan, if get a true, mean you are the leader if you already a leader, a false means you are kicked

func (*ZkElection) Init

func (z *ZkElection) Init() (err error)

Init init the elections

dir is root path for election, if dir = "/project", then, election will use "/project/election" as election path
	and node would be "/project/election/n_xxxxxxxx"
if error happens, the election would work

Jump to

Keyboard shortcuts

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