Documentation
¶
Index ¶
- Constants
- Variables
- func CalculateChecksum(data []byte) uint32
- func Checksum(data []byte) uint32
- func IsValueLogFileID(id uint32) bool
- func ValueLogFileID(id uint32) uint32
- func ValueLogSegmentID(id uint32) uint32
- func ValuePtrIsCompressed(ptr ValuePtr) bool
- func ValuePtrMarkCompressed(length uint32) uint32
- func ValuePtrRecordLength(ptr ValuePtr) uint32
- func VerifyChecksumNonMutating(data []byte) bool
- type FreelistPageBody
- 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 slab. DefaultInlineThreshold = 256 // PageHeaderSize is the size of the PageHeader struct. PageHeaderSize = 16 // ValuePtrSize is the size of the ValuePtr struct. ValuePtrSize = 16 )
const MaxFreeIDs = 509
MaxFreeIDs per page. PageSize (4096) - Header (16) - NextPageID (8) = 4072 bytes. Each ID = 8 bytes. 4072 / 8 = 509.
const MetaPageBodySize = 60
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 the checksum field (bytes 8-12) as zero.
func IsValueLogFileID ¶
IsValueLogFileID reports whether the FileID references a value-log segment.
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 ValuePtrMarkCompressed ¶
ValuePtrMarkCompressed sets the compression flag on a record length.
func ValuePtrRecordLength ¶
ValuePtrRecordLength returns the record length with internal flags stripped.
func VerifyChecksumNonMutating ¶
VerifyChecksumNonMutating verifies that the page checksum matches the data, assuming the checksum field (bytes 8-12) is 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 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 Slabs. | Offset (8 bytes) | // 8-byte aligned | Length (4 bytes) | | FileID (4 bytes) |
func DecodeValuePtr ¶
DecodeValuePtr decodes the ValuePtr from the provided buffer.