fsm

package
v0.0.0-...-37eefcc Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSnapshot

func NewSnapshot(data []byte) *snapshot

Types

type Command

type Command struct {
	Operation OperationType `json:"operation,omitempty" bson:"operation,omitempty"`

	// Contains the rest of the data
	Data json.RawMessage `json:"data,omitempty" bson:"data,omitempty"`
}

This is a wrapper to propagate the changes to all nodes

type ConfigFSM

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

TODO: Optimise and check proper concurency

func NewConfigFSM

func NewConfigFSM(
	dht dht.DHT,
	rStore *routestore.RouteStore,
	log *zap.Logger,
) *ConfigFSM

func (*ConfigFSM) Apply

func (c *ConfigFSM) Apply(rlog *raft.Log) interface{}

Apply log is invoked once a log entry is committed. It returns a value which will be made available in the ApplyFuture returned by Raft.Apply method if that method was called on the same Raft node as the FSM.

func (*ConfigFSM) GetLastUpdatedTime

func (c *ConfigFSM) GetLastUpdatedTime() int

func (*ConfigFSM) Restore

func (c *ConfigFSM) Restore(r io.ReadCloser) error

Restore is used to restore an FSM from a Snapshot. It is not called concurrently with any other command. The FSM must discard all previous state.

func (*ConfigFSM) SetChangeHandler

func (c *ConfigFSM) SetChangeHandler(fn func() error)

func (*ConfigFSM) Snapshot

func (c *ConfigFSM) Snapshot() (raft.FSMSnapshot, error)

Snapshot will be called during make snapshot. Snapshot is used to support log compaction.

type ConfigSnapshot

type ConfigSnapshot struct {
	Shards map[dht.ShardID]dht.ShardLocation `json:"slots,omitempty" bson:"slots,omitempty"`
}

ConfigSnapshot is a snapshot of the current state of the node. It is replicated across all the nodes in the cluster with Raft.

type NodeConfig

type NodeConfig interface {
	// Returns the last updated time
	GetLastUpdatedTime() int

	SetChangeHandler(func() error)
}

type OperationType

type OperationType int
const (
	// In this case, the Data will contain the JSON snapshot of DHT map.
	SlotVsNodeChange OperationType = 1

	// Data will contain the JSON snapshot of the DHT map.
	// As opposed to SlotVsNodeChange, this message means that the nodes are being initialised for the first time
	InitialiseNodes OperationType = 2

	// Add route information
	AddRoute OperationType = 3

	// Remove route information
	RemoveRoute OperationType = 4
)

Jump to

Keyboard shortcuts

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