wal

package module
v0.0.0-...-e2497fa Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2023 License: MIT Imports: 12 Imported by: 0

README

walgo

A write-ahead log written in Golang. I tried to write it with the Golang mindset and using the standard library as much as possible. I also tried to make it easy to use and understand.

Note

This is not production ready. Please do not use it as is until I have a chance to update it. You are free to use it as a base to implement your own write-ahead log.

Documentation

Index

Constants

View Source
const ConstEntrySize = 35

ConstEntrySize is the size of the constant portion of an Entry 8 + 4 + 15 + 4 + 4 = 35

Variables

View Source
var ErrConfigNotFound = errors.New("config file not found")
View Source
var ErrCrc32Mismatch = errors.New("crc32 mismatch")
View Source
var ErrFileAlreadyOpen = errors.New("file already open")
View Source
var ErrIndexAndTimestampSet = errors.New("index and timestamp cannot both be set")
View Source
var ErrNoPreviousEntry = errors.New("no previous entry")
View Source
var ErrNoSegmentsFound = errors.New("no segments found")
View Source
var ErrNotADirectory = errors.New("not a directory")
View Source
var ErrParseConfig = errors.New("error parsing config file")

Functions

This section is empty.

Types

type Entry

type Entry struct {
	Index     uint64
	Length    uint32
	Data      []byte
	Timestamp time.Time
	Crc32     uint32
}

Entry is a single message in a Wal

type Option

type Option func(*Wal)

func WithExpiration

func WithExpiration(limit, interval time.Duration) Option

WithExpiration sets the expiration time of messages in the Wal and the interval at which to check for expired segments

func WithMaxSegmentCount

func WithMaxSegmentCount(maxSegmentCount uint64) Option

WithMaxSegmentCount sets the maximum number of segments

func WithMaxSegmentSize

func WithMaxSegmentSize(maxSegmentSize uint64) Option

WithMaxSegmentSize sets the maximum size of a segment in bytes

type Reader

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

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Next

func (r *Reader) Next() (*Entry, error)

type ReaderOption

type ReaderOption func(*Reader) error

func WithIndex

func WithIndex(index uint64) ReaderOption

WithIndex sets the starting index of the Reader. It will try to seek to the message with that index. If it is set to before the earliest index, it will be set to the earliest index. If it is set to after the latest index, it will be set to the latest index. It will fail if the WithTimestamp option is also set.

func WithTimestamp

func WithTimestamp(timestamp time.Time) ReaderOption

WithTimestamp sets the starting timestamp of the Reader. It will seek for the first message after that timestamp. If it is set to after the latest timestamp, it will be set to the latest timestamp. It will fail if the WithIndex option is also set.

type Wal

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

Wal is a write-ahead log

func Load

func Load(dir string) (*Wal, error)

Load loads an existing Wal instance from disk

func New

func New(path string, options ...Option) (*Wal, error)

New creates a new Wal instance and initializes the directory/file structure

func (*Wal) Close

func (wal *Wal) Close() error

Close closes the current segment

func (*Wal) Flush

func (wal *Wal) Flush() error

Flush flushes the current segment to disk

func (*Wal) Reader

func (wal *Wal) Reader(options ...ReaderOption) (*Reader, error)

func (*Wal) Write

func (wal *Wal) Write(message []byte) (err error)

Write writes a message to the Wal in binary encoded Entry format

Jump to

Keyboard shortcuts

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