replication

package
v1.52.8 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package replication is the consensus-replication boundary for the Tasks shard manager. Drivers (local, quasar) implement Replicator; the shard manager calls Propose before committing every mutation and installs Subscribe handlers to apply frames received from peers.

The Decision values mirror github.com/luxfi/consensus core/types so the quasar driver can pass them through without reshaping.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRejected = errors.New("replication: frame rejected by quorum")
	ErrTimeout  = errors.New("replication: consensus timeout")
)

ErrRejected and ErrTimeout normalize Replicator failure modes.

Functions

This section is empty.

Types

type Decision

type Decision uint8

Decision is the consensus outcome for a proposed frame.

const (
	DecisionUndecided Decision = iota
	DecisionAccept
	DecisionReject
	DecisionTimeout
)

type Frame

type Frame struct {
	Principal string `json:"principal"` // canonical "org/project/user"
	Namespace string `json:"ns"`
	Seq       uint64 `json:"seq"`
	Op        string `json:"op"`  // "put" | "del"
	Key       string `json:"key"` // canonical key (no org prefix)
	Value     []byte `json:"val,omitempty"`
}

Frame is the wire envelope a Shard ships through consensus. The payload is the application-level mutation; ShardKey routes the frame to the right namespace shard on apply.

type Handler

type Handler func(ctx context.Context, f Frame) error

Handler applies an accepted frame to the local shard.

type LocalReplicator

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

LocalReplicator is the single-node passthrough. Every Propose returns DecisionAccept synchronously and fans the frame out to local subscribers — the same code path the quasar driver uses on accept, so callers cannot tell the difference.

func NewLocal

func NewLocal() *LocalReplicator

NewLocal returns a single-node Replicator.

func (*LocalReplicator) Close

func (r *LocalReplicator) Close() error

Close is a no-op; no resources held.

func (*LocalReplicator) Kind added in v1.52.0

func (r *LocalReplicator) Kind() string

Stats returns counters used by /v1/tasks/cluster. Kind identifies the single-node passthrough driver.

func (*LocalReplicator) Propose

func (r *LocalReplicator) Propose(ctx context.Context, f Frame) (Decision, error)

Propose immediately accepts and dispatches.

func (*LocalReplicator) Stats

func (r *LocalReplicator) Stats() (accepted, rejected, timeouts uint64)

Stats reports accept/reject counts; the local driver has no timeout outcome.

func (*LocalReplicator) Subscribe

func (r *LocalReplicator) Subscribe(h Handler)

Subscribe appends an applier; thread-safe with Propose.

type Replicator

type Replicator interface {
	// Propose ships frame through consensus and returns the decision.
	Propose(ctx context.Context, frame Frame) (Decision, error)
	// Subscribe registers a handler invoked once per accepted frame.
	Subscribe(h Handler)
	// Close releases driver resources.
	Close() error
	// Kind names the driver ("local" | "quasar") for introspection — so the
	// embed handlers never type-switch on a concrete driver, which is what keeps
	// the consensus-backed quasar driver out of this package's import graph (and
	// thus out of hanzoai/base's module graph via pruning).
	Kind() string
	// Stats returns cumulative accept/reject/timeout counts. A driver with no
	// timeout outcome (local) reports timeouts as 0.
	Stats() (accepted, rejected, timeouts uint64)
}

Replicator is the interface every driver implements. Propose blocks until the cluster decides; Subscribe registers an applier called for every accepted frame including those originated locally (so a single code path persists, regardless of leader).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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