wal

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2025 License: BSD-3-Clause Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReplayDir added in v1.1.0

func ReplayDir(dir string, logger common.Logger, callback func(op uint8, key []byte, expiresAt time.Time) error) error

ReplayDir replays WAL files from a directory in read-only fashion. It does not create, rotate, modify, or quarantine files. Best-effort: on corruption, it logs and continues.

Types

type Config

type Config struct {
	RotateSize  int64
	MaxFileSize int64
	BufferSize  int
	// Durability policy
	SyncOnEveryWrite  bool
	FlushOnEveryWrite bool
	FlushEveryBytes   int
}

Config controls WAL sizing and buffering.

type WAL

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

WAL represents a Write-Ahead Log for durability.

func New

func New(dir string, logger common.Logger) (*WAL, error)

New creates a new WAL instance.

func NewWithConfig

func NewWithConfig(dir string, logger common.Logger, cfg Config) (*WAL, error)

NewWithConfig creates a new WAL instance with custom configuration.

func (*WAL) Close

func (w *WAL) Close() error

Close closes the WAL.

func (*WAL) CurrentSeq

func (w *WAL) CurrentSeq() uint64

CurrentSeq returns the current WAL sequence number.

func (*WAL) DeleteOldFiles

func (w *WAL) DeleteOldFiles(beforeSeq uint64) error

DeleteOldFiles deletes WAL files older than the specified sequence.

func (*WAL) Flush

func (w *WAL) Flush() error

Flush flushes buffered data to disk.

func (*WAL) Replay

func (w *WAL) Replay(callback func(op uint8, key []byte, expiresAt time.Time) error) error

Replay replays all WAL files and calls the callback for each record.

func (*WAL) Rotate

func (w *WAL) Rotate() error

Rotate exposes WAL rotation to callers.

func (*WAL) Sync

func (w *WAL) Sync() error

Sync syncs the WAL file to disk.

func (*WAL) Write

func (w *WAL) Write(op uint8, key []byte) error

Write writes an operation to the WAL.

func (*WAL) WriteBatch added in v1.1.0

func (w *WAL) WriteBatch(entries []*WALEntry) error

WriteBatch writes a batch of operations to the WAL. This is more efficient than multiple individual writes as it minimizes lock contention and disk I/O.

func (*WAL) WriteWithTTL

func (w *WAL) WriteWithTTL(op uint8, key []byte, ttl time.Duration) error

WriteWithTTL writes an operation to the WAL with TTL.

type WALEntry added in v1.1.0

type WALEntry struct {
	Op  uint8
	Key []byte
	TTL time.Duration
}

WALEntry represents a single operation to be written to the WAL.

type WALHeader

type WALHeader struct {
	Magic     uint32 // 4 bytes
	Version   uint16 // 2 bytes
	CreatedAt int64  // 8 bytes (unix timestamp)
}

WALHeader represents the fixed-size WAL file header (14 bytes).

type WALRecord

type WALRecord struct {
	Op     uint8
	Key    []byte
	SeqNum uint64
	TTL    time.Duration // 0 means no TTL
	CRC32C uint32
}

WALRecord represents a single WAL record.

Jump to

Keyboard shortcuts

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