replica

package
v1.10.2 Latest Latest
Warning

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

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

Documentation

Overview

Package replica owns the backup-side wiring: open a ZapDB read-only, take a snapshot, stream the badger Backup bytes through hanzoai/vfs (4 KiB content-addressed age-encrypted blocks), and publish a manifest naming the produced block list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChunkReader

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

ChunkReader reads back a stream the ChunkWriter produced. It fetches each BlockID via vfs.GetBlock in order. Plaintext blocks are returned padded to vfs.BlockSize; the reader truncates the final block to (plainSize - (n-1)*BlockSize) when plainSize is not a multiple of BlockSize.

func NewChunkReader

func NewChunkReader(ctx context.Context, v *vfs.VFS, blocks []vfs.BlockID, plainSize int64) *ChunkReader

NewChunkReader builds a reader. plainSize MUST match the manifest.

func (*ChunkReader) Read

func (r *ChunkReader) Read(p []byte) (int, error)

Read implements io.Reader.

type ChunkWriter

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

ChunkWriter buffers an io.Writer stream into vfs.BlockSize pages and pushes each full page through vfs.PutBlock. The last page (Close) flushes whatever bytes remain — vfs.Pad zero-pads short tails to BlockSize before encryption.

Concurrency: not safe for concurrent use. Caller serialises Write/Close.

func NewChunkWriter

func NewChunkWriter(ctx context.Context, v *vfs.VFS) *ChunkWriter

NewChunkWriter constructs a ChunkWriter against the given VFS. The caller is responsible for Close() — it flushes any partial tail block.

func (*ChunkWriter) Blocks

func (c *ChunkWriter) Blocks() []vfs.BlockID

Blocks returns the ordered BlockIDs produced by this writer. Only valid after Close.

func (*ChunkWriter) Close

func (c *ChunkWriter) Close() error

Close flushes any partial tail block. Safe to call multiple times. After Close, Blocks and PlainSize are stable.

func (*ChunkWriter) PlainSize

func (c *ChunkWriter) PlainSize() int64

PlainSize returns the number of plaintext bytes the writer consumed. Used by the manifest so Restore can truncate the final block.

func (*ChunkWriter) Write

func (c *ChunkWriter) Write(p []byte) (int, error)

Write implements io.Writer. Each completed vfs.BlockSize page is encrypted + put to the backend; the produced BlockID is appended to the in-memory ordered slice.

type Config

type Config struct {
	DBPath            string
	Network           string   // e.g. "mainnet"
	VFS               *vfs.VFS // backend + crypto
	Backend           backend.Backend
	StatePath         string        // override state file path; empty -> derived
	Interval          time.Duration // between cycles, default 60s
	FullSnapshotEvery time.Duration // re-snapshot full at this cadence
	AgeSchemeLabel    string        // recorded in manifests for audit
}

Config wires a single replica.

type Replica

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

Replica is a single (database, backend) pair that the daemon ticks against. Each tick: snapshot ZapDB, stream through vfs, publish a manifest, advance HEAD, persist watermark.

func New

func New(cfg Config) (*Replica, error)

New constructs a Replica. The VFS + Backend are taken in pre-built so the daemon can share them across multiple databases.

func (*Replica) Run

func (r *Replica) Run(ctx context.Context) error

Run loops the replicator until ctx is cancelled. Errors per cycle are logged but do not terminate the loop — the next tick retries.

Jump to

Keyboard shortcuts

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