wal

package
v0.0.0-...-051453a Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Segment

type Segment[T any] struct {
	// contains filtered or unexported fields
}

Segment is a collection of records that exist in the WAL, in the order they were appended. The WAL will append a maximum of maxSegmentSize records to a segment before cutting a new one.

func (*Segment[T]) Length

func (s *Segment[T]) Length() int

func (*Segment[T]) Records

func (s *Segment[T]) Records() []T

Records returns a copy of records in this segment

type WAL

type WAL[T any] struct {
	// contains filtered or unexported fields
}

WAL is a simple write-ahead-log like structure containing multiple records. It is rooted at a specific directory, which contains WAL segments as files. Each file is named with a ULID for the segment based on the timestamp the segment was created. Segments contain a maximum of maxSegmentSize records, and segments are automatically added as new records are appended to the log, as well as removed as segments are successfully processed.

func Open

func Open[T any](path string, maxSegmentSize int) (WAL[T], error)

Open constructs a new WAL by loading segments from the specified directory. Directories and files that are not named with a valid ULID are ignored. Each segment is loaded in order based on the timestamp the segment was created, which is embedded in the ID of the segment.

func (*WAL[T]) Append

func (w *WAL[T]) Append(v T) error

Append adds the specified value to the WAL, creating a new segment if required. Once the record is appended to the tail of the WAL, the segment containing it is committed to disk.

func (*WAL[T]) Process

func (w *WAL[T]) Process(visit func(segment Segment[T]) error) error

Process iterates through WAL segments in order and invokes the specified visitation function on each segment. If the function returns no error, the segment is trimmed from the WAL. If the function returns an error, processing stops and the segment is retained.

Jump to

Keyboard shortcuts

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