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
- func AppendFrame(walPath string, payload []byte) error
- func CheckpointRecorded(dir string) (redo uint64, ok bool, err error)
- func FrameBytes(walPath string) ([]byte, error)
- func Frames(walPath string) ([]wal.Frame, error)
- func LogImage(walPath string) ([]byte, error)
- func RewriteFrames(walPath string, fn func(i int, f *wal.Frame) bool) error
- func SegmentPaths(walPath string) ([]string, error)
- func TailSegmentPath(walPath string) (string, error)
- type FrameLoc
Constants ¶
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 ¶
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 ¶
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 ¶
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 ¶
Frames decodes every frame of every segment of the WAL at walPath, oldest first, stopping at the first undecodable frame.
func LogImage ¶
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 ¶
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 ¶
SegmentPaths returns the segment files of the WAL at walPath, oldest first.
func TailSegmentPath ¶
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 ¶
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.