Documentation
¶
Overview ¶
Package ltx reads and writes Liteserver Transaction (LTX) files.
Index ¶
- Constants
- Variables
- func ChecksumPage(pgno uint32, data []byte) uint64
- func ChecksumReader(r io.Reader, pageSize int) (uint64, error)
- func FormatFilename(minTXID, maxTXID uint64) string
- func FormatTXID(id uint64) string
- func IsValidHeaderFlags(flags uint32) bool
- func IsValidPageSize(sz uint32) bool
- func ParseFilename(name string) (minTXID, maxTXID uint64, err error)
- func ParseTXID(s string) (uint64, error)
- type Compactor
- type Decoder
- type Encoder
- func (enc *Encoder) Close() error
- func (enc *Encoder) EncodeHeader(hdr Header) error
- func (enc *Encoder) EncodePage(hdr PageHeader, data []byte) (err error)
- func (enc *Encoder) Header() Header
- func (enc *Encoder) N() int64
- func (enc *Encoder) SetPostApplyChecksum(chksum uint64)
- func (enc *Encoder) Trailer() Trailer
- type FileSpec
- type Header
- type PageHeader
- type PageSpec
- type Reader
- type Trailer
Constants ¶
const ( // Magic is the first 4 bytes of every LTX file. Magic = "LTX1" // Version is the current version of the LTX file format. Version = 1 )
const ( HeaderSize = 100 PageHeaderSize = 4 TrailerSize = 16 )
Size constants.
const ( ChecksumSize = 8 TrailerChecksumOffset = TrailerSize - ChecksumSize )
Checksum size & positions.
const ( // ChecksumFlag is a flag on the checksum to ensure it is non-zero. ChecksumFlag uint64 = 1 << 63 // ChecksumMask is the mask of the bits used for the page checksum. ChecksumMask uint64 = (1 << 63) - 1 )
const MaxPageSize = 65536
MaxPageSize is the maximum allowed page size for SQLite.
Variables ¶
var ( ErrInvalidFile = errors.New("invalid LTX file") ErrDecoderClosed = errors.New("ltx decoder closed") ErrEncoderClosed = errors.New("ltx encoder closed") ErrNoChecksum = errors.New("no file checksum") ErrInvalidChecksumFormat = errors.New("invalid file checksum format") ErrChecksumMismatch = errors.New("file checksum mismatch") )
Errors
Functions ¶
func ChecksumPage ¶
ChecksumPage returns a CRC64 checksum that combines the page number & page data.
func ChecksumReader ¶ added in v0.2.1
ChecksumReader reads an entire database file from r and computes its rolling checksum.
func FormatFilename ¶
FormatFilename returns an LTX filename representing a range of transactions.
func FormatTXID ¶
FormatTXID returns id formatted as a fixed-width hex number.
func IsValidHeaderFlags ¶
IsValidHeaderFlags returns true if flags are unset. Flags are reserved.
func IsValidPageSize ¶
IsValidPageSize returns true if sz is between 512 and 64K and a power of two.
func ParseFilename ¶
ParseFilename parses a transaction range from an LTX file.
Types ¶
type Compactor ¶
type Compactor struct {
// contains filtered or unexported fields
}
Compactor represents a compactor of LTX files.
func NewCompactor ¶
NewCompactor returns a new instance of Compactor with default settings.
type Decoder ¶ added in v0.2.2
type Decoder struct {
// contains filtered or unexported fields
}
Decoder represents a decoder of an LTX file.
func NewDecoder ¶ added in v0.2.2
NewDecoder returns a new instance of Decoder.
func (*Decoder) Close ¶ added in v0.2.2
Close verifies the reader is at the end of the file and that the checksum matches.
func (*Decoder) DecodeHeader ¶ added in v0.2.2
DecodeHeader reads the LTX file header frame and stores it internally. Call Header() to retrieve the header after this is successfully called.
func (*Decoder) DecodePage ¶ added in v0.2.2
func (dec *Decoder) DecodePage(hdr *PageHeader, data []byte) error
DecodePage reads the next page header into hdr and associated page data.
type Encoder ¶ added in v0.2.2
type Encoder struct {
// contains filtered or unexported fields
}
Encoder implements a encoder for an LTX file.
func NewEncoder ¶ added in v0.2.2
NewEncoder returns a new instance of Encoder.
func (*Encoder) EncodeHeader ¶ added in v0.2.2
EncodeHeader writes hdr to the file's header block.
func (*Encoder) EncodePage ¶ added in v0.2.2
func (enc *Encoder) EncodePage(hdr PageHeader, data []byte) (err error)
EncodePage writes hdr & data to the file's page block.
func (*Encoder) SetPostApplyChecksum ¶ added in v0.2.2
SetPostApplyChecksum sets the post-apply checksum of the database. Must call before Close().
type FileSpec ¶
FileSpec is an in-memory representation of an LTX file. Typically used for testing.
type Header ¶
type Header struct {
Version int // based on magic
Flags uint32 // reserved flags
PageSize uint32 // page size, in bytes
Commit uint32 // db size after transaction, in pages
MinTXID uint64 // minimum transaction ID
MaxTXID uint64 // maximum transaction ID
Timestamp uint64 // seconds since unix epoch
PreApplyChecksum uint64 // rolling checksum of database before applying this LTX file
}
Header represents the header frame of an LTX file.
func (*Header) IsSnapshot ¶
IsSnapshot returns true if header represents a complete database snapshot. This is true if the header includes the initial transaction. Snapshots must include all pages in the database.
func (*Header) MarshalBinary ¶
MarshalBinary encodes h to a byte slice.
func (*Header) UnmarshalBinary ¶
UnmarshalBinary decodes h from a byte slice.
type PageHeader ¶
type PageHeader struct {
Pgno uint32
}
PageHeader represents the header for a single page in an LTX file.
func (*PageHeader) IsZero ¶ added in v0.2.0
func (h *PageHeader) IsZero() bool
IsZero returns true if the header is empty.
func (*PageHeader) MarshalBinary ¶
func (h *PageHeader) MarshalBinary() ([]byte, error)
MarshalBinary encodes h to a byte slice.
func (*PageHeader) UnmarshalBinary ¶
func (h *PageHeader) UnmarshalBinary(b []byte) error
UnmarshalBinary decodes h from a byte slice.
func (*PageHeader) Validate ¶
func (h *PageHeader) Validate() error
Validate returns an error if h is invalid.
type PageSpec ¶ added in v0.2.0
type PageSpec struct {
Header PageHeader
Data []byte
}
PageSpec is an in-memory representation of an LTX page frame. Typically used for testing.
type Reader ¶ added in v0.2.0
type Reader struct {
// contains filtered or unexported fields
}
Reader is a passthrough that validates the contents of the underlying reader.
func (*Reader) Header ¶ added in v0.2.0
Header returns a copy of the header. Available after DecodeHeader().
func (*Reader) PeekHeader ¶ added in v0.2.2
PeekHeader reads the header into a buffer and allows the caller to inspect it.
func (*Reader) Read ¶ added in v0.2.2
Read reads bytes from the underlying reader into p. Returns io.ErrShortBuffer if len(p) is less than the size of the page frame.
type Trailer ¶ added in v0.2.0
type Trailer struct {
PostApplyChecksum uint64 // rolling checksum of database after this LTX file is applied
FileChecksum uint64 // crc64 checksum of entire file
}
Trailer represents the ending frame of an LTX file.
func (*Trailer) MarshalBinary ¶ added in v0.2.0
MarshalBinary encodes h to a byte slice.
func (*Trailer) UnmarshalBinary ¶ added in v0.2.0
UnmarshalBinary decodes h from a byte slice.