wal

package
v1.9.13-beta2 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Op        OpType
	Entity    string // e.g. "processes", "executors"
	Key       string // primary key
	Data      []byte // JSON-encoded record (nil for deletes)
	Timestamp int64  // unix nanoseconds
}

Entry represents a single WAL entry.

type FileWAL

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

FileWAL is a WAL implementation backed by a single file on disk.

func NewFileWAL

func NewFileWAL(dir string, syncMode SyncMode) (*FileWAL, error)

NewFileWAL opens or creates a WAL file in the given directory.

func (*FileWAL) Append

func (w *FileWAL) Append(entry Entry) error

Append writes an entry to the WAL.

func (*FileWAL) Close

func (w *FileWAL) Close() error

Close closes the WAL file.

func (*FileWAL) Replay

func (w *FileWAL) Replay(fn func(Entry) error) error

Replay reads all valid entries from the WAL, calling fn for each. Corrupt or truncated trailing entries are silently skipped (crash recovery).

func (*FileWAL) Truncate

func (w *FileWAL) Truncate() error

Truncate removes all entries by replacing the WAL file with an empty one.

type OpType

type OpType uint8

OpType represents the type of WAL operation.

const (
	OpPut    OpType = 1
	OpDelete OpType = 2
)

type SyncMode

type SyncMode int

SyncMode controls when the WAL calls fsync.

const (
	// SyncAlways calls fsync after every append (safest, slowest).
	SyncAlways SyncMode = iota
	// SyncNone never calls fsync (fastest, data loss on crash).
	SyncNone
)

type WAL

type WAL interface {
	// Append writes an entry to the log. Depending on the SyncMode, the
	// entry may or may not be durable when Append returns.
	Append(entry Entry) error

	// Replay reads all entries from the log in order, calling fn for each.
	// If fn returns an error, replay stops and the error is returned.
	Replay(fn func(Entry) error) error

	// Truncate removes all entries from the log. Called after a successful
	// flush to disk.
	Truncate() error

	// Close flushes any buffered data and closes the log.
	Close() error
}

WAL is the interface for write-ahead logging. Implementations must be safe for concurrent use by multiple goroutines.

Jump to

Keyboard shortcuts

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