Documentation

Overview

Package cluster manages etcd cluster.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	Started time.Time

	LeadIdx int
	Members []*Member
	// contains filtered or unexported fields
}

Cluster contains all embedded etcd Members in the same cluster. Configuration is meant to be auto-generated.

func Start

func Start(ccfg Config) (clus *Cluster, err error)

Start starts embedded etcd cluster.

func (*Cluster) ActiveNodeN

func (clus *Cluster) ActiveNodeN() (cnt int)

ActiveNodeN returns the number of Members that are running.

func (*Cluster) Add

func (clus *Cluster) Add() error

Add adds one member.

func (*Cluster) AllConfigs

func (clus *Cluster) AllConfigs() []embed.Config

AllConfigs returns all configurations.

func (*Cluster) AllEndpoints

func (clus *Cluster) AllEndpoints(scheme bool) []string

AllEndpoints returns all endpoints of clients.

func (*Cluster) AllMemberStatus

func (clus *Cluster) AllMemberStatus() []clusterpb.MemberStatus

AllMemberStatus returns all node status.

func (*Cluster) Client

func (clus *Cluster) Client(eps ...string) (*clientv3.Client, *tls.Config, error)

Client creates the client.

func (*Cluster) Config

func (clus *Cluster) Config(i int) embed.Config

Config returns the configuration of the server.

func (*Cluster) Endpoints

func (clus *Cluster) Endpoints(i int, scheme bool) []string

Endpoints returns the endpoints of the node.

func (*Cluster) FindIndex

func (clus *Cluster) FindIndex(ep string) int

FindIndex returns the node index by client URL. It returns -1 if none.

func (*Cluster) InitialCluster

func (clus *Cluster) InitialCluster() string

InitialCluster returns the 'initial-cluster' string.

func (*Cluster) IsStopped

func (clus *Cluster) IsStopped(i int) (stopped bool)

IsStopped returns true if the node has stopped.

func (*Cluster) MemberStatus

func (clus *Cluster) MemberStatus(i int) clusterpb.MemberStatus

MemberStatus returns the node status.

func (*Cluster) Quorum

func (clus *Cluster) Quorum() int

Quorum returns the size of quorum.

func (*Cluster) Remove

func (clus *Cluster) Remove(i int) error

Remove removes the member and its data.

func (*Cluster) Restart

func (clus *Cluster) Restart(i int) error

Restart restarts a node.

func (*Cluster) SetClientDialTimeout

func (clus *Cluster) SetClientDialTimeout(d time.Duration)

SetClientDialTimeout sets the client dial timeout.

func (*Cluster) Shutdown

func (clus *Cluster) Shutdown()

Shutdown stops all Members and deletes all data directories.

func (*Cluster) Size

func (clus *Cluster) Size() int

Size returns the size of cluster.

func (*Cluster) Stop

func (clus *Cluster) Stop(i int)

Stop stops a node.

func (*Cluster) StopNotify

func (clus *Cluster) StopNotify() <-chan struct{}

StopNotify returns receive-only stop channel to notify the cluster has stopped.

func (*Cluster) StoppedStartedAt

func (clus *Cluster) StoppedStartedAt(i int) time.Time

StoppedStartedAt returns the node's last stop and (re)start action time.

func (*Cluster) UpdateMemberStatus

func (clus *Cluster) UpdateMemberStatus()

UpdateMemberStatus updates node statuses.

func (*Cluster) WaitForLeader

func (clus *Cluster) WaitForLeader() error

WaitForLeader waits for cluster to elect a new leader.

type Config

type Config struct {
	Size     int
	RootDir  string
	RootPort int

	EmbeddedClient bool
	PeerTLSInfo    transport.TLSInfo
	PeerAutoTLS    bool
	ClientTLSInfo  transport.TLSInfo
	ClientAutoTLS  bool

	RootCtx     context.Context
	RootCancel  func()
	DialTimeout time.Duration // for client requests
}

Config defines etcd local cluster Configuration.

func (Config) ClientScheme

func (c Config) ClientScheme() string

ClientScheme returns the client scheme. TODO: support unix

func (Config) PeerScheme

func (c Config) PeerScheme() string

PeerScheme returns the peer scheme. TODO: support unix

type Member

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

Member contains *embed.Etcd and its state.

func (*Member) Client

func (m *Member) Client(scheme bool, eps ...string) (cli *clientv3.Client, tlsCfg *tls.Config, err error)

Client creates a client from a member. If 'eps' is not empty, it overwrites clientv3.Config.Endpoints. If 'embedded' is true, it ignores 'scheme' and 'eps' arguments, since it directly connects to a single embedded server.

func (*Member) FetchMemberStatus

func (m *Member) FetchMemberStatus() error

FetchMemberStatus fetches member status (make sure to close the client outside of this function).

func (*Member) Restart

func (m *Member) Restart() error

Restart restarts the member.

func (*Member) Start

func (m *Member) Start() error

Start starts the member.

func (*Member) Stop

func (m *Member) Stop()

Stop stops the member.

func (*Member) WaitForLeader

func (m *Member) WaitForLeader() error

WaitForLeader waits for the member to find a leader.

Directories

Path Synopsis
clusterpb Package clusterpb is a generated protocol buffer package.