replica

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 20 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package replica adapts native metadata transactions to a shared application authority. The authority owns consensus; the adapter owns its native engine.

Index

Constants

View Source
const EventualRPCMessageBytes = 64 << 20
View Source
const EventualRPCVersion = 1
View Source
const EventualSnapshotChunkBytes = 1 << 20

Variables

View Source
var (
	ErrEventualIdentity = errors.New("eventual replication identity mismatch")
	ErrEventualAck      = errors.New("invalid eventual replication acknowledgement")
	ErrEventualClosed   = errors.New("eventual replication closed")
)
View Source
var (
	ErrReplicaStoreUnavailable = errors.New("replica store unavailable; close and reopen to recover")
	ErrReplicaSnapshotStale    = errors.New("snapshot precedes applied replica mutations")
)

Functions

This section is empty.

Types

type Engine

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

Engine records deterministic metadata edits in the common authority log. It deliberately does not implement meta.AsyncUpdater: namespace RAM must not publish changes before commit and local application are confirmed.

func NewEngine

func NewEngine(base meta.Engine, authority *clustermeta.Authority, domain string) (*Engine, error)

NewEngine registers the domain state machine and native watermark. On success it transfers ownership of base; the authority remains borrowed.

func (*Engine) Apply

func (e *Engine) Apply(ctx context.Context, seq uint64, payload []byte) error

Apply persists edits and their native watermark before the authority can confirm application. Metadata owns the durable batch format and validation.

func (*Engine) Barrier

func (e *Engine) Barrier(ctx context.Context) error

func (*Engine) Base

func (e *Engine) Base() meta.Engine

Base returns the borrowed native engine for capture inside an existing authority barrier. Direct reads bypass the service gate.

func (*Engine) Close

func (e *Engine) Close() error

func (*Engine) Snapshot

func (e *Engine) Snapshot(ctx context.Context, w io.Writer) error

Snapshot requires an existing authority barrier. It snapshots base directly so coordinated capture cannot recursively acquire the authority gate.

func (*Engine) Sync

func (e *Engine) Sync(ctx context.Context) error

func (*Engine) Update

func (e *Engine) Update(ctx context.Context, fn func(meta.Tx) error) error

func (*Engine) View

func (e *Engine) View(ctx context.Context, fn func(meta.ReadTx) error) error

type EventualAck

type EventualAck struct {
	EventualStatus
	EventID string `json:"event_id"`
	Hash    string `json:"hash"`
}

type EventualHome

type EventualHome struct {
	Domain          string `json:"domain"`
	HomeIncarnation string `json:"home_incarnation"`
	HomeEpoch       string `json:"home_epoch"`
}

EventualHome pins a stream to one namespace and Home generation. A new generation requires explicit offline recovery; RPC never promotes a replica.

type EventualReceiver

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

EventualReceiver applies one pinned stream to a borrowed native-only engine. The caller must not serve an existing Namespace RAM view over that engine: applying native transactions does not publish changes into a live Namespace. The caller owns the RPC server/listener and stops it before closing receiver, then closes the engine. Receiver.Close seals admission and joins admitted work.

func NewEventualReceiver

func NewEventualReceiver(ctx context.Context, config EventualReceiverConfig) (*EventualReceiver, error)

func (*EventualReceiver) Close

func (r *EventualReceiver) Close() error

func (*EventualReceiver) HandleRPC

func (r *EventualReceiver) HandleRPC(ctx context.Context, principal cluster.Principal, method string, raw json.RawMessage) (any, error)

type EventualReceiverConfig

type EventualReceiverConfig struct {
	Engine          meta.Engine
	ReplicaID       string
	Home            meta.HomeConfig
	SourcePrincipal string
	Snapshot        *EventualSnapshotReceiverConfig
}

type EventualSender

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

EventualSender owns one peer's RPC connection and serializes delivery. It borrows Outbox and its engine. Construction starts no goroutines or network calls; callers explicitly run Run or CatchUp, then Close before the engine. At most one owned event and one RPC are in flight. Network work never runs inside a Home mutation or its local acknowledgement boundary.

