wal

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBufferSize = 1 << 27
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LogStatus

type LogStatus uint16

LogStatus represents the state of log, written to applied

type Options

type Options struct {
	Path       string
	TargetSize int64
	BufferSize int64
}

Options wal options to create new WAL. WAL logs uses cyclic rotation to avoid fragmentation. It allocates free blocks only when log reaches target size

type Reader

type Reader struct {
	Id uid.LID
	// contains filtered or unexported fields
}

Reader reads logs from WAL. Reader reader is a simple iterator over log data

func (*Reader) Count

func (r *Reader) Count() uint32

Count returns entry count in the current reader

func (*Reader) Next

func (r *Reader) Next() ([]byte, bool)

Next returns next record from the log data iterator or false if iteration is done

func (*Reader) Read

func (r *Reader) Read(f func(uint64, bool) (bool, error)) (err error)

Read reads log written to the WAL but fully applied. It returns Reader iterator

type WAL

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

WAL write ahead logs to recover db commit failure dues to db crash or other unexpected errors

func New

func New(opts Options) (*WAL, bool, error)

New will open a WAL. If the previous run did not shut down cleanly, a set of upper seq will be returned which got committed successfully to the WAL, but were never signaled as fully completed.

If no WAL exists, a new one will be created.

func (*WAL) Close

func (wal *WAL) Close() error

Close closes the wal, frees used resources and checks for active logs.

func (*WAL) NewReader

func (wal *WAL) NewReader() (*Reader, error)

NewReader returns new log reader to read logs from WAL

func (*WAL) NewWriter

func (wal *WAL) NewWriter() (*Writer, error)

NewWriter returns new log writer to write to WAL

func (*WAL) Seq

func (wal *WAL) Seq() uint64

Seq returns upper DB sequence successfully written to the logfile in wal

func (*WAL) SignalLogApplied

func (wal *WAL) SignalLogApplied(upperSeq uint64) error

SignalLogApplied informs the WAL that it is safe to reuse blocks.

func (*WAL) Sync

func (wal *WAL) Sync() error

Sync syncs log entries to disk

type Writer

type Writer struct {
	Id uid.LID
	// contains filtered or unexported fields
}

Writer writes entries to the write ahead log. Thread-safe.

func (*Writer) Append

func (w *Writer) Append(data []byte) <-chan error

Append appends records into WAL

func (*Writer) SignalInitWrite

func (w *Writer) SignalInitWrite(seq uint64) <-chan error

SignalInitWrite will signal to the WAL that log append has completed, and that the WAL can safely write log and being applied atomically.

Jump to

Keyboard shortcuts

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