wal

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package wal provides Write-Ahead Logging for XxSql storage engine.

Index

Constants

View Source
const (
	// WALFileExt is the extension for WAL files.
	WALFileExt = ".xwal"

	// WALHeaderSize is the size of the WAL file header.
	WALHeaderSize = 32

	// WALRecordHeaderSize is the size of a WAL record header.
	// LSN (8) + Type (1) + TxnID (8) + PageID (8) = 25 bytes
	WALRecordHeaderSize = 25

	// DefaultSyncInterval is the default sync interval.
	DefaultSyncInterval = 100 * time.Millisecond

	// DefaultMaxSize is the default max WAL file size (64MB).
	DefaultMaxSize = 64 * 1024 * 1024
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LSN

type LSN uint64

LSN represents a Log Sequence Number.

const InvalidLSN LSN = 0

InvalidLSN represents an invalid LSN.

type Manager

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

Manager manages WAL operations.

func NewManager

func NewManager(config ManagerConfig) *Manager

NewManager creates a new WAL manager.

func (*Manager) Append

func (m *Manager) Append(recordType RecordType, txnID, pageID uint64, tableName string, data []byte) (LSN, error)

Append appends a record to the WAL.

func (*Manager) AppendRecord

func (m *Manager) AppendRecord(r *Record) (LSN, error)

AppendRecord appends a pre-constructed record to the WAL.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the WAL manager.

func (*Manager) GetCurrentLSN

func (m *Manager) GetCurrentLSN() LSN

GetCurrentLSN returns the current LSN.

func (*Manager) GetFlushedLSN

func (m *Manager) GetFlushedLSN() LSN

GetFlushedLSN returns the last flushed LSN.

func (*Manager) LogAbort

func (m *Manager) LogAbort(txnID uint64) (LSN, error)

LogAbort logs a transaction abort.

func (*Manager) LogBegin

func (m *Manager) LogBegin(txnID uint64) (LSN, error)

LogBegin logs a transaction begin.

func (*Manager) LogCheckpoint

func (m *Manager) LogCheckpoint(txnID uint64, checkpointData []byte) (LSN, error)

LogCheckpoint logs a checkpoint.

func (*Manager) LogCommit

func (m *Manager) LogCommit(txnID uint64) (LSN, error)

LogCommit logs a transaction commit.

func (*Manager) LogCreateTable

func (m *Manager) LogCreateTable(txnID uint64, tableName string, schemaData []byte) (LSN, error)

LogCreateTable logs a create table operation.

func (*Manager) LogDelete

func (m *Manager) LogDelete(txnID uint64, tableName string, rowData []byte) (LSN, error)

LogDelete logs a delete operation.

func (*Manager) LogDropTable

func (m *Manager) LogDropTable(txnID uint64, tableName string) (LSN, error)

LogDropTable logs a drop table operation.

func (*Manager) LogInsert

func (m *Manager) LogInsert(txnID uint64, tableName string, rowData []byte) (LSN, error)

LogInsert logs an insert operation.

func (*Manager) LogPageWrite

func (m *Manager) LogPageWrite(txnID, pageID uint64, pageData []byte) (LSN, error)

LogPageWrite logs a page write operation.

func (*Manager) LogSequenceCreate

func (m *Manager) LogSequenceCreate(name string, startValue int64) error

LogSequenceCreate logs a sequence creation.

func (*Manager) LogSequenceDrop

func (m *Manager) LogSequenceDrop(name string) error

LogSequenceDrop logs a sequence drop.

func (*Manager) LogSequenceNext

func (m *Manager) LogSequenceNext(name string, value int64) error

LogSequenceNext logs a sequence next value operation.

func (*Manager) LogUpdate

func (m *Manager) LogUpdate(txnID uint64, tableName string, oldData, newData []byte) (LSN, error)

LogUpdate logs an update operation.

func (*Manager) NeedsCheckpoint

func (m *Manager) NeedsCheckpoint() (bool, error)

NeedsCheckpoint returns true if a checkpoint is needed.

func (*Manager) Open

func (m *Manager) Open() error

Open opens the WAL file.

func (*Manager) Replay

func (m *Manager) Replay(fn func(*Record) error) error

Replay reads all records from the WAL.

func (*Manager) Size

func (m *Manager) Size() (int64, error)

Size returns the current WAL file size.

func (*Manager) Sync

func (m *Manager) Sync() error

Sync syncs the WAL file to disk.

func (*Manager) Truncate

func (m *Manager) Truncate() error

Truncate truncates the WAL file.

type ManagerConfig

type ManagerConfig struct {
	Path         string
	MaxSize      int64
	SyncInterval time.Duration
}

ManagerConfig holds WAL manager configuration.

type Record

type Record struct {
	LSN       LSN
	Type      RecordType
	TxnID     uint64
	PageID    uint64
	TableName string
	Data      []byte
	Timestamp int64
}

Record represents a WAL record.

func UnmarshalRecord

func UnmarshalRecord(data []byte) (*Record, int, error)

UnmarshalRecord deserializes bytes to a record.

func (*Record) Marshal

func (r *Record) Marshal() []byte

Marshal serializes a record to bytes.

type RecordType

type RecordType uint8

RecordType represents the type of WAL record.

const (
	RecordTypeBegin RecordType = iota
	RecordTypeCommit
	RecordTypeAbort
	RecordTypeInsert
	RecordTypeUpdate
	RecordTypeDelete
	RecordTypeCreateTable
	RecordTypeDropTable
	RecordTypeCreateIndex
	RecordTypeDropIndex
	RecordTypeCheckpoint
	RecordTypePageWrite
	RecordTypeSequenceCreate
	RecordTypeSequenceDrop
	RecordTypeSequenceNext
)

func (RecordType) String

func (t RecordType) String() string

String returns the string representation.

Jump to

Keyboard shortcuts

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