func NewEventualSender

func NewEventualSender(config EventualSenderConfig) (*EventualSender, error)

func (*EventualSender) CatchUp

func (s *EventualSender) CatchUp(ctx context.Context) error

CatchUp drains the currently available backlog, returning the first error. It does not wait for future Home mutations or retry an unavailable peer.

func (*EventualSender) Close

func (s *EventualSender) Close() error

func (*EventualSender) ReplicateOnce

func (s *EventualSender) ReplicateOnce(ctx context.Context) (bool, error)

ReplicateOnce delivers one event or repairs a missing baseline. Exact pending snapshot receipts are reconciled before reading the old outbox cursor, since installed images intentionally contain no historical event deduplication keys.

func (*EventualSender) Run

func (s *EventualSender) Run(ctx context.Context) error

Run drains events and retries transient transport/storage failures until cancelled. Configuration, identity, ordering and acknowledgement failures stop the loop so the owner can explicitly repair the stream.

type EventualSenderConfig

type EventualSenderConfig struct {
	Outbox          *meta.Outbox
	Home            meta.HomeConfig
	ReplicaID       string
	Endpoint        string
	RPC             cluster.RPCClientConfig
	Timeout         time.Duration
	RetryInterval   time.Duration
	SnapshotTimeout time.Duration
	CaptureSnapshot func(context.Context) (*EventualSnapshot, error)
}

type EventualSnapshot

type EventualSnapshot struct {
	Info   meta.MutationSnapshotInfo
	Reader io.ReadCloser
}

EventualSnapshot owns one complete immutable stream. The sender closes Reader on every exit; Close must unblock Read. Capture must release namespace/Home locks before returning it, and its callback must honor cancellation.

type EventualSnapshotAck

type EventualSnapshotAck struct {
	EventualStatus
	Info meta.MutationSnapshotInfo `json:"info"`
}

type EventualSnapshotReceiverConfig

type EventualSnapshotReceiverConfig struct {
	Store     *ReplicaStore
	Directory string
	MaxBytes  uint64
}

EventualSnapshotReceiverConfig enables bounded online installation into the same stable ReplicaStore passed as Engine. Directory owns no preexisting files; each receiver creates and removes its own private upload directory underneath.

type EventualStatus

type EventualStatus struct {
	EventualHome
	Version   int    `json:"version"`
	ReplicaID string `json:"replica_id"`
	Sequence  uint64 `json:"sequence"`
}

type HomeEngine

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

HomeEngine adapts one eventual HomeWriter to Namespace persistence. Every successful Update includes both the metadata and its outbox event in a local durability boundary. It deliberately does not implement meta.AsyncUpdater. Callbacks must not re-enter this engine.

func NewHomeEngine

func NewHomeEngine(ctx context.Context, base meta.Engine, config meta.HomeConfig) (*HomeEngine, error)

NewHomeEngine transfers ownership of base only on success. The Home identity and sequence belong to meta.HomeWriter; this adapter owns serialization of reads, barriers, writes and shutdown. It starts no delivery or network work.

func (*HomeEngine) Barrier

func (e *HomeEngine) Barrier(ctx context.Context) error

Barrier waits for earlier Home mutations, including their durability checks. It does not imply remote delivery or acknowledgements.

func (*HomeEngine) Base

func (e *HomeEngine) Base() meta.Engine

Base returns the borrowed native engine for outbox delivery and coordinated capture. Direct access bypasses Home admission; callers may update delivery bookkeeping but must not mutate namespace data or close it. Stop borrowed users before closing HomeEngine.

func (*HomeEngine) CaptureMutationSnapshot

func (e *HomeEngine) CaptureMutationSnapshot(ctx context.Context, w io.Writer, limits meta.MutationSnapshotLimits) (meta.MutationSnapshotInfo, error)

CaptureMutationSnapshot produces a namespace-only replica bootstrap stream. It excludes Home mutations and shutdown until the borrowed writer returns. The caller must first stop exports or quiesce every file service and drain staged data; this gate alone does not coordinate core or Namespace RAM. Transmission must happen after capture, outside Home admission. Destination errors do not poison Home, but a failed source Sync requires recovery.

func (*HomeEngine) Close

func (e *HomeEngine) Close() error

Close waits for admitted operations, releases Home ownership and closes the native engine exactly once. Borrowed users must already have stopped.

func (*HomeEngine) Position

func (e *HomeEngine) Position(ctx context.Context) (meta.MutationPosition, error)

Position returns the pinned Home identity and locally durable engine cursor. Namespace may still be publishing a completed Update into its RAM indexes; this cursor alone does not establish a Namespace RAM publication boundary.

func (*HomeEngine) Snapshot

func (e *HomeEngine) Snapshot(ctx context.Context, w io.Writer) error

Snapshot captures base while excluding Home mutations and shutdown. Earlier Home updates are already locally durable; the native Snapshotter owns any further source synchronization it requires. A snapshot or destination error does not poison Home admission.

func (*HomeEngine) Sync

func (e *HomeEngine) Sync(ctx context.Context) error

Sync establishes a local durability boundary. Remote outbox delivery has its own explicit acknowledgement boundary and is not part of this method.

func (*HomeEngine) Update

func (e *HomeEngine) Update(ctx context.Context, fn func(meta.Tx) error) error

func (*HomeEngine) View

func (e *HomeEngine) View(ctx context.Context, fn func(meta.ReadTx) error) error

type ReplicaInstallResult

type ReplicaInstallResult struct {
	Info         meta.MutationSnapshotInfo
	Position     meta.MutationPosition
	Published    bool
	Durable      bool
	Ready        bool
	PreviousPath string
}

ReplicaInstallResult describes the active database, not the private candidate. Published also holds for an already installed receipt. Durable means its directory publication is confirmed; Ready means the owned engine is usable. Errors after publication never authorize removing or replacing that database.

type ReplicaStore

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

ReplicaStore owns a replaceable local replication-only engine. All entry points serialize with installation and Close; it exposes no borrowed base or AsyncUpdater. It must not underlie a live Namespace RAM view. Callbacks must not reenter the store. The caller holds Options.Path+".lock" throughout Open, every request, Close, and recovery; the store never replaces that outer lock.

func OpenReplicaStore

func OpenReplicaStore(ctx context.Context, config ReplicaStoreConfig) (*ReplicaStore, error)

OpenReplicaStore recovers an interrupted installation before normal Open can initialize a missing database. It starts no network or background delivery. Native and bbolt are supported; auto retains meta.Open's normal selection.

func (*ReplicaStore) Barrier

func (e *ReplicaStore) Barrier(ctx context.Context) error

func (*ReplicaStore) Close

func (e *ReplicaStore) Close() error

Close first seals admission and cancels active operations, then joins them before closing the current owned engine once. Stop/join transports first so borrowed stream readers cannot remain blocked inside Read.

func (*ReplicaStore) Install

func (e *ReplicaStore) Install(ctx context.Context, r io.Reader, info meta.MutationSnapshotInfo) (result ReplicaInstallResult, err error)

Install accepts one authenticated, pinned snapshot. The receiver must also hold its unified Apply/status/install gate: ApplyMutationEvent spans Update and Sync and must not be split by an installation. Reader is borrowed; its transport owner must interrupt blocked Read calls during cancellation/stop. Exact receipt retries do not read r or discard any subsequently applied tail.

func (*ReplicaStore) Sync

func (e *ReplicaStore) Sync(ctx context.Context) error

func (*ReplicaStore) Update

func (e *ReplicaStore) Update(ctx context.Context, fn func(meta.Tx) error) error

func (*ReplicaStore) View

func (e *ReplicaStore) View(ctx context.Context, fn func(meta.ReadTx) error) error

type ReplicaStoreConfig

type ReplicaStoreConfig struct {
	Options meta.Options
	Home    meta.HomeConfig
	Limits  meta.MutationSnapshotLimits
}

Jump to

Keyboard shortcuts

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