wal

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

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

Go to latest
Published: Feb 17, 2022 License: Apache-2.0 Imports: 18 Imported by: 6

README

wal

This package provides a simple data structure for use as a write-ahead log.

Documentation

Index

Constants

View Source
const (
	// OffsetSize is the size in bytes of a WAL offset
	OffsetSize = 16
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Offset

type Offset []byte

Offset records an offset in the WAL

func NewOffset

func NewOffset(fileSequence int64, position int64) Offset

func NewOffsetForTS

func NewOffsetForTS(ts time.Time) Offset

NewOffsetForTS creates an offset for a given timestamp.

func (Offset) After

func (a Offset) After(b Offset) bool

func (Offset) FileSequence

func (o Offset) FileSequence() int64

func (Offset) Position

func (o Offset) Position() int64

func (Offset) String

func (o Offset) String() string

func (Offset) TS

func (o Offset) TS() time.Time

type Opts

type Opts struct {
	// Dir is the location of the WAL
	Dir string

	// SyncInterval determines how frequently to force an fsync to flush data to disk.
	// If syncInterval is 0, it will force sync on every write to the WAL.
	SyncInterval time.Duration

	// MaxMemoryBacklog determines the maximum number of writes that will be held in memory
	// pending write to the WAL. Set this to 0 to use no backlog, set to a value greater than 0
	// to allow buffering in memory. This can be useful to avoid slowing down clients while background
	// fsync takes place.
	MaxMemoryBacklog int
}

type Reader

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

Reader allows reading from a WAL. It is NOT safe to read from a single Reader from multiple goroutines.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the Reader.

func (*Reader) Offset

func (r *Reader) Offset() Offset

Offset returns the furthest Offset read by this Reader. It is NOT safe to call this concurrently with Read().

func (*Reader) Read

func (r *Reader) Read() ([]byte, error)

Read reads the next chunk from the WAL, blocking until one is available.

func (*Reader) Stop

func (r *Reader) Stop()

Stop stops this reader from advancing

type WAL

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

WAL provides a simple write-ahead log backed by a single file on disk. It is safe to write to a single WAL from multiple goroutines.

func Open

func Open(opts *Opts) (*WAL, error)

Open opens a WAL in the given directory with the given options.

func (*WAL) Close

func (wal *WAL) Close() (err error)

Close closes the wal, including flushing any unsaved writes.

func (*WAL) CompressBefore

func (wal *WAL) CompressBefore(o Offset) error

CompressBefore compresses all data prior to the given offset on disk.

func (*WAL) CompressBeforeSize

func (wal *WAL) CompressBeforeSize(limit int64) error

CompressBeforeSize compresses all segments prior to the given size

func (*WAL) CompressBeforeTime

func (wal *WAL) CompressBeforeTime(ts time.Time) error

CompressBeforeTime compresses all data prior to the given offset on disk.

func (*WAL) Latest

func (wal *WAL) Latest() ([]byte, Offset, error)

Latest() returns the latest entry in the WAL along with its offset

func (*WAL) NewReader

func (wal *WAL) NewReader(name string, offset Offset, bufferSource func() []byte) (*Reader, error)

NewReader constructs a new Reader for reading from this WAL starting at the given offset. The returned Reader is NOT safe for use from multiple goroutines. Name is just a label for the reader used during logging.

func (*WAL) TruncateBefore

func (wal *WAL) TruncateBefore(o Offset) error

TruncateBefore removes all data prior to the given offset from disk.

func (*WAL) TruncateBeforeTime

func (wal *WAL) TruncateBeforeTime(ts time.Time) error

TruncateBeforeTime truncates WAL data prior to the given timestamp.

func (*WAL) TruncateToSize

func (wal *WAL) TruncateToSize(limit int64) error

TruncateToSize caps the size of the WAL to the given number of bytes

func (*WAL) Write

func (wal *WAL) Write(bufs ...[]byte) error

Write atomically writes one or more buffers to the WAL.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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