wal

package module
v0.0.0-...-7f82e91 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2022 License: MIT Imports: 12 Imported by: 0

README

Embedded Write Ahead Log

Simple multi segment write ahead log. Writes two type of files files *.index and *.store. Configurable maximum index and store file sizes.

Files stucuture:

  • Index record structure: [recordID (8 bytes)][recordOffset (8 bytes)]
  • Store record structure: [size (8 bytes)][data (variable bytes)]

Usage example

wl, _ := wal.New(".", nil)
offset, _ := wl.Append(data)
data, _ := wl.Read(offset)
wl.Close()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRecordNotFound = errors.New("record is not found")
	ErrIndexRecordID  = errors.New("cant read record id from index")
)
View Source
var ErrMaxIndexSize = errors.New("max index size should be multiple by 16 and more than 0")

Functions

This section is empty.

Types

type Config

type Config struct {
	Segment struct {
		MaxStoreSizeBytes uint64
		MaxIndexSizeBytes uint64
	}
}

Config stores embedded log configuration data MaxIndexSizeBytes should be multiple of 16

type WAL

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

func New

func New(dir string, cfg *Config) (*WAL, error)

New creates a Write Ahead Log in specified directory it will look for files [d+].store and [d+].index if no such files are present it will create an empty ones: 0001.index and 0001.store

func (*WAL) Append

func (w *WAL) Append(data []byte) (uint64, error)

Append add data to the log returns record id and error if any

func (*WAL) Close

func (w *WAL) Close() error

func (*WAL) Read

func (w *WAL) Read(id uint64) ([]byte, error)

Read returns byte slice for record id and error if any

func (*WAL) Trim

func (w *WAL) Trim(id uint64) error

Trim remove all segments that startID is less than id

Jump to

Keyboard shortcuts

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