wal

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SerializeRecord

func SerializeRecord(rec *LogRecord) ([]byte, error)

SerializeRecord encodes a LogRecord into a binary byte slice.

Types

type LogRecord

type LogRecord struct {
	LSN    uint64
	TxID   uint64
	Type   RecordType
	PageID page.PageID
	Data   []byte // Page content (after-image)
}

LogRecord represents a single entry in the Write-Ahead Log.

func DeserializeRecord

func DeserializeRecord(r io.Reader) (*LogRecord, error)

DeserializeRecord decodes a LogRecord from an io.Reader and verifies its CRC32 checksum.

type RecordType

type RecordType byte

RecordType represents the action logged in the WAL.

const (
	Begin RecordType = iota
	Update
	Commit
	Abort
)

type WAL

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

WAL manages appending and reading log records from the log file.

func Open

func Open(filename string) (*WAL, error)

Open opens or creates a WAL file.

func (*WAL) Append

func (w *WAL) Append(txID uint64, recType RecordType, pageID page.PageID, data []byte) (uint64, error)

Append logs a new record to the WAL and returns its Log Sequence Number (LSN).

func (*WAL) Close

func (w *WAL) Close() error

Close closes the WAL file.

func (*WAL) Filename

func (w *WAL) Filename() string

Filename returns the path of the WAL file.

func (*WAL) ReadAllRecords

func (w *WAL) ReadAllRecords() ([]*LogRecord, error)

ReadAllRecords reads all records from the beginning of the WAL.

func (*WAL) Sync

func (w *WAL) Sync() error

Sync flushes the WAL changes to physical disk (fsync).

func (*WAL) Truncate

func (w *WAL) Truncate() error

Truncate clears all records from the WAL file and resets the LSN sequence.

Jump to

Keyboard shortcuts

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