waltest

package
v0.17.2 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package waltest locates the files of a segmented write-ahead log for tests and examples that inspect or damage WAL bytes directly. It reads the operating-system filesystem and has no side effects; every function is safe for concurrent use.

Index

Constants

View Source
const SegmentHeaderSize = 32

SegmentHeaderSize is the size of a segment file's header; its first frame starts at this offset.

Variables

This section is empty.

Functions

func AppendFrame

func AppendFrame(walPath string, payload []byte) error

AppendFrame appends one durable frame carrying payload to the tail segment of the WAL at walPath, after its last frame, with the position, prev-link and store id a writer would have given it. It models a frame written by a process that then died.

func CheckpointRecorded

func CheckpointRecorded(dir string) (redo uint64, ok bool, err error)

CheckpointRecorded reports whether the last checkpoint of the store in dir recorded its snapshot in the WAL control file: the control file has the prefix-truncated flag and its checkpoint redo position equals the redo position the published snapshot (dir/snapshot) records. That is the state in which recovery starts from the snapshot alone, whether or not a whole segment could be unlinked. redo is the snapshot's redo position.

func FrameBytes

func FrameBytes(walPath string) ([]byte, error)

FrameBytes returns the frame bytes of every segment of the WAL at walPath, headers stripped, concatenated oldest first: a frame stream a wal.Reader decodes.

func Frames

func Frames(walPath string) ([]wal.Frame, error)

Frames decodes every frame of every segment of the WAL at walPath, oldest first, stopping at the first undecodable frame.

func LogImage

func LogImage(walPath string) ([]byte, error)

LogImage returns the bytes of every file of the WAL at walPath — the legacy file, the control file and each segment — concatenated in that order, for a test that asserts nothing in the log was modified. Missing files contribute nothing.

func RewriteFrames

func RewriteFrames(walPath string, fn func(i int, f *wal.Frame) bool) error

RewriteFrames rewrites every segment of the WAL at walPath through fn, which may change a frame's payload in place (fn's frame is a copy it owns) and returns false to drop the frame. Every surviving frame is re-encoded with a recomputed position, prev-link and CRC, starting from the first frame's original position, so the result is a structurally valid segmented log whose content differs only as fn decided. The control file is left as it is, so a rewrite that moves the position of the oldest retained frame or of a snapshot's redo position is the caller's to reason about.

func SegmentPaths

func SegmentPaths(walPath string) ([]string, error)

SegmentPaths returns the segment files of the WAL at walPath, oldest first.

func TailSegmentPath

func TailSegmentPath(walPath string) (string, error)

TailSegmentPath returns the newest segment of the WAL at walPath that holds at least one frame byte: the segment a crash tears and the one the writer appends to. Empty spare segments after it are skipped.

Types

type FrameLoc

type FrameLoc struct {
	Frame wal.Frame
	// Path is the segment file holding the frame.
	Path string
	// Offset is the file offset of the frame's first header byte.
	Offset int64
	// Size is the frame's encoded size.
	Size int64
}

FrameLoc is one frame of a segmented log and where it lies on disk.

func LocateFrames

func LocateFrames(walPath string) ([]FrameLoc, error)

LocateFrames returns every decodable frame of every segment of the WAL at walPath, oldest first, with its file and offset, stopping in each segment at the first undecodable frame.

Jump to

Keyboard shortcuts

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