Documentation
¶
Index ¶
- Constants
- type Command
- type ConsistentHashPayload
- type FSM
- func (f *FSM) Apply(log *raft.Log) interface{}
- func (f *FSM) GetProxyBlock(hash string) (string, bool)
- func (f *FSM) GetRoundRobinNext(groupName string) uint32
- func (f *FSM) GetWeightedRRState(groupName, proxyName string) (WeightedProxy, bool)
- func (f *FSM) Restore(readCloser io.ReadCloser) error
- func (f *FSM) Snapshot() (raft.FSMSnapshot, error)
- type FSMSnapshot
- type HealthStatus
- type Node
- func (n *Node) AddPeer(ctx context.Context, peerID, peerAddr, grpcAddr string) error
- func (n *Node) AddPeerInternal(ctx context.Context, peerID, peerAddress, grpcAddress string) error
- func (n *Node) Apply(ctx context.Context, data []byte, timeout time.Duration) error
- func (n *Node) GetHealthStatus() HealthStatus
- func (n *Node) GetPeers() []raft.Server
- func (n *Node) GetState() (raft.RaftState, raft.ServerID)
- func (n *Node) LeaveCluster(ctx context.Context) error
- func (n *Node) RemovePeer(ctx context.Context, peerID string) error
- func (n *Node) RemovePeerInternal(ctx context.Context, peerID string) error
- func (n *Node) Shutdown() error
- func (n *Node) StartPeerSynchronizer(ctx context.Context)
- type PeerPayload
- type RoundRobinPayload
- type WeightedProxy
- type WeightedRRBatchPayload
- type WeightedRRPayload
Constants ¶
const ( CommandAddConsistentHashEntry = "ADD_CONSISTENT_HASH_ENTRY" CommandAddRoundRobinNext = "ADD_ROUND_ROBIN_NEXT" CommandUpdateWeightedRR = "UPDATE_WEIGHTED_RR" CommandUpdateWeightedRRBatch = "UPDATE_WEIGHTED_RR_BATCH" CommandAddPeer = "ADD_PEER" CommandRemovePeer = "REMOVE_PEER" RaftLeaderState = raft.Leader LeaderElectionTimeout = 3 * time.Second ApplyTimeout = 2 * time.Second // Timeout for applying commands )
Configuration constants for Raft operations.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶ added in v0.10.2
type Command struct { Type string `json:"type"` Payload interface{} `json:"payload"` }
Command represents a general command structure for all operations.
type ConsistentHashPayload ¶ added in v0.10.2
ConsistentHashPayload represents the payload for consistent hash operations.
type FSM ¶
type FSM struct {
// contains filtered or unexported fields
}
FSM represents the Finite State Machine for the Raft cluster.
func (*FSM) GetProxyBlock ¶
GetProxyBlock safely retrieves the block name for a given hash.
func (*FSM) GetRoundRobinNext ¶ added in v0.10.2
GetRoundRobinNext retrieves the next index for a given group name.
func (*FSM) GetWeightedRRState ¶ added in v0.10.2
func (f *FSM) GetWeightedRRState(groupName, proxyName string) (WeightedProxy, bool)
GetWeightedRRState retrieves the weight for a given group name and proxy name.
type FSMSnapshot ¶
type FSMSnapshot struct {
// contains filtered or unexported fields
}
FSMSnapshot represents a snapshot of the FSM.
func (*FSMSnapshot) Persist ¶
func (f *FSMSnapshot) Persist(sink raft.SnapshotSink) error
Persist writes the FSMSnapshot data to the given SnapshotSink.
func (*FSMSnapshot) Release ¶
func (f *FSMSnapshot) Release()
type HealthStatus ¶ added in v0.10.2
type Node ¶
type Node struct { Fsm *FSM Logger zerolog.Logger Peers []config.RaftPeer // contains filtered or unexported fields }
Node represents a node in the Raft cluster.
func NewRaftNode ¶
NewRaftNode creates and initializes a new Raft node.
func (*Node) AddPeerInternal ¶ added in v0.10.2
AddPeerInternal adds a new peer to the Raft cluster.
func (*Node) GetHealthStatus ¶ added in v0.10.2
func (n *Node) GetHealthStatus() HealthStatus
GetHealthStatus returns the health status of the Raft node.
func (*Node) GetPeers ¶ added in v0.10.2
GetPeers returns the current list of servers in the Raft configuration. If the Raft node is not initialized, it returns an empty slice.
func (*Node) LeaveCluster ¶ added in v0.10.2
LeaveCluster gracefully removes the node from the Raft cluster and performs cleanup.
func (*Node) RemovePeer ¶
RemovePeer removes a peer from the Raft cluster.
func (*Node) RemovePeerInternal ¶ added in v0.10.2
RemovePeerInternal removes a peer from the Raft cluster.
func (*Node) Shutdown ¶
Shutdown gracefully stops the Node by stopping the gRPC server, closing RPC client connections, and shutting down the underlying Raft node. It returns an error if the Raft node fails to shutdown properly, ignoring the ErrRaftShutdown error which indicates the node was already shutdown.
func (*Node) StartPeerSynchronizer ¶ added in v0.10.2
StartPeerSynchronizer starts a goroutine that synchronizes peers between Raft and FSM.
type PeerPayload ¶ added in v0.10.2
type PeerPayload struct { ID string `json:"id"` Address string `json:"address"` GRPCAddress string `json:"grpcAddress"` }
PeerPayload represents the payload for peer operations.
type RoundRobinPayload ¶ added in v0.10.2
type RoundRobinPayload struct { NextIndex uint32 `json:"nextIndex"` GroupName string `json:"groupName"` }
RoundRobinPayload represents the payload for round robin operations.
type WeightedProxy ¶ added in v0.10.2
type WeightedProxy struct { CurrentWeight int `json:"currentWeight"` EffectiveWeight int `json:"effectiveWeight"` }
WeightedProxy represents the weight structure for WeightedRoundRobin operations.
type WeightedRRBatchPayload ¶ added in v0.10.2
type WeightedRRBatchPayload struct { GroupName string `json:"groupName"` Updates map[string]WeightedProxy `json:"updates"` }
WeightedRRBatchPayload represents the payload for batch updates of WeightedRoundRobin operations.
type WeightedRRPayload ¶ added in v0.10.2
type WeightedRRPayload struct { GroupName string `json:"groupName"` ProxyName string `json:"proxyName"` Weight WeightedProxy `json:"weight"` }
WeightedRRPayload represents the payload for WeightedRoundRobin operations.