Documentation
¶
Overview ¶
Package ltx reads and writes Liteserver Transaction (LTX) files.
Index ¶
- Constants
- Variables
- func ChecksumPage(pgno uint32, data []byte) uint64
- func FormatFilename(minTXID, maxTXID uint64) string
- func FormatTXID(id uint64) string
- func FormatTXIDRange(min, max uint64) string
- func IsValidHeaderFlags(flags uint32) bool
- func IsValidPageSize(sz uint32) bool
- func ParseFilename(name string) (minTXID, maxTXID uint64, err error)
- type Compactor
- type FileSpec
- type Header
- type PageHeader
- type PageSpec
- type Reader
- func (r *Reader) Checksum() uint64
- func (r *Reader) Close() error
- func (r *Reader) Header() Header
- func (r *Reader) N() int64
- func (r *Reader) ReadHeader() error
- func (r *Reader) ReadPage(hdr *PageHeader, data []byte) error
- func (r *Reader) Trailer() Trailer
- func (r *Reader) Verify() (Header, Trailer, error)
- type Trailer
- type Writer
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 = 52 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 )
Variables ¶
var ( ErrInvalidFile = errors.New("invalid LTX file") ErrReaderClosed = errors.New("reader closed") ErrWriterClosed = errors.New("writer 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 FormatFilename ¶
FormatFilename returns an LTX filename representing a range of transactions.
func FormatTXID ¶
FormatTXID returns id formatted as a fixed-width hex number.
func FormatTXIDRange ¶
FormatTXIDRange returns min & max formatted as a single number if equal or a range if different.
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 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
DBID uint32 // database ID
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 represents a reader of an LTX file.
func (*Reader) Checksum ¶ added in v0.2.0
Checksum returns the checksum of the file. Only valid after close.
func (*Reader) Close ¶ added in v0.2.0
Close verifies the reader is at the end of the file and that the checksum matches.
func (*Reader) ReadHeader ¶ added in v0.2.0
ReadHeader reads the LTX file header frame and stores it internally. Call Header() to retrieve the header after this is successfully called.
func (*Reader) ReadPage ¶ added in v0.2.0
func (r *Reader) ReadPage(hdr *PageHeader, data []byte) error
ReadPage reads the next page header into hdr and associated page data.
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.
type Writer ¶ added in v0.2.0
type Writer struct {
// contains filtered or unexported fields
}
Writer implements a writer an LTX file.
func (*Writer) SetPostApplyChecksum ¶ added in v0.2.0
SetPostApplyChecksum sets the post-apply checksum of the database. Must call before Close().
func (*Writer) Trailer ¶ added in v0.2.0
Trailer returns a copy of the trailer. File checksum available after Close().
func (*Writer) WriteHeader ¶ added in v0.2.0
WriteHeader writes hdr to the file's header block.