raft

package
v1.14.0-rc.12 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoVirtualNodesInPlacementTablesAPILevel = 20
)

Variables

View Source
var ErrNamespaceNotFound = fmt.Errorf("namespace not found")

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

	// Namespace is the namespace of the Dapr runtime host.
	Namespace 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

	// Version of the Actor APIs supported by the Dapr runtime
	APILevel uint32
}

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

func (*DaprHostMember) NamespaceAndName added in v1.14.0

func (d *DaprHostMember) NamespaceAndName() string

type DaprHostMemberState

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

DaprHostMemberState is the wrapper over DaprHostMemberStateData that includes the cluster config and lock

func (*DaprHostMemberState) APILevel added in v1.13.0

func (s *DaprHostMemberState) APILevel() uint32

APILevel returns the current API level of the cluster.

func (*DaprHostMemberState) ForEachHost added in v1.14.0

func (s *DaprHostMemberState) ForEachHost(fn func(*DaprHostMember) bool)

ForEachHost loops through hosts across all namespaces and runs the provided function Early exit can be achieved by returning false from the provided function

func (*DaprHostMemberState) ForEachHostInNamespace added in v1.14.0

func (s *DaprHostMemberState) ForEachHostInNamespace(ns string, fn func(*DaprHostMember) bool)

ForEachHostInNamespace loops through all hosts in a namespace and runs the provided function Early exit can be achieved by returning false from the provided function

func (*DaprHostMemberState) ForEachNamespace added in v1.14.0

func (s *DaprHostMemberState) ForEachNamespace(fn func(string, *daprNamespace) bool)

ForEachNamespace loops through all namespaces and runs the provided function Early exit can be achieved by returning false from the provided function

func (*DaprHostMemberState) Index

func (s *DaprHostMemberState) Index() uint64

func (*DaprHostMemberState) MemberCount added in v1.14.0

func (s *DaprHostMemberState) MemberCount() int

MemberCount returns number of hosts in a namespace

func (*DaprHostMemberState) MemberCountInNamespace added in v1.14.0

func (s *DaprHostMemberState) MemberCountInNamespace(ns string) int

MemberCountInNamespace returns number of hosts in a namespace

func (*DaprHostMemberState) NamespaceCount added in v1.14.0

func (s *DaprHostMemberState) NamespaceCount() int

NamespaceCount returns the number of namespaces in the store

func (*DaprHostMemberState) TableGeneration

func (s *DaprHostMemberState) TableGeneration() uint64

func (*DaprHostMemberState) UpsertRequired added in v1.14.0

func (s *DaprHostMemberState) UpsertRequired(ns string, new *placementv1pb.Host) bool

UpsertRequired checks if the newly reported data matches the saved state, or needs to be updated

type DaprHostMemberStateConfig added in v1.13.0

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

DaprHostMemberStateConfig contains the placement cluster configuration data that needs to be consistent across leader changes

type DaprHostMemberStateData added in v1.4.0

type DaprHostMemberStateData struct {
	// Index is the index number of raft log.
	Index uint64
	// Version of the actor APIs for the cluster
	APILevel uint32
	// TableGeneration is the generation of hashingTableMap.
	// This is increased whenever hashingTableMap is updated.
	TableGeneration uint64
	Namespace       map[string]*daprNamespace
}

DaprHostMemberStateData is the state that stores Dapr namespace, runtime host and consistent hashing tables data

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 it 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(withVirtualNodes bool, namespace string) *v1pb.PlacementTables

PlacementState returns the current placement tables. the withVirtualNodes parameter is here for backwards compatibility and should be removed in 1.15 TODO in v1.15 remove the withVirtualNodes parameter

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 Options added in v1.11.0

type Options struct {
	ID                string
	InMem             bool
	Peers             []PeerInfo
	LogStorePath      string
	Clock             clock.Clock
	ReplicationFactor int64
	MinAPILevel       uint32
	MaxAPILevel       uint32
	Healthz           healthz.Healthz
	Security          security.Provider
	Config            *raft.Config
}

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(opts Options) *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) GetID added in v1.14.0

func (s *Server) GetID() string

func (*Server) GetRaftBind added in v1.14.0

func (s *Server) GetRaftBind() string

func (*Server) IsLeader

func (s *Server) IsLeader() bool

IsLeader returns true if the current node is leader.

func (*Server) Raft

func (s *Server) Raft(ctx context.Context) (*raft.Raft, error)

Raft returns raft node.

func (*Server) StartRaft

func (s *Server) StartRaft(ctx context.Context) 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