Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateChecksum(data []byte) uint32
- func Checksum(data []byte) uint32
- func EncodeLeafRef(ptr LeafLogPtr) (uint64, error)
- func EncodePackedValuePtr(dst []byte, ptr ValuePtr)
- func IsLeafRefID(id uint64) bool
- func IsValueLogFileID(id uint32) bool
- func UpdateChecksum(data []byte) uint32
- func ValueLogFileID(id uint32) uint32
- func ValueLogSegmentID(id uint32) uint32
- func ValuePtrIsCompressed(ptr ValuePtr) bool
- func ValuePtrIsGrouped(ptr ValuePtr) bool
- func ValuePtrMarkCompressed(length uint32) uint32
- func ValuePtrMarkGrouped(length uint32, subIndex uint8) uint32
- func ValuePtrRecordLength(ptr ValuePtr) uint32
- func ValuePtrRecordLengthHintMatches(ptr ValuePtr, expected uint32) bool
- func ValuePtrSubIndex(ptr ValuePtr) uint8
- func VerifyChecksumNonMutating(data []byte) bool
- type FreelistPageBody
- type LeafLogPtr
- type MetaPageBody
- type PageHeader
- type PageType
- type ValuePtr
Constants ¶
const ( // PageSize is the fixed size of a page in bytes. PageSize = 4096 // DefaultInlineThreshold determines when a value is stored in the value log. DefaultInlineThreshold = 512 // PageHeaderSize is the size of the PageHeader struct. PageHeaderSize = 16 // ValuePtrSize is the size of the ValuePtr struct. ValuePtrSize = 16 // PackedValuePtrSize is the on-disk size of a packed ValuePtr encoding. // // Layout: Offset32 (u32 LE) | Length (u32 LE) | FileID (u32 LE). // This is used by experimental leaf encodings to reduce pointer payload. PackedValuePtrSize = 12 )
const MaxFreeIDs = 509
MaxFreeIDs per page. PageSize (4096) - Header (16) - NextPageID (8) = 4072 bytes. Each ID = 8 bytes. 4072 / 8 = 509.
const MetaPageBodySize = 60
const ValuePtrGroupedMaxRecordLen uint32 = 0x00ffffff
ValuePtrGroupedMaxRecordLen is the maximum record length (excluding CRC) that can be encoded in a grouped ValuePtr length hint for new writes.
Grouped pointers embed a sub-index in the Length field, leaving 24 bits for a best-effort record length hint. Larger records must set the hint to 0 and rely on the value-log record header's ValueLen instead.
Variables ¶
var ErrFreelistEmpty = errors.New("freelist page is empty")
var ErrFreelistFull = errors.New("freelist page is full")
var ErrInvalidPageType = errors.New("invalid page type")
Functions ¶
func CalculateChecksum ¶
CalculateChecksum computes the checksum of the page data, treating checksum bytes 8-11 (data[8:12]) as zero.
func EncodeLeafRef ¶ added in v0.4.0
func EncodeLeafRef(ptr LeafLogPtr) (uint64, error)
func EncodePackedValuePtr ¶ added in v0.3.0
EncodePackedValuePtr encodes ptr into dst using the packed 12-byte encoding. dst must be at least PackedValuePtrSize bytes.
Packed pointers store Offset as u32. Callers must ensure ptr.Offset fits.
func IsLeafRefID ¶ added in v0.5.0
func IsValueLogFileID ¶
IsValueLogFileID reports whether the FileID references a value-log segment.
func UpdateChecksum ¶ added in v0.4.0
UpdateChecksum computes CRC32C for the page while treating checksum bytes 8-11 (data[8:12]) as zero, then writes the computed checksum back into the page header. It mutates data in-place and returns the computed checksum.
func ValueLogFileID ¶
ValueLogFileID marks a value-log segment ID for use in ValuePtr.FileID.
func ValueLogSegmentID ¶
ValueLogSegmentID strips the value-log marker bit from a FileID.
func ValuePtrIsCompressed ¶
ValuePtrIsCompressed reports whether the pointer references a compressed value.
func ValuePtrIsGrouped ¶ added in v0.2.0
ValuePtrIsGrouped reports whether the pointer references a grouped record.
func ValuePtrMarkCompressed ¶
ValuePtrMarkCompressed sets the compression flag on a record length.
func ValuePtrMarkGrouped ¶ added in v0.2.0
ValuePtrMarkGrouped sets the grouped flag and sub-index (0-127) on a record length.
func ValuePtrRecordLength ¶
ValuePtrRecordLength returns the record length with internal flags stripped.
func ValuePtrRecordLengthHintMatches ¶ added in v0.4.0
ValuePtrRecordLengthHintMatches reports whether the encoded record-length hint matches expected.
A zero hint means "omitted hint" and always matches.
func ValuePtrSubIndex ¶ added in v0.2.0
ValuePtrSubIndex returns the row index within a grouped record.
func VerifyChecksumNonMutating ¶
VerifyChecksumNonMutating verifies that the page checksum matches the data, assuming checksum bytes 8-11 (data[8:12]) are zero for the calculation. It avoids modifying the underlying buffer.
Types ¶
type FreelistPageBody ¶
FreelistPageBody represents the body of a Freelist Page. Layout: NextPageID (8 bytes) Count (2 bytes) -- Wait, Header has Count? Standard Header has `Count`. We can use that. But we need to encode the array. NextPageID (8 bytes) + Array[uint64]
func DecodeFreelistBody ¶
func DecodeFreelistBody(buf []byte, count uint16) FreelistPageBody
func (*FreelistPageBody) Encode ¶
func (f *FreelistPageBody) Encode(buf []byte)
type LeafLogPtr ¶ added in v0.5.0
LeafLogPtr points to a leaf page stored in the external leaf log.
The FileID is the raw segment identifier in the leaf-log namespace. It is intentionally distinct from ValuePtr.FileID, which carries the value-log marker bit for payload lookups.
func DecodeLeafRef ¶ added in v0.4.0
func DecodeLeafRef(id uint64) (LeafLogPtr, bool)
func DecodeLeafRefID ¶ added in v0.5.0
func DecodeLeafRefID(id uint64) LeafLogPtr
func LeafLogPtrFromValuePtr ¶ added in v0.5.0
func LeafLogPtrFromValuePtr(ptr ValuePtr) (LeafLogPtr, error)
func (LeafLogPtr) ValueLogFileID ¶ added in v0.5.0
func (ptr LeafLogPtr) ValueLogFileID() uint32
func (LeafLogPtr) ValuePtr ¶ added in v0.5.0
func (ptr LeafLogPtr) ValuePtr() ValuePtr
type MetaPageBody ¶
type MetaPageBody struct {
CommitSeq uint64
UserRootPageID uint64
SystemRootPageID uint64
FreelistHeadID uint64
TotalPages uint64
ActiveSlabID uint32
ActiveSlabTail uint64
LastCommitHeight uint64
}
MetaPageBody represents the body of the Superblock.
func DecodeMetaBody ¶
func DecodeMetaBody(buf []byte) MetaPageBody
DecodeMetaBody decodes the MetaPageBody from the provided buffer.
func (*MetaPageBody) Encode ¶
func (m *MetaPageBody) Encode(buf []byte)
EncodeMetaBody encodes the MetaPageBody into the provided buffer.
type PageHeader ¶
PageHeader represents the 16-byte header of a page. | PageID (8 bytes) | | Checksum (4 bytes) | | Flags (2 bytes) | | Count (2 bytes) |
func DecodeHeader ¶
func DecodeHeader(buf []byte) PageHeader
DecodeHeader decodes the PageHeader from the provided buffer.
func UnsafeCastHeader ¶
func UnsafeCastHeader(data []byte) *PageHeader
CastHeader casts the beginning of a byte slice to a PageHeader struct pointer. Use with caution: implies unsafe access and assumes strict layout matching. This is an alternative to Encode/Decode for zero-copy access if needed, but requires the struct memory layout to match the wire format (packing). Go structs usually have padding/alignment. PageHeader: 8 + 4 + 2 + 2 = 16 bytes. Naturally aligned. ValuePtr: 8 + 4 + 2 + 2 = 16 bytes. Naturally aligned. So, we can use unsafe casting if endianness matches the machine's endianness. However, the spec requires LittleEndian. If the host is BigEndian, this fails. For now, we stick to Encode/Decode or binary.LittleEndian read/write for safety across archs unless zero-copy is strictly required and we add endianness checks. The spec mentions: "Implementation Note: To maximize throughput... use unsafe.Pointer casting". This implies the on-disk format should match the in-memory struct layout, AND the machine is likely LittleEndian (standard for Cosmos/x86/ARM). Let's implement a UnsafeCastHeader for when we have the mmap slice.
func (*PageHeader) Encode ¶
func (h *PageHeader) Encode(buf []byte)
EncodeHeader encodes the PageHeader into the provided buffer. The buffer must be at least PageHeaderSize bytes.
type PageType ¶
type PageType uint16
PageType represents the type of page (Meta, Freelist, Internal, Leaf).
type ValuePtr ¶
ValuePtr points to data stored in the value log. | Offset (8 bytes) | // 8-byte aligned | Length (4 bytes) | | FileID (4 bytes) |
func DecodePackedValuePtr ¶ added in v0.3.0
DecodePackedValuePtr decodes a packed 12-byte ValuePtr from src. src must be at least PackedValuePtrSize bytes.
func DecodeValuePtr ¶
DecodeValuePtr decodes the ValuePtr from the provided buffer.