Documentation
¶
Index ¶
- Constants
- Variables
- type CompressionKind
- type CompressionOptions
- type Options
- type SlabFile
- func (s *SlabFile) Close() error
- func (s *SlabFile) Read(offset int64, verifyCRC bool) ([]byte, error)
- func (s *SlabFile) ReadUnsafe(offset int64, verifyCRC bool) ([]byte, error)
- func (s *SlabFile) RepairTail() error
- func (s *SlabFile) Sync() error
- func (s *SlabFile) Truncate(size int64) error
- func (s *SlabFile) Write(key, value []byte) (int64, error)
- func (s *SlabFile) WriteBatch(buf []byte) (int64, error)
- type SlabManager
- func (sm *SlabManager) AcquireSlabs(set *SlabSet)
- func (sm *SlabManager) ActiveSlabID() uint32
- func (sm *SlabManager) ActiveSlabTail() uint64
- func (sm *SlabManager) Append(key, value []byte) (page.ValuePtr, error)
- func (sm *SlabManager) AppendMany(keys [][]byte, values [][]byte) ([]page.ValuePtr, error)
- func (sm *SlabManager) Close() error
- func (sm *SlabManager) CurrentSlabSet() *SlabSet
- func (sm *SlabManager) Flush() error
- func (sm *SlabManager) GetSlabPath(id uint32) string
- func (sm *SlabManager) MarkZombie(id uint32) error
- func (sm *SlabManager) PruneSlabs(maxID uint32) error
- func (sm *SlabManager) Read(ptr page.ValuePtr) ([]byte, error)
- func (sm *SlabManager) ReadUnsafe(ptr page.ValuePtr) ([]byte, error)
- func (sm *SlabManager) ReleaseSlabs(set *SlabSet) error
- func (sm *SlabManager) RemapStats() (remaps uint64, deadMappings uint64)
- func (sm *SlabManager) RemoveSlab(id uint32) error
- func (sm *SlabManager) RepairActiveSlabTail() (uint64, error)
- func (sm *SlabManager) Rotate() (*SlabFile, error)
- func (sm *SlabManager) SetActiveSlab(id uint32) error
- func (sm *SlabManager) SetDisableReadChecksum(disable bool)
- func (sm *SlabManager) Sync() error
- func (sm *SlabManager) TruncateActiveSlab(offset uint64) error
- func (sm *SlabManager) ZombieCount() int
- type SlabSet
Constants ¶
const (
// HeaderSize: CRC(4) + KeyLen(2) + ValueLen(4)
HeaderSize = 10
)
Variables ¶
var ( // MaxSlabSize is 4GB (hard limit for rotation). // Variable to allow testing overrides. MaxSlabSize int64 = 4 * 1024 * 1024 * 1024 // MaxRecordSize bounds a single slab record (header + key + value). // Set <= 0 to disable the cap. MaxRecordSize int64 = 64 * 1024 * 1024 // MaxDeadMappings caps the number of old mmaps retained to avoid exhausting // vm.max_map_count. Set <= 0 to disable the cap. MaxDeadMappings = 64 )
Functions ¶
This section is empty.
Types ¶
type CompressionKind ¶
type CompressionKind uint8
const ( CompressionNone CompressionKind = iota CompressionZSTD )
type CompressionOptions ¶
type CompressionOptions struct {
Kind CompressionKind
MinBytes int
MinSavingsBytes int
}
type Options ¶
type Options struct {
Compression CompressionOptions
}
type SlabFile ¶
type SlabFile struct {
ID uint32
Path string
File *os.File
RefCount atomic.Int64
IsZombie atomic.Bool
Size int64 // Track size for rotation
// contains filtered or unexported fields
}
SlabFile represents a single physical .slab file.
func OpenSlabLazy ¶
OpenSlabLazy registers a slab without opening its file descriptor.
func OpenSlabLazyReadOnly ¶
OpenSlabLazyReadOnly registers a slab without opening its file descriptor in read-only mode.
func OpenSlabReadOnly ¶
OpenSlabReadOnly opens an existing slab file in read-only mode.
func (*SlabFile) Read ¶
ReadAt reads a record at the given offset (which points to KeyLen, skipping CRC).
func (*SlabFile) ReadUnsafe ¶
ReadUnsafe returns a zero-copy view of the record. It forces a synchronous remap if the current mapping does not cover the record.
func (*SlabFile) RepairTail ¶
RepairTail scans the slab file to find the last complete (and checksummed) record and truncates any partial/corrupt tail bytes. This is primarily a crash-recovery helper.
type SlabManager ¶
type SlabManager struct {
// contains filtered or unexported fields
}
func NewSlabManager ¶
func NewSlabManager(dir string) (*SlabManager, error)
func NewSlabManagerReadOnly ¶
func NewSlabManagerReadOnly(dir string, opts Options) (*SlabManager, error)
func NewSlabManagerWithOptions ¶
func NewSlabManagerWithOptions(dir string, opts Options) (*SlabManager, error)
func (*SlabManager) AcquireSlabs ¶
func (sm *SlabManager) AcquireSlabs(set *SlabSet)
AcquireSlabs increments the RefCount for the Set (O(1)).
func (*SlabManager) ActiveSlabID ¶
func (sm *SlabManager) ActiveSlabID() uint32
func (*SlabManager) ActiveSlabTail ¶
func (sm *SlabManager) ActiveSlabTail() uint64
func (*SlabManager) Append ¶
func (sm *SlabManager) Append(key, value []byte) (page.ValuePtr, error)
func (*SlabManager) AppendMany ¶
AppendMany appends multiple records while amortizing system calls. It returns a pointer for each key/value pair (same order as inputs).
Thread-safety: This is serialized by the SlabManager mutex.
func (*SlabManager) Close ¶
func (sm *SlabManager) Close() error
func (*SlabManager) CurrentSlabSet ¶
func (sm *SlabManager) CurrentSlabSet() *SlabSet
CurrentSlabSet returns a snapshot of the current slabs.
func (*SlabManager) Flush ¶ added in v0.2.0
func (sm *SlabManager) Flush() error
Flush writes any buffered appends to disk (without fsync).
func (*SlabManager) GetSlabPath ¶
func (sm *SlabManager) GetSlabPath(id uint32) string
GetSlabPath returns the path for a given slab ID.
func (*SlabManager) MarkZombie ¶
func (sm *SlabManager) MarkZombie(id uint32) error
MarkZombie removes a slab from the active set so future snapshots stop pinning it. The file is deleted once all snapshots release it.
func (*SlabManager) PruneSlabs ¶
func (sm *SlabManager) PruneSlabs(maxID uint32) error
func (*SlabManager) Read ¶
func (sm *SlabManager) Read(ptr page.ValuePtr) ([]byte, error)
Read reads from the slab file identified by ptr.FileID. For Snapshot Isolation, the caller should ensure the file is pinned via a Snapshot. If accessing without snapshot (e.g. during Compaction or internal ops), care must be taken. Current impl uses RLock on the master map, so it's safe against concurrent Close() initiated by Prune/Compaction IF Prune/Compaction removes from map.
func (*SlabManager) ReadUnsafe ¶
func (sm *SlabManager) ReadUnsafe(ptr page.ValuePtr) ([]byte, error)
func (*SlabManager) ReleaseSlabs ¶
func (sm *SlabManager) ReleaseSlabs(set *SlabSet) error
ReleaseSlabs decrements the Set RefCount. If 0, unpins files and cleans zombies.
func (*SlabManager) RemapStats ¶
func (sm *SlabManager) RemapStats() (remaps uint64, deadMappings uint64)
RemapStats returns cumulative mmap remap counts across slabs.
func (*SlabManager) RemoveSlab ¶
func (sm *SlabManager) RemoveSlab(id uint32) error
RemoveSlab deletes a slab file from disk and unregisters it from the manager. It is only safe to call when the slab is not referenced by any snapshots.
func (*SlabManager) RepairActiveSlabTail ¶
func (sm *SlabManager) RepairActiveSlabTail() (uint64, error)
RepairActiveSlabTail scans and truncates any partial/corrupt tail records on the active slab (best-effort crash recovery).
func (*SlabManager) Rotate ¶
func (sm *SlabManager) Rotate() (*SlabFile, error)
Rotate forces creation of a new active slab.
func (*SlabManager) SetActiveSlab ¶
func (sm *SlabManager) SetActiveSlab(id uint32) error
func (*SlabManager) SetDisableReadChecksum ¶
func (sm *SlabManager) SetDisableReadChecksum(disable bool)
func (*SlabManager) Sync ¶
func (sm *SlabManager) Sync() error
func (*SlabManager) TruncateActiveSlab ¶
func (sm *SlabManager) TruncateActiveSlab(offset uint64) error
func (*SlabManager) ZombieCount ¶
func (sm *SlabManager) ZombieCount() int
ZombieCount returns the number of zombie slabs.