paxos

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

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

func NewAcceptor(agentID string, ident *identity.Identity, store *state.Store) *Acceptor

NewAcceptor creates and returns a new Acceptor. agentID is the ID of the acceptor, and store is the database to use.

func (*Acceptor) Accept

Accept processes an AcceptRequest (Phase 2a) and determines whether to accept the proposed value (Phase 2b).

func (*Acceptor) Prepare

Prepare processes a PrepareRequest (Phase 1a) and determines whether to issue a promise (Phase 1b).

func (*Acceptor) SetValidator

func (a *Acceptor) SetValidator(v func(ctx context.Context, req *paxosv1.AcceptRequest) error)

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 NewCell

func NewCell(agentID string, store *state.Store, ident *identity.Identity, acceptor *Acceptor, factory PeerFactory, selfGRPCAddr, selfHTTPURL string) *Cell

func (*Cell) ApplyMembershipChange

func (c *Cell) ApplyMembershipChange(value []byte)

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) GetStore

func (c *Cell) GetStore() *state.Store

GetStore returns the underlying state store.

func (*Cell) GetSyncState

func (c *Cell) GetSyncState() (map[string]uint64, error)

GetSyncState retrieves a map of all keys and their highest known consensus version numbers.

func (*Cell) PingPeers

func (c *Cell) PingPeers(ctx context.Context)

PingPeers performs a one-off ping to all active peers.

func (*Cell) Propose

func (c *Cell) Propose(ctx context.Context, key string, value []byte, qt QuorumType) error

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

func (c *Cell) ProposeMembership(ctx context.Context, agentID string, info state.PeerInfo) error

ProposeMembership initiates a proposal to add or update an agent's membership in the cluster.

func (*Cell) ProposeRemoval

func (c *Cell) ProposeRemoval(ctx context.Context, agentID string) error

ProposeRemoval initiates a proposal to remove an agent from the cluster's membership.

func (*Cell) SetLockChecker

func (c *Cell) SetLockChecker(checker func(ctx context.Context, key string) error)

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

func (c *Cell) SetSelfAddress(grpcAddr, httpURL string)

SetSelfAddress updates the node's own address information.

func (*Cell) SetSelfInfo

func (c *Cell) SetSelfInfo(info state.PeerInfo)

func (*Cell) StartEndpointSyncLoop

func (c *Cell) StartEndpointSyncLoop(ctx context.Context, interval time.Duration)

StartEndpointSyncLoop periodically requests updated endpoints for missing peers from active peers.

func (*Cell) StartPingLoop

func (c *Cell) StartPingLoop(ctx context.Context, interval time.Duration)

StartPingLoop periodically triggers liveness checks and endpoint updates for all active peers.

func (*Cell) StartSelfCheckLoop

func (c *Cell) StartSelfCheckLoop(ctx context.Context, interval time.Duration)

func (*Cell) StartSyncLoop

func (c *Cell) StartSyncLoop(ctx context.Context, interval time.Duration)

StartSyncLoop periodically triggers synchronization of state with all active peers.

func (*Cell) SyncWithPeers

func (c *Cell) SyncWithPeers(ctx context.Context)

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.

func (*Proposer) Propose

func (p *Proposer) Propose(ctx context.Context, key string, value []byte, qt QuorumType) ([]byte, error)

Propose executes the full Paxos protocol (Phase 1 and Phase 2) to establish consensus on a value for a key.

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
)

Jump to

Keyboard shortcuts

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