elector

package
v0.0.0-...-432d548 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const SpecSep = "\n"

SpecSep is the seperator for service spec.

Variables

This section is empty.

Functions

func ResolveMaster

func ResolveMaster(zfs string) (string, error)

ResolveMaster resolves fiber/carbon master http arpc endpoint (host:port) from zookeeper. zfs://xxx/xxx/LeaderElection/$lock-file {endpoint-1\nendpoint-2}

Types

type AppBase

type AppBase interface {
	Start() error
	Recover() error
	Stop()
}

AppBase is the implemented application interface.

type CacheResolver

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

CacheResolver resolve endpoint with cache

func NewCacheResolver

func NewCacheResolver(zfs string) *CacheResolver

NewCacheResolver creates a cache resolver

func (*CacheResolver) AfterCall

func (r *CacheResolver) AfterCall(succ bool)

AfterCall reset cache address if failed.

func (*CacheResolver) Resolve

func (r *CacheResolver) Resolve() (string, error)

Resolve resolves endpoint

type CacheResolverFactory

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

CacheResolverFactory manages a table of cached resolvers

func NewCacheResolverFactory

func NewCacheResolverFactory() *CacheResolverFactory

NewCacheResolverFactory creates a new factory

func (*CacheResolverFactory) Get

Get returns a cache resolver

type ElectApp

type ElectApp struct {
	LostCh <-chan struct{}
	// contains filtered or unexported fields
}

ElectApp is the base election app to use.

func NewElectApp

func NewElectApp(urlRoot string, port int, impl AppBase) (*ElectApp, error)

NewElectApp creates a new elect app.

func (*ElectApp) Elect

func (app *ElectApp) Elect(sigCh chan os.Signal) error

Elect try to elect, wait until it became the leader or error occurs.

func (*ElectApp) GetLeader

func (app *ElectApp) GetLeader() (string, bool, error)

GetLeader return the leader spec. Call this function only if it's not the leader.

func (*ElectApp) IsLeader

func (app *ElectApp) IsLeader() bool

IsLeader check if it's the leader now.

func (*ElectApp) Shutdown

func (app *ElectApp) Shutdown() error

Shutdown shuts the app.

type ElectOptions

type ElectOptions struct {
	Backend     string
	Hosts       []string
	Key         string
	Val         string
	ConnTimeout int
	LostTimeout int
}

ElectOptions is the election options.

func ParseElectOptions

func ParseElectOptions(urlStr string) (*ElectOptions, error)

ParseElectOptions parse election options from a url query string.

type Elector

type Elector interface {
	GetLeader() (string, error)
	IsLeader() bool
	Elect(stopChan chan struct{}) (<-chan struct{}, error)
	Close() error
}

Elector is the elector api.

func NewElector

func NewElector(opts *ElectOptions) (Elector, error)

NewElector creates a new elector.

type NopElector

type NopElector struct {
}

NopElector is a test nop election implementation.

func (NopElector) Close

func (n NopElector) Close() error

Close close.

func (NopElector) Elect

func (n NopElector) Elect(stopChan chan struct{}) (<-chan struct{}, error)

Elect try to elect the leader.

func (NopElector) GetLeader

func (n NopElector) GetLeader() (string, error)

GetLeader get the leader spec.

func (NopElector) IsLeader

func (n NopElector) IsLeader() bool

IsLeader check if it's the leader.

Jump to

Keyboard shortcuts

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