fsm

package
v0.0.0-...-18f39a8 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SubDataTypeAwareType = reflect.TypeOf((*SubDataTypeAware)(nil)).Elem()
	SubDataAwareType     = reflect.TypeOf((*SubDataAware)(nil)).Elem()
)

Functions

This section is empty.

Types

type Distributable

type Distributable interface {
	GetDistributableItems() interface{}
}

Distributable enable the distribution of struct.

type DistributableItem

type DistributableItem interface {
	GetItemID() string
	SetNodeID(string)
}

DistributableItem gives the ID getter.

func GetDistributable

func GetDistributable(dataItem reflect.Value) (DistributableItem, bool)

type DistributeRequest

type DistributeRequest struct {
	Data interface{}
}

func (DistributeRequest) GetSubData

func (s DistributeRequest) GetSubData() interface{}

func (DistributeRequest) Marshal

func (s DistributeRequest) Marshal(t *marshal.TypeRegister) ([]byte, error)

func (*DistributeRequest) Unmarshal

func (s *DistributeRequest) Unmarshal(t *marshal.TypeRegister, d []byte) (err error)

type DistributeService

type DistributeService struct {
	Picker
}

func NewDistributeService

func NewDistributeService(picker Picker) *DistributeService

func (*DistributeService) ApplySnapshot

func (m *DistributeService) ApplySnapshot(nodeID string, input interface{}) error

func (*DistributeService) GetReqDataType

func (m *DistributeService) GetReqDataType() interface{}

func (*DistributeService) NewLog

func (m *DistributeService) NewLog(nodeID string, request interface{}) interface{}

func (*DistributeService) RegisterMarshalTypes

func (m *DistributeService) RegisterMarshalTypes(reg *marshal.TypeRegister)

RegisterMarshalTypes registers the types for marshaling and unmarshaling.

type Distributor

type Distributor struct {
	// StickyMap sticky item to the nodeID.
	StickyMap map[string]string
}

Distributor is the role to charge the distribution among the raft cluster nodes.

func NewDistributor

func NewDistributor() *Distributor

NewDistributor makes a new Distributor.

func (*Distributor) CleanSticky

func (d *Distributor) CleanSticky()

CleanSticky cleans the sticky map state.

func (*Distributor) Distribute

func (d *Distributor) Distribute(shortNodeIds []string, data interface{}) int

Distribute do the distribution.

func (*Distributor) StickTo

func (d *Distributor) StickTo(itemID, shortNodeID string)

StickTo stick a item to a node.

type FSM

type FSM struct {
	RaftLogSum uint64
	// contains filtered or unexported fields
}

func NewRoutingFSM

func NewRoutingFSM(shortNodeID string, services []Service, ser *marshal.TypeRegister) *FSM

func (*FSM) Apply

func (i *FSM) Apply(raftlog *raft.Log) interface{}

func (*FSM) Restore

func (i *FSM) Restore(closer io.ReadCloser) error

func (*FSM) Snapshot

func (i *FSM) Snapshot() (raft.FSMSnapshot, error)

type KvExectable

type KvExectable interface {
	Exec(req KvRequest) interface{}
}

type KvOperate

type KvOperate string
const (
	KvGet KvOperate = "get"
	KvSet KvOperate = "set"
	KvDel KvOperate = "del"
)

type KvRequest

type KvRequest struct {
	Value     interface{}
	KvOperate KvOperate
	MapName   string
	Key       string
}

type Map

type Map struct {
	Data map[string]interface{}
	// contains filtered or unexported fields
}

type MarshalTypesRegister

type MarshalTypesRegister interface {
	// RegisterMarshalTypes registers the types for marshaling and unmarshaling.
	RegisterMarshalTypes(reg *marshal.TypeRegister)
}

type MemKvService

type MemKvService struct {
	Maps map[string]*Map
	// contains filtered or unexported fields
}

func NewMemKvService

func NewMemKvService() *MemKvService

func (*MemKvService) ApplySnapshot

func (m *MemKvService) ApplySnapshot(nodeID string, input interface{}) error

func (*MemKvService) Exec

func (m *MemKvService) Exec(req KvRequest) interface{}

func (*MemKvService) GetReqDataType

func (m *MemKvService) GetReqDataType() interface{}

func (*MemKvService) NewLog

func (m *MemKvService) NewLog(nodeID string, req interface{}) interface{}

func (*MemKvService) RegisterMarshalTypes

func (m *MemKvService) RegisterMarshalTypes(typeRegister *marshal.TypeRegister)

RegisterMarshalTypes registers the types for marshaling and unmarshaling.

type Picker

type Picker interface {
	PickForNode(node string, request interface{})
	MarshalTypesRegister
}

type PickerFn

type PickerFn func(node string, request interface{})

func (PickerFn) PickForNode

func (f PickerFn) PickForNode(node string, request interface{})

type ReqTypeInfo

type ReqTypeInfo struct {
	Service Service
	ReqType reflect.Type
}

func MakeReqTypeInfo

func MakeReqTypeInfo(service Service) ReqTypeInfo

type Service

type Service interface {
	// NewLog is called when a new raft log message is committed in the cluster and matched with any of the GetReqDataTypes returned types
	// in this method we can handle what should happen when we got a new raft log regarding our FSM service
	NewLog(shortNodeID string, request interface{}) interface{}

	// GetReqDataType returns all the request structs which are used by this FSMService
	GetReqDataType() interface{}

	// ApplySnapshot is used to decode and apply a snapshot to the FSMService
	ApplySnapshot(shortNodeID string, input interface{}) error

	MarshalTypesRegister
}

Service interface makes it easier to build State Machines

type Snapshot

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

func (*Snapshot) Persist

func (i *Snapshot) Persist(sink raft.SnapshotSink) error

func (*Snapshot) Release

func (i *Snapshot) Release()

type SubDataAware

type SubDataAware interface {
	GetSubData() interface{}
}

type SubDataTypeAware

type SubDataTypeAware interface {
	GetSubDataType() reflect.Type
}

Jump to

Keyboard shortcuts

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