Documentation
¶
Index ¶
- type Acceptor
- func (a *Acceptor) Accept(ctx context.Context, req *paxosv1.AcceptRequest) (*paxosv1.AcceptedResponse, error)
- func (a *Acceptor) Prepare(ctx context.Context, req *paxosv1.PrepareRequest) (*paxosv1.PromiseResponse, error)
- func (a *Acceptor) SetValidator(v func(ctx context.Context, req *paxosv1.AcceptRequest) error)
- type Cell
- func (c *Cell) ApplyMembershipChange(value []byte)
- func (c *Cell) CatchUp(ctx context.Context, p PeerClient, key string)
- func (c *Cell) GetActivePeers() []PeerClient
- func (c *Cell) GetStore() *state.Store
- func (c *Cell) GetSyncState() (map[string]uint64, error)
- func (c *Cell) PingPeers(ctx context.Context)
- func (c *Cell) Propose(ctx context.Context, key string, value []byte, qt QuorumType) error
- func (c *Cell) ProposeMembership(ctx context.Context, agentID string, info state.PeerInfo) error
- func (c *Cell) ProposeRemoval(ctx context.Context, agentID string) error
- func (c *Cell) SetLockChecker(checker func(ctx context.Context, key string) error)
- func (c *Cell) SetPeers(peers []PeerClient)
- func (c *Cell) SetSelfAddress(grpcAddr, httpURL string)
- func (c *Cell) SetSelfInfo(info state.PeerInfo)
- func (c *Cell) StartEndpointSyncLoop(ctx context.Context, interval time.Duration)
- func (c *Cell) StartPingLoop(ctx context.Context, interval time.Duration)
- func (c *Cell) StartSelfCheckLoop(ctx context.Context, interval time.Duration)
- func (c *Cell) StartSyncLoop(ctx context.Context, interval time.Duration)
- func (c *Cell) SyncWithPeers(ctx context.Context)
- func (c *Cell) TriggerShutdown()
- type ConnectionInfo
- type MembershipChange
- type PeerClient
- type PeerFactory
- type Proposer
- type QuorumType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Acceptor ¶
type Acceptor struct {
// contains filtered or unexported fields
}
Acceptor handles the receiving end of the Paxos protocol, promising and accepting proposals.
func NewAcceptor ¶
NewAcceptor creates and returns a new Acceptor. agentID is the ID of the acceptor, and store is the database to use.
func (*Acceptor) Accept ¶
func (a *Acceptor) Accept(ctx context.Context, req *paxosv1.AcceptRequest) (*paxosv1.AcceptedResponse, error)
Accept processes an AcceptRequest (Phase 2a) and determines whether to accept the proposed value (Phase 2b).
func (*Acceptor) Prepare ¶
func (a *Acceptor) Prepare(ctx context.Context, req *paxosv1.PrepareRequest) (*paxosv1.PromiseResponse, error)
Prepare processes a PrepareRequest (Phase 1a) and determines whether to issue a promise (Phase 1b).
func (*Acceptor) SetValidator ¶
SetValidator configures a validation hook for AcceptRequests.
type Cell ¶
type Cell struct {
ShutdownChan chan struct{}
// contains filtered or unexported fields
}
Cell coordinates the Paxos consensus process for this agent, managing communication with peers, handling proposals, and maintaining state.
func (*Cell) ApplyMembershipChange ¶
ApplyMembershipChange updates the local state to reflect a new cluster membership map.
func (*Cell) CatchUp ¶
func (c *Cell) CatchUp(ctx context.Context, p PeerClient, key string)
CatchUp fetches the latest value of a specific key from a peer and applies it locally.
func (*Cell) GetActivePeers ¶
func (c *Cell) GetActivePeers() []PeerClient
GetActivePeers returns a snapshot of the current connected peers.
func (*Cell) GetSyncState ¶
GetSyncState retrieves a map of all keys and their highest known consensus version numbers.
func (*Cell) Propose ¶
Propose attempts to reach consensus on updating a key with a new value using the specified quorum constraint. It automatically retries on concurrent modification errors.
func (*Cell) ProposeMembership ¶
ProposeMembership initiates a proposal to add or update an agent's membership in the cluster.
func (*Cell) ProposeRemoval ¶
ProposeRemoval initiates a proposal to remove an agent from the cluster's membership.
func (*Cell) SetLockChecker ¶
SetLockChecker configures an optional hook for checking locks during proposals.
func (*Cell) SetPeers ¶
func (c *Cell) SetPeers(peers []PeerClient)
SetPeers directly sets the internal list of connected peers.
func (*Cell) SetSelfAddress ¶
SetSelfAddress updates the node's own address information.
func (*Cell) SetSelfInfo ¶
func (*Cell) StartEndpointSyncLoop ¶
StartEndpointSyncLoop periodically requests updated endpoints for missing peers from active peers.
func (*Cell) StartPingLoop ¶
StartPingLoop periodically triggers liveness checks and endpoint updates for all active peers.
func (*Cell) StartSelfCheckLoop ¶
func (*Cell) StartSyncLoop ¶
StartSyncLoop periodically triggers synchronization of state with all active peers.
func (*Cell) SyncWithPeers ¶
SyncWithPeers exchanges version information with peers and downloads updated data if a peer has a more recent version of any key.
func (*Cell) TriggerShutdown ¶
func (c *Cell) TriggerShutdown()
type ConnectionInfo ¶
type ConnectionInfo struct {
// GRPCAddr is the host:port for gRPC communication.
GRPCAddr string
// HTTPURL is the base URL for the agent's HTTP dashboard.
HTTPURL string
}
ConnectionInfo encapsulates network connection details for an agent.
type MembershipChange ¶
type MembershipChange struct {
// Action is the type of change (e.g. "add", "remove").
Action string `json:"action"`
// AgentID is the ID of the agent being changed.
AgentID string `json:"agent_id"`
// Address is the address of the agent being added.
Address string `json:"address"`
}
MembershipChange describes a cluster membership change.
type PeerClient ¶
type PeerClient interface {
// Prepare sends a PrepareRequest to the remote peer.
Prepare(ctx context.Context, req *paxosv1.PrepareRequest) (*paxosv1.PromiseResponse, error)
// Accept sends an AcceptRequest to the remote peer.
Accept(ctx context.Context, req *paxosv1.AcceptRequest) (*paxosv1.AcceptedResponse, error)
// JoinCluster requests the remote peer to allow this agent to join the cluster.
JoinCluster(ctx context.Context, req *paxosv1.JoinClusterRequest) (*paxosv1.JoinClusterResponse, error)
// Sync synchronizes data with the remote peer.
Sync(ctx context.Context, req *paxosv1.SyncRequest) (*paxosv1.SyncResponse, error)
// GetKVEntry retrieves a key-value entry from the remote peer.
GetKVEntry(ctx context.Context, req *paxosv1.GetKVEntryRequest) (*paxosv1.GetKVEntryResponse, error)
// Ping sends a PingRequest to check if the peer is alive.
Ping(ctx context.Context, req *paxosv1.PingRequest) (*paxosv1.PingResponse, error)
// GetPeerEndpoints fetches endpoint information from the peer.
GetPeerEndpoints(ctx context.Context, req *paxosv1.GetPeerEndpointsRequest) (*paxosv1.GetPeerEndpointsResponse, error)
// AgentID returns the ID of the remote peer.
AgentID() string
// Close terminates the connection to the peer.
Close() error
}
PeerClient represents an interface for communicating with a remote Paxos peer.
type PeerFactory ¶
type PeerFactory func(agentID, address string) (PeerClient, error)
PeerFactory creates a PeerClient given an agent ID and address.
type Proposer ¶
type Proposer struct {
// contains filtered or unexported fields
}
Proposer coordinates the proposal process for the Paxos protocol across the cluster.
func NewProposer ¶
func NewProposer(agentID string, ident *identity.Identity, peers []PeerClient, acceptor *Acceptor) *Proposer
NewProposer constructs a new Proposer.
type QuorumType ¶
type QuorumType int
QuorumType indicates the required level of agreement for a successful proposal.
const ( // QuorumMajority requires consensus from >50% of nodes. QuorumMajority QuorumType = iota // QuorumAll requires consensus from 100% of nodes. QuorumAll )