raft

package
v1.10.5-rc.1 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandType

type CommandType uint8

CommandType is the type of raft command in log entry.

const (
	// MemberUpsert is the command to update or insert new or existing member info.
	MemberUpsert CommandType = 0
	// MemberRemove is the command to remove member from actor host member state.
	MemberRemove CommandType = 1

	// TableDisseminate is the reserved command for dissemination loop.
	TableDisseminate CommandType = 100
)

type DaprHostMember

type DaprHostMember struct {
	// Name is the unique name of Dapr runtime host.
	Name string
	// AppID is Dapr runtime app ID.
	AppID string
	// Entities is the list of Actor Types which this Dapr runtime supports.
	Entities []string

	// UpdatedAt is the last time when this host member info is updated.
	UpdatedAt int64
}

DaprHostMember represents Dapr runtime actor host member which serve actor types.

type DaprHostMemberState

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

DaprHostMemberState is the state to store Dapr runtime host and consistent hashing tables.

func (*DaprHostMemberState) Index

func (s *DaprHostMemberState) Index() uint64

func (*DaprHostMemberState) Members

func (s *DaprHostMemberState) Members() map[string]*DaprHostMember

func (*DaprHostMemberState) TableGeneration

func (s *DaprHostMemberState) TableGeneration() uint64

type DaprHostMemberStateData added in v1.4.0

type DaprHostMemberStateData struct {
	// Index is the index number of raft log.
	Index uint64
	// Members includes Dapr runtime hosts.
	Members map[string]*DaprHostMember

	// TableGeneration is the generation of hashingTableMap.
	// This is increased whenever hashingTableMap is updated.
	TableGeneration uint64
	// contains filtered or unexported fields
}

type FSM

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

FSM implements a finite state machine that is used along with Raft to provide strong consistency. We implement this outside the Server to avoid exposing this outside the package.

func (*FSM) Apply

func (c *FSM) Apply(log *raft.Log) interface{}

Apply log is invoked once a log entry is committed.

func (*FSM) PlacementState

func (c *FSM) PlacementState() *v1pb.PlacementTables

PlacementState returns the current placement tables.

func (*FSM) Restore

func (c *FSM) Restore(old io.ReadCloser) error

Restore streams in the snapshot and replaces the current state store with a new one based on the snapshot if all goes OK during the restore.

func (*FSM) Snapshot

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

Snapshot is used to support log compaction. This call should return an FSMSnapshot which can be used to save a point-in-time snapshot of the FSM.

func (*FSM) State

func (c *FSM) State() *DaprHostMemberState

State is used to return a handle to the current state.

type PeerInfo

type PeerInfo struct {
	ID      string
	Address string
}

PeerInfo represents raft peer node information.

type Server

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

Server is Raft server implementation.

func New

func New(id string, inMem bool, peers []PeerInfo, logStorePath string) *Server

New creates Raft server node.

func (*Server) ApplyCommand

func (s *Server) ApplyCommand(cmdType CommandType, data DaprHostMember) (bool, error)

ApplyCommand applies command log to state machine to upsert or remove members.

func (*Server) FSM

func (s *Server) FSM() *FSM

FSM returns fsm.

func (*Server) IsLeader

func (s *Server) IsLeader() bool

IsLeader returns true if the current node is leader.

func (*Server) Raft

func (s *Server) Raft() *raft.Raft

Raft returns raft node.

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown shutdown raft server gracefully.

func (*Server) StartRaft

func (s *Server) StartRaft(config *raft.Config) error

StartRaft starts Raft node with Raft protocol configuration. if config is nil, the default config will be used.

Jump to

Keyboard shortcuts

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