client

package
v0.0.0-...-a4452f2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultTimeout = 5 * time.Second
	DefaultPort    = 12379
	DefaultServer  = "127.0.0.1"
)

Client defaults

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	KeysAPI etcd.KeysAPI
	// contains filtered or unexported fields
}

Client describes a ETCD configuration client

func NewClient

func NewClient(id string, opts Opts) (*Client, error)

NewClient creates a new ETCD client connection to ETCD servers

func (*Client) GetInt64

func (client *Client) GetInt64(key string) (int64, error)

GetInt64 returns an int64 value from the configuration key

func (*Client) NewElection

func (client *Client) NewElection(path string) MasterElection

NewElection creates a new ETCD master elector

func (*Client) SetInt64

func (client *Client) SetInt64(key string, value int64) error

SetInt64 set an int64 value to the configuration key

func (*Client) Start

func (client *Client) Start()

Start the client

func (*Client) Stop

func (client *Client) Stop()

Stop the client

type MasterElection

type MasterElection interface {
	Start()
	StartAndWait()
	Stop()
	IsMaster() bool
	AddEventListener(listener MasterElectionListener)
	TTL() time.Duration
}

MasterElection describes the master election mechanism

type MasterElectionListener

type MasterElectionListener interface {
	OnStartAsMaster()
	OnStartAsSlave()
	OnSwitchToMaster()
	OnSwitchToSlave()
}

MasterElectionListener describes the multi election mechanism

type MasterElectionService

type MasterElectionService interface {
	NewElection(key string) MasterElection
}

MasterElectionService describes the election service mechanism

type MasterElector

type MasterElector struct {
	insanelock.RWMutex
	EtcdKeyAPI etcd.KeysAPI
	HolderID   string
	// contains filtered or unexported fields
}

MasterElector describes an ETCD master elector

func NewMasterElector

func NewMasterElector(etcdClient *Client, path string) *MasterElector

NewMasterElector creates a new ETCD master elector

func (*MasterElector) AddEventListener

func (le *MasterElector) AddEventListener(listener MasterElectionListener)

AddEventListener registers a new listener

func (*MasterElector) IsMaster

func (le *MasterElector) IsMaster() bool

IsMaster returns true if the current instance is master

func (*MasterElector) Start

func (le *MasterElector) Start()

Start the master election mechanism

func (*MasterElector) StartAndWait

func (le *MasterElector) StartAndWait()

StartAndWait starts the election mechanism and wait for the first election before returning

func (*MasterElector) Stop

func (le *MasterElector) Stop()

Stop the election mechanism

func (*MasterElector) TTL

func (le *MasterElector) TTL() time.Duration

TTL time to live

type Opts

type Opts struct {
	Servers []string
	Timeout time.Duration
	Logger  logging.Logger
}

Opts describes the options of an etcd client

Jump to

Keyboard shortcuts

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