node

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package node implements the Node gRPC service hosted by every Node. It handles cluster state pushes from the Elector, node state queries during Primary election, and split-brain prevention.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ElectorGuard

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

ElectorGuard detects potential split-brain scenarios where two Electors are concurrently pushing cluster state to the same Node.

Detection works by tracking the current and previous Elector IDs along with the timestamp of the most recent handoff. If the previous Elector pushes again within splitBrainWindow of being superseded, the guard rejects the push and logs a split-brain error. After the window elapses, the same sequence (A → B → A) is treated as a normal re-election.

func NewElectorGuard

func NewElectorGuard(logger *slog.Logger) *ElectorGuard

NewElectorGuard creates a new split-brain guard.

func (*ElectorGuard) Check

func (g *ElectorGuard) Check(electorNodeID string) error

Check validates that the given elector node ID is consistent with the expected single-Elector model. If the previous Elector pushes again within splitBrainWindow of being superseded, it indicates two concurrent Electors and the push is rejected. After the window elapses, the returning Elector is accepted as a normal re-election.

type RevisionSource

type RevisionSource interface {
	LatestRevision() (int64, error)
}

RevisionSource provides the latest revision for node state queries.

type Server

type Server struct {
	proto.UnimplementedNodeServer
	// contains filtered or unexported fields
}

Server implements the proto.NodeServer gRPC interface. It is hosted by every Node and called by the Elector for cluster state pushes and node state queries during Primary election.

func NewServer

func NewServer(
	logger *slog.Logger,
	nodeID string,
	startTime int64,
	state *nodestate.State,
	db RevisionSource,
	peers *peerclient.Manager,
	watches WatchRevisionSource,
) *Server

NewServer creates a new Node gRPC server.

func (*Server) GetMinWatchRevision

func (s *Server) GetMinWatchRevision(_ context.Context, _ *emptypb.Empty) (*proto.MinWatchRevisionResponse, error)

GetMinWatchRevision returns the minimum revision across all active watches on this node. If no watches are active, the current committed revision is returned instead, indicating that this node has no outstanding watchers/watches below that point.

func (*Server) GetNodeState

func (s *Server) GetNodeState(_ context.Context, _ *emptypb.Empty) (*proto.NodeState, error)

GetNodeState returns the current node state triple, latest revision, and start time. Called by the Elector during primary election.

func (*Server) PushClusterState

func (s *Server) PushClusterState(ctx context.Context, req *proto.ClusterState) (*emptypb.Empty, error)

PushClusterState receives and applies a cluster state update from the Elector. It validates the update, checks for split-brain, converts the proto message to the internal type, and delegates to the applier.

func (*Server) SendCompactionNotice

func (s *Server) SendCompactionNotice(_ context.Context, req *proto.CompactionNotice) (*proto.CompactionNoticeResponse, error)

SendCompactionNotice handles a compaction notice from the Primary. It atomically raises the watch-admission floor to the proposed compaction revision and validates that no active watch would be invalidated. Returns confirmed=true on success, confirmed=false if an active watch exists below the proposed revision.

type WatchRevisionSource

type WatchRevisionSource interface {
	MinWatchRevision() int64
	SetWatchAdmissionFloor(revision int64) error
}

WatchRevisionSource provides the minimum watch revision across all active watches on this node. Returns -1 when no watches are active. It also supports setting the watch-admission floor for the compaction notice protocol.

Jump to

Keyboard shortcuts

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