wal

package
v8.24.2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2024 License: MIT, Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WALHeaderSize      = 32
	WALFrameHeaderSize = 24

	WALSupportedVersion = 3007000
)

SQLite constants

Variables

View Source
var (
	// ErrOpenTransaction is returned when the final frame in the WAL file is not a committing frame.
	ErrOpenTransaction = errors.New("open transaction at end of WAL file")
)

Functions

func ResetStats added in v8.18.6

func ResetStats()

ResetStats resets the expvar stats for this module. Mostly for test purposes.

func WALChecksum

func WALChecksum(bo binary.ByteOrder, s0, s1 uint32, b []byte) (uint32, uint32)

WALChecksum computes a running SQLite WAL checksum over a byte slice.

Types

type CompactingScanner

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

CompactingScanner implements WALIterator to iterate over frames in a WAL file. It also compacts the WAL file, with Next() returning the last valid frame for each page in the right order such that they can be written to a new WAL file. This Scanner requires that the final frame in the WAL file is a committing frame. It will return an error at creation time if this is not the case.

func NewCompactingScanner

func NewCompactingScanner(r io.ReadSeeker, fullScan bool) (*CompactingScanner, error)

NewCompactingScanner creates a new CompactingScanner with the given io.ReadSeeker. If fullScan is true, the scanner will perform a full scan of the WAL file, performing a checksum on each frame. If fullScan is false, the scanner will only scan the file sufficiently to find the last valid frame for each page. This is faster when the caller knows that the entire WAL file is valid, and will not contain pages from a previous checkpointing operation.

func NewFastCompactingScanner

func NewFastCompactingScanner(r io.ReadSeeker) (*CompactingScanner, error)

NewFastCompactingScanner creates a new CompactingScanner with the given io.ReadSeeker. It performs a fast scan of the WAL file, assuming that the file is valid and does not need to be checked.

func (*CompactingScanner) Bytes added in v8.18.4

func (c *CompactingScanner) Bytes() ([]byte, error)

Bytes returns a byte slice containing the entire contents of the compacted WAL file. The byte slice is suitable for writing to a new WAL file.

func (*CompactingScanner) Header

func (c *CompactingScanner) Header() (*WALHeader, error)

Header returns the header of the WAL file.

func (*CompactingScanner) Next

func (c *CompactingScanner) Next() (*Frame, error)

Next return the next logical frame from the WAL file.

type Frame

type Frame struct {
	Pgno   uint32
	Commit uint32
	Data   []byte
}

Frame points to a single WAL frame in a WAL file.

type FullScanner

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

FullScanner implements WALIterator to iterate over all frames in a WAL file.

func NewFullScanner

func NewFullScanner(r io.ReadSeeker) (*FullScanner, error)

NewFullScanner creates a new FullScanner with the given io.Reader.

func (*FullScanner) Header

func (f *FullScanner) Header() (*WALHeader, error)

Header returns the header of the WAL file.

func (*FullScanner) Next

func (f *FullScanner) Next() (*Frame, error)

Next reads the next frame from the WAL file.

type Reader

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

Reader wraps an io.Reader and parses SQLite WAL frames.

This reader verifies the salt & checksum integrity while it reads. It does not enforce transaction boundaries (i.e. it may return uncommitted frames). It is the responsibility of the caller to handle this.

Reader has been copied from the litefs source code. Many thanks to the authors of that software. See https://github.com/superfly/litefs for more details.

func NewReader

func NewReader(r io.ReadSeeker) *Reader

NewReader returns a new instance of Reader.

func (*Reader) Offset

func (r *Reader) Offset() int64

Offset returns the file offset of the last read frame. Returns zero if no frames have been read.

func (*Reader) PageSize

func (r *Reader) PageSize() uint32

PageSize returns the page size from the header. Must call ReadHeader() first.

func (*Reader) ReadFrame

func (r *Reader) ReadFrame(data []byte) (pgno, commit uint32, err error)

ReadFrame returns the next page number and commit offset from the WAL. If data is not nil, then the page data is read into the buffer. If data is nil, then the page data is skipped. ReadFrame Returns io.EOF at the end of the valid WAL.

func (*Reader) ReadHeader

func (r *Reader) ReadHeader() error

ReadHeader reads the WAL header into the reader. Returns io.EOF if WAL is invalid.

type WALHeader

type WALHeader struct {
	Magic     uint32
	Version   uint32
	PageSize  uint32
	Seq       uint32
	Salt1     uint32
	Salt2     uint32
	Checksum1 uint32
	Checksum2 uint32
}

WALHeader represents the header of a WAL file.

func (*WALHeader) Copy added in v8.18.4

func (h *WALHeader) Copy(b []byte)

Copy copies the WALHeader to the given byte slice. If the byte slice is too small, a panic occurs.

type WALIterator

type WALIterator interface {
	Header() (*WALHeader, error)
	Next() (*Frame, error)
}

WALIterator defines the interface for WAL frame iteration.

type Writer

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

Writer is used to write a WAL file.

func NewWriter

func NewWriter(r WALIterator) (*Writer, error)

NewWriter returns a new Writer.

func (*Writer) WriteTo

func (w *Writer) WriteTo(ww io.Writer) (n int64, retErr error)

WriteTo writes the frames from the WALIterator to the given io.Writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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