cluster

package
v1.17.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConcurrentTransaction = errors.New("concurrent transaction")
	ErrInvalidTransaction    = errors.New("invalid transaction")
	ErrExpiredTransaction    = errors.New("transaction TTL expired")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	OpenTransaction(ctx context.Context, host string, tx *Transaction) error
	AbortTransaction(ctx context.Context, host string, tx *Transaction) error
	CommitTransaction(ctx context.Context, host string, tx *Transaction) error
}

type CommitFn

type CommitFn func(ctx context.Context, tx *Transaction) error

type Config

type Config struct {
	Hostname       string `json:"hostname" yaml:"hostname"`
	GossipBindPort int    `json:"gossipBindPort" yaml:"gossipBindPort"`
	DataBindPort   int    `json:"dataBindPort" yaml:"dataBindPort"`
	Join           string `json:"join" yaml:"join"`
}

type ConsensusFn

type ConsensusFn func(ctx context.Context,
	in []*Transaction) (*Transaction, error)

The Broadcaster is the link between the the current node and all other nodes during a tx operation. This makes it a natural place to inject a consensus function for read transactions. How consensus is reached is completely opaque to the broadcaster and can be controlled through custom business logic.

type HostnameSource

type HostnameSource interface {
	AllNames() []string
}

type MemberLister

type MemberLister interface {
	Hostnames() []string
}

type NodeIterationStrategy

type NodeIterationStrategy int
const (
	StartRandom NodeIterationStrategy = iota
	StartAfter
)

type NodeIterator

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

func NewNodeIterator

func NewNodeIterator(source HostnameSource,
	strategy NodeIterationStrategy,
) (*NodeIterator, error)

func (*NodeIterator) Next

func (n *NodeIterator) Next() string

func (*NodeIterator) SetStartNode

func (n *NodeIterator) SetStartNode(startNode string)

type Remote

type Remote interface {
	BroadcastTransaction(ctx context.Context, tx *Transaction) error
	BroadcastAbortTransaction(ctx context.Context, tx *Transaction) error
	BroadcastCommitTransaction(ctx context.Context, tx *Transaction) error
}

type ResponseFn

type ResponseFn func(ctx context.Context, tx *Transaction) error

type State

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

func Init

func Init(userConfig Config, logger logrus.FieldLogger) (*State, error)

func (*State) AllHostnames

func (s *State) AllHostnames() []string

AllHostnames for live members, including self.

func (*State) AllNames

func (s *State) AllNames() []string

All node names (not their hostnames!) for live members, including self.

func (*State) ClusterHealthScore

func (s *State) ClusterHealthScore() int

func (*State) Hostnames

func (s *State) Hostnames() []string

Hostnames for all live members, except self. Use AllHostnames to include self, prefixes the data port.

func (*State) LocalName

func (s *State) LocalName() string

func (*State) NodeCount

func (s *State) NodeCount() int

All node names (not their hostnames!) for live members, including self.

func (*State) NodeHostname

func (s *State) NodeHostname(nodeName string) (string, bool)

type Transaction

type Transaction struct {
	ID       string
	Type     TransactionType
	Payload  interface{}
	Deadline time.Time
}

type TransactionType

type TransactionType string

type TxBroadcaster

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

func NewTxBroadcaster

func NewTxBroadcaster(state MemberLister, client Client) *TxBroadcaster

func (*TxBroadcaster) BroadcastAbortTransaction

func (t *TxBroadcaster) BroadcastAbortTransaction(ctx context.Context, tx *Transaction) error

func (*TxBroadcaster) BroadcastCommitTransaction

func (t *TxBroadcaster) BroadcastCommitTransaction(ctx context.Context, tx *Transaction) error

func (*TxBroadcaster) BroadcastTransaction

func (t *TxBroadcaster) BroadcastTransaction(ctx context.Context, tx *Transaction) error

func (*TxBroadcaster) SetConsensusFunction

func (t *TxBroadcaster) SetConsensusFunction(fn ConsensusFn)

type TxManager

type TxManager struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewTxManager

func NewTxManager(remote Remote, logger logrus.FieldLogger) *TxManager

func (*TxManager) BeginTransaction

func (c *TxManager) BeginTransaction(ctx context.Context, trType TransactionType,
	payload interface{}, ttl time.Duration,
) (*Transaction, error)

Begin a Transaction with the specified type and payload. Transactions expire after the specified TTL. For a transaction that does not ever expire, pass in a ttl of 0. When choosing TTLs keep in mind that clocks might be slightly skewed in the cluster, therefore set your TTL for desiredTTL + toleratedClockSkew

func (*TxManager) CloseReadTransaction

func (c *TxManager) CloseReadTransaction(ctx context.Context,
	tx *Transaction,
) error

func (*TxManager) CommitWriteTransaction

func (c *TxManager) CommitWriteTransaction(ctx context.Context,
	tx *Transaction,
) error

func (*TxManager) IncomingAbortTransaction

func (c *TxManager) IncomingAbortTransaction(ctx context.Context,
	tx *Transaction,
)

func (*TxManager) IncomingBeginTransaction

func (c *TxManager) IncomingBeginTransaction(ctx context.Context,
	tx *Transaction,
) error

func (*TxManager) IncomingCommitTransaction

func (c *TxManager) IncomingCommitTransaction(ctx context.Context,
	tx *Transaction,
) error

func (*TxManager) SetCommitFn

func (c *TxManager) SetCommitFn(fn CommitFn)

SetCommitFn sets a function that is used in Write Transactions, you can read from the transaction payload and use that state to alter your local state

func (*TxManager) SetResponseFn

func (c *TxManager) SetResponseFn(fn ResponseFn)

SetResponseFn sets a function that is used in Read Transactions. The function sets the local state (by writing it into the Tx Payload). It can then be sent to other nodes. Consensus is not part of the ResponseFn. The coordinator - who initiated the Tx - is responsible for coming up with consensus. Deciding on Consensus requires insights into business logic, as from the TX's perspective payloads are opaque.

Jump to

Keyboard shortcuts

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