wal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package wal is a durable, file-based write-ahead log of edit intents. Each Append fsyncs one JSON-encoded record (one line) to <dir>/wal.log; Replay reads every record back in order. There is no SQLite or external store: the log is a plain append-only file so a crash mid-edit can be reconciled on restart by replaying the recorded intents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(dir string, in Intent) error

Append durably records one intent. It creates dir if needed, then opens <dir>/wal.log in append mode, writes the JSON encoding of in as a single line, and fsyncs the file before returning so the record survives a crash.

Types

type Intent

type Intent struct {
	// ID uniquely identifies this intent.
	ID string `json:"id"`
	// Edits are the byte-range replacements this intent will apply.
	Edits []locator.FileEdit `json:"edits"`
	// Originals maps each affected file path to its pre-edit raw bytes.
	Originals map[string][]byte `json:"originals"`
	// ExpectedRawHash maps each file path to its expected raw content hash.
	ExpectedRawHash map[string]string `json:"expected_raw_hash"`
	// ExpectedNormHash maps each file path to its expected normalized hash.
	ExpectedNormHash map[string]string `json:"expected_norm_hash"`
}

Intent is one durably-recorded edit intent. It captures the edits to apply, the original bytes of each affected file (for restore-on-failure), and the expected raw and normalized content hashes per file (for drift detection) so a recovering process has everything needed to reapply or roll back.

func Replay

func Replay(dir string) ([]Intent, error)

Replay reads every recorded intent from <dir>/wal.log in append order. A missing directory or log file is treated as an empty log: it returns an empty slice and no error.

Jump to

Keyboard shortcuts

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