sync

package
v0.0.0-...-284234c Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2016 License: Apache-2.0 Imports: 3 Imported by: 0

README

Sync interface

The sync interface provides a way to coordinate across a number of nodes. This can be used for leadership election, membership consensus, etc. It's a building block for application synchronization.

We want the ability to choose between CP and AP where CP is useful for transactional and leader behaviour and AP for eventually consistent semantics.

type Sync interface {
        // distributed lock interface
        Lock(...LockOption) (Lock, error)
        // leader election interface
        Leader(...LeaderOption) (Leader, error)
        // Start/Stop the internal publisher
        // used to announce this client and
        // subscribe to announcements.
        Start() error
        Stop() error
}

type Lock interface {
        Id() string
        Acquire() error
        Release() error
}

type Leader interface {
        // Returns the current leader
        Leader() (*registry.Node, error)
        // Elect self to become leader
        Elect() (Elected, error)
        // Returns the status of this node
        Status() (LeaderStatus, error)
}

type Elected interface {
        // Returns a channel which indicates
        // when the leadership is revoked
        Revoked() (chan bool, error)
        // Resign the leadership
        Resign() error
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultNamespace = "/micro/sync"
)

Functions

func NewContext

func NewContext(ctx context.Context, c Sync) context.Context

Types

type Elected

type Elected interface {
	// Returns a channel which indicates
	// when the leadership is revoked
	Revoked() (chan struct{}, error)
	// Resign the leadership
	Resign() error
}

type Leader

type Leader interface {
	// The unique ID to synchronize with
	Id() string
	// Returns the current leader
	Leader() (*registry.Node, error)
	// Elect self to become leader
	Elect() (Elected, error)
	// Returns the status of this node
	Status() (LeaderStatus, error)
}

type LeaderOption

type LeaderOption func(o *LeaderOptions)

type LeaderOptions

type LeaderOptions struct{}

type LeaderStatus

type LeaderStatus int32
const (
	FollowerStatus  LeaderStatus = 0
	CandidateStatus LeaderStatus = 1
	ElectedStatus   LeaderStatus = 2
)

type Lock

type Lock interface {
	// The unique ID to lock on
	Id() string
	// Acquire the lock
	Acquire() error
	// Release the lock
	Release() error
}

type LockOption

type LockOption func(o *LockOptions)

func LockTTL

func LockTTL(t time.Duration) LockOption

func LockWait

func LockWait(t time.Duration) LockOption

type LockOptions

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

type Option

type Option func(o *Options)

func Namespace

func Namespace(n string) Option

func Nodes

func Nodes(nodes ...string) Option

func Service

func Service(s *registry.Service) Option

type Options

type Options struct {
	Namespace string
	Service   *registry.Service
	Nodes     []string
}

type Sync

type Sync interface {
	// distributed lock interface
	Lock(id string, opts ...LockOption) (Lock, error)
	// leader election interface
	Leader(id string, opts ...LeaderOption) (Leader, error)
	// Start/Stop the internal publisher
	// used to announce this client and
	// subscribe to announcements.
	Start() error
	Stop() error
	// Name of sync
	String() string
}

func FromContext

func FromContext(ctx context.Context) (Sync, bool)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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