sync

package
v1.4.9-alpha-3 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

Package sync is an interface for distributed synchronization

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLockTimeout = errors.New("lock timeout")
)

Functions

This section is empty.

Types

type ElectWatcher added in v1.4.8

type ElectWatcher interface {
	// Next is a blocking call
	Next() (*Member, error)
	Close()
}

ElectWatcher watch election event

type Leader

type Leader interface {
	// Id leader node
	Id() string
	// Resign resigns leadership
	Resign() error
	// Observe watch leadership event
	Observe() chan ObserveResult
	// Primary get the info of primary role
	Primary() (*Member, error)
	// Status returns when leadership is lost
	Status() chan bool
}

Leader provides leadership election

type LeaderOption

type LeaderOption func(o *LeaderOptions)

func LeaderId added in v1.0.3

func LeaderId(id string) LeaderOption

LeaderId sets the leader id

func LeaderNS added in v0.22.4

func LeaderNS(ns string) LeaderOption

LeaderNS sets the leader namespace

func LeaderTTL added in v0.22.4

func LeaderTTL(t int64) LeaderOption

LeaderTTL sets the leader ttl

type LeaderOptions

type LeaderOptions struct {
	TTL       int64
	Namespace string
	Id        string
}

type ListMembersOption added in v0.22.3

type ListMembersOption func(o *ListMembersOptions)

func MemberNS added in v0.22.4

func MemberNS(ns string) ListMembersOption

MemberNS sets the list member namespace

type ListMembersOptions added in v0.22.3

type ListMembersOptions struct {
	Namespace string
}

type LockOption

type LockOption func(o *LockOptions)

func LockTTL

func LockTTL(t time.Duration) LockOption

LockTTL sets the lock ttl

func LockWait

func LockWait(t time.Duration) LockOption

LockWait sets the wait time

type LockOptions

type LockOptions struct {
	TTL  time.Duration
	Wait time.Duration
}

type Member added in v0.22.3

type Member struct {
	Leader    string `json:"leader"`
	Id        string `json:"id"`
	Namespace string `json:"namespace"`
	Role      Role   `json:"role"`
}

type ObserveResult added in v1.4.8

type ObserveResult struct {
	Namespace string `json:"namespace"`
	Id        string `json:"id"`
}

type Option

type Option func(o *Options)

func Nodes

func Nodes(a ...string) Option

Nodes sets the addresses to use

func Prefix

func Prefix(p string) Option

Prefix sets a prefix to any lock ids used

type Options

type Options struct {
	Nodes  []string
	Prefix string
}

type Role added in v0.22.3

type Role string
const (
	Primary Role = "primary"
	Follow  Role = "follow"
)

type Sync

type Sync interface {
	// Init Initialise options
	Init(...Option) error
	// Options Return the options
	Options() Options
	// Leader Elect a leader
	Leader(ctx context.Context, name string, opts ...LeaderOption) (Leader, error)
	// ListMembers get all election member
	ListMembers(ctx context.Context, opts ...ListMembersOption) ([]*Member, error)
	// WatchElect watch leader event
	WatchElect(ctx context.Context, opts ...WatchElectOption) (ElectWatcher, error)
	// Lock acquires a lock
	Lock(ctx context.Context, id string, opts ...LockOption) error
	// Unlock releases a lock
	Unlock(ctx context.Context, id string) error
	// String Sync implementation
	String() string
}

Sync is an interface for distributed synchronization

type WatchElectOption added in v1.4.8

type WatchElectOption func(o *WatchElectOptions)

func WatchId added in v1.4.8

func WatchId(id string) WatchElectOption

WatchId sets the watch elector id

func WatchNS added in v1.4.8

func WatchNS(ns string) WatchElectOption

WatchNS sets the watch elector namespace

type WatchElectOptions added in v1.4.8

type WatchElectOptions struct {
	Namespace string
	Id        string
}

Directories

Path Synopsis
Package memory provides a sync.Mutex implementation of the lock for local use
Package memory provides a sync.Mutex implementation of the lock for local use

Jump to

Keyboard shortcuts

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