cluster

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrActorNotFound is return when an actor is not found
	ErrActorNotFound = errors.New("actor not found")
	// ErrPeerSyncNotFound is returned when a peerSync record is not found
	ErrPeerSyncNotFound = errors.New("peerSync record not found")
)

Functions

This section is empty.

Types

type Engine

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

Engine represents the Engine

func NewEngine

func NewEngine(name string, disco discovery.Provider, host *discovery.Node, opts ...Option) (*Engine, error)

NewEngine creates an instance of cluster Engine

func (*Engine) AdvertisedAddress

func (n *Engine) AdvertisedAddress() string

AdvertisedAddress returns the cluster node cluster address that is known by the peers in the cluster

func (*Engine) Events

func (n *Engine) Events() <-chan *Event

Events returns a channel where cluster events are published

func (*Engine) GetActor

func (n *Engine) GetActor(ctx context.Context, actorName string) (*internalpb.WireActor, error)

GetActor fetches an actor from the Node

func (*Engine) GetPartition

func (n *Engine) GetPartition(actorName string) int

GetPartition returns the partition where a given actor is stored

func (*Engine) GetState added in v2.1.0

func (n *Engine) GetState(ctx context.Context, peerAddress string) (*internalpb.PeerState, error)

GetState fetches a given peer state

func (*Engine) Host added in v2.1.0

func (n *Engine) Host() string

Host returns the Node Host

func (*Engine) IsLeader added in v2.1.0

func (n *Engine) IsLeader(ctx context.Context) bool

IsLeader states whether the given cluster node is a leader or not at a given point in time in the cluster

func (*Engine) KeyExists

func (n *Engine) KeyExists(ctx context.Context, key string) (bool, error)

KeyExists checks the existence of a given key

func (*Engine) Peers

func (n *Engine) Peers(ctx context.Context) ([]*Peer, error)

Peers returns a channel containing the list of peers at a given time

func (*Engine) PutActor

func (n *Engine) PutActor(ctx context.Context, actor *internalpb.WireActor) error

PutActor pushes to the cluster the peer sync request

func (*Engine) RemotingPort added in v2.1.0

func (n *Engine) RemotingPort() int

RemotingPort returns the Node remoting port

func (*Engine) RemoveActor

func (n *Engine) RemoveActor(ctx context.Context, actorName string) error

RemoveActor removes a given actor from the cluster. An actor is removed from the cluster when this actor has been passivated.

func (*Engine) SetKey

func (n *Engine) SetKey(ctx context.Context, key string) error

SetKey sets a given key to the cluster

func (*Engine) Start

func (n *Engine) Start(ctx context.Context) error

Start starts the Engine.

func (*Engine) Stop

func (n *Engine) Stop(ctx context.Context) error

Stop stops the Engine gracefully

func (*Engine) UnsetKey added in v2.1.0

func (n *Engine) UnsetKey(ctx context.Context, key string) error

UnsetKey unsets the already set given key in the cluster

type Event

type Event struct {
	Payload *anypb.Any
	Type    EventType
}

Event defines the cluster event

type EventType

type EventType int
const (
	NodeJoined EventType = iota
	NodeLeft
)

func (EventType) String

func (x EventType) String() string

type Interface

type Interface interface {
	// Start starts the cluster engine
	Start(ctx context.Context) error
	// Stop stops the cluster engine
	Stop(ctx context.Context) error
	// Host returns the cluster startNode host address
	Host() string
	// RemotingPort returns the cluster remoting port
	RemotingPort() int
	// PutActor replicates onto the Node the metadata of an actor
	PutActor(ctx context.Context, actor *internalpb.WireActor) error
	// GetActor fetches an actor from the Node
	GetActor(ctx context.Context, actorName string) (*internalpb.WireActor, error)
	// GetPartition returns the partition where a given actor is stored
	GetPartition(actorName string) int
	// SetKey sets a given key to the cluster
	SetKey(ctx context.Context, key string) error
	// KeyExists checks the existence of a given key
	KeyExists(ctx context.Context, key string) (bool, error)
	// UnsetKey unsets the already set given key in the cluster
	UnsetKey(ctx context.Context, key string) error
	// RemoveActor removes a given actor from the cluster.
	// An actor is removed from the cluster when this actor has been passivated.
	RemoveActor(ctx context.Context, actorName string) error
	// Events returns a channel where cluster events are published
	Events() <-chan *Event
	// AdvertisedAddress returns the cluster node cluster address that is known by the
	// peers in the cluster
	AdvertisedAddress() string
	// Peers returns a channel containing the list of peers at a given time
	Peers(ctx context.Context) ([]*Peer, error)
	// GetState fetches a given peer state
	GetState(ctx context.Context, peerAddress string) (*internalpb.PeerState, error)
	// IsLeader states whether the given cluster node is a leader or not at a given
	// point in time in the cluster
	IsLeader(ctx context.Context) bool
}

Interface defines the Node interface

type Option

type Option interface {
	// Apply sets the Option value of a config.
	Apply(cl *Engine)
}

Option is the interface that applies a configuration option.

func WithHasher

func WithHasher(hasher hash.Hasher) Option

WithHasher sets the custom hasher

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger sets the logger

func WithMinimumPeersQuorum

func WithMinimumPeersQuorum(count uint32) Option

WithMinimumPeersQuorum sets the minimum number of nodes to form a quorum

func WithPartitionsCount

func WithPartitionsCount(count uint64) Option

WithPartitionsCount sets the total number of partitions

func WithReadTimeout

func WithReadTimeout(timeout time.Duration) Option

WithReadTimeout sets the Node read timeout. This timeout specifies the timeout of a data retrieval

func WithReplicaCount added in v2.1.0

func WithReplicaCount(count uint32) Option

WithReplicaCount sets replica count

func WithShutdownTimeout

func WithShutdownTimeout(timeout time.Duration) Option

WithShutdownTimeout sets the Node shutdown timeout.

func WithWriteTimeout

func WithWriteTimeout(timeout time.Duration) Option

WithWriteTimeout sets the Node write timeout. This timeout specifies the timeout of a data replication

type OptionFunc

type OptionFunc func(eng *Engine)

OptionFunc implements the Option interface.

func (OptionFunc) Apply

func (f OptionFunc) Apply(c *Engine)

Apply applies the Node's option

type Peer

type Peer struct {
	// Host represents the peer address.
	Host string
	// Port represents the peer port
	Port int
	// Coordinator states that the given peer is the leader not.
	// A peer is a coordinator when it is the oldest node in the cluster
	Coordinator bool
}

Peer defines the peer info

Jump to

Keyboard shortcuts

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