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
- Variables
- type Engine
- func (e *Engine) Apply(ctx context.Context, seq uint64, payload []byte) error
- func (e *Engine) Barrier(ctx context.Context) error
- func (e *Engine) Base() meta.Engine
- func (e *Engine) Close() error
- func (e *Engine) Snapshot(ctx context.Context, w io.Writer) error
- func (e *Engine) Sync(ctx context.Context) error
- func (e *Engine) Update(ctx context.Context, fn func(meta.Tx) error) error
- func (e *Engine) View(ctx context.Context, fn func(meta.ReadTx) error) error
- type EventualAck
- type EventualHome
- type EventualReceiver
- type EventualReceiverConfig
- type EventualSender
- type EventualSenderConfig
- type EventualSnapshot
- type EventualSnapshotAck
- type EventualSnapshotReceiverConfig
- type EventualStatus
- type HomeEngine
- func (e *HomeEngine) Barrier(ctx context.Context) error
- func (e *HomeEngine) Base() meta.Engine
- func (e *HomeEngine) CaptureMutationSnapshot(ctx context.Context, w io.Writer, limits meta.MutationSnapshotLimits) (meta.MutationSnapshotInfo, error)
- func (e *HomeEngine) Close() error
- func (e *HomeEngine) Position(ctx context.Context) (meta.MutationPosition, error)
- func (e *HomeEngine) Snapshot(ctx context.Context, w io.Writer) error
- func (e *HomeEngine) Sync(ctx context.Context) error
- func (e *HomeEngine) Update(ctx context.Context, fn func(meta.Tx) error) error
- func (e *HomeEngine) View(ctx context.Context, fn func(meta.ReadTx) error) error
- type ReplicaInstallResult
- type ReplicaStore
- func (e *ReplicaStore) Barrier(ctx context.Context) error
- func (e *ReplicaStore) Close() error
- func (e *ReplicaStore) Install(ctx context.Context, r io.Reader, info meta.MutationSnapshotInfo) (result ReplicaInstallResult, err error)
- func (e *ReplicaStore) Sync(ctx context.Context) error
- func (e *ReplicaStore) Update(ctx context.Context, fn func(meta.Tx) error) error
- func (e *ReplicaStore) View(ctx context.Context, fn func(meta.ReadTx) error) error
- type ReplicaStoreConfig
Constants ¶
const EventualRPCMessageBytes = 64 << 20
const EventualRPCVersion = 1
const EventualSnapshotChunkBytes = 1 << 20
Variables ¶
var ( ErrEventualIdentity = errors.New("eventual replication identity mismatch") ErrEventualAck = errors.New("invalid eventual replication acknowledgement") ErrEventualClosed = errors.New("eventual replication closed") )
var ( 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 ¶
NewEngine registers the domain state machine and native watermark. On success it transfers ownership of base; the authority remains borrowed.
func (*Engine) Apply ¶
Apply persists edits and their native watermark before the authority can confirm application. Metadata owns the durable batch format and validation.
func (*Engine) Base ¶
Base returns the borrowed native engine for capture inside an existing authority barrier. Direct reads bypass the service gate.
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
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.
type EventualSenderConfig ¶
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 ¶
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.
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) 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.
type ReplicaStoreConfig ¶
type ReplicaStoreConfig struct {
Options meta.Options
Home meta.HomeConfig
Limits meta.MutationSnapshotLimits
}