Documentation ¶
Index ¶
Constants ¶
const ( WALHeaderSize = 32 WALFrameHeaderSize = 24 WALSupportedVersion = 3007000 )
SQLite constants
Variables ¶
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.
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 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 ¶
Offset returns the file offset of the last read frame. Returns zero if no frames have been read.
func (*Reader) PageSize ¶
PageSize returns the page size from the header. Must call ReadHeader() first.
func (*Reader) ReadFrame ¶
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 ¶
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.
type WALIterator ¶
WALIterator defines the interface for WAL frame iteration.