Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeFileID(fileID uint32) (lane uint32, seq uint32)
- func DecodeSegmentID(id uint32) (lane uint32, seq uint32)
- func EncodeFileID(lane uint32, seq uint32) (uint32, error)
- func EncodeSegmentID(lane uint32, seq uint32) (uint32, error)
- func GenerateAutotuneValues(workload AutotuneWorkload, size, count int, seed int64) [][]byte
- func ReadAt(f *os.File, ptr page.ValuePtr, verifyCRC bool) ([]byte, error)
- func ReadAtWithDict(f *os.File, ptr page.ValuePtr, verifyCRC bool, dictLookup DictLookup) ([]byte, error)
- func ShouldKeepCompressed(rawBytes, encodedBytes int, encodeNs int64, ...) bool
- type AutotuneMode
- type AutotuneOptions
- type AutotuneWorkload
- type Clock
- type DictLookup
- type EncodeCostModel
- type EncodeCostModelFunc
- type File
- func (f *File) Close() error
- func (f *File) Read(ptr page.ValuePtr, verifyCRC bool) ([]byte, error)
- func (f *File) ReadAppend(ptr page.ValuePtr, verifyCRC bool, dst []byte) ([]byte, error)
- func (f *File) ReadUnsafe(ptr page.ValuePtr, verifyCRC bool) ([]byte, error)
- func (f *File) ReadUnsafeAppend(ptr page.ValuePtr, verifyCRC bool, dst []byte) ([]byte, error)
- type FrameHeader
- type FrameStats
- type Manager
- func (m *Manager) Acquire(set *Set)
- func (m *Manager) Close() error
- func (m *Manager) CurrentSet() *Set
- func (m *Manager) MarkZombie(id uint32) error
- func (m *Manager) Read(ptr page.ValuePtr) ([]byte, error)
- func (m *Manager) ReadAppend(ptr page.ValuePtr, dst []byte) ([]byte, error)
- func (m *Manager) ReadUnsafe(ptr page.ValuePtr) ([]byte, error)
- func (m *Manager) ReadUnsafeAppend(ptr page.ValuePtr, dst []byte) ([]byte, error)
- func (m *Manager) Refresh() error
- func (m *Manager) Release(set *Set) error
- func (m *Manager) RemapStats() (remaps uint64, deadMappings uint64)
- func (m *Manager) RemoveSegment(id uint32) error
- func (m *Manager) RemoveSegmentForce(id uint32) error
- func (m *Manager) SegmentPath(id uint32) string
- func (m *Manager) SetDictLookup(lookup DictLookup)
- func (m *Manager) SetDisableReadChecksum(disable bool)
- type Reader
- type RealClock
- type Record
- type Set
- type VirtualClock
- type VirtualSink
- type Writer
- func (w *Writer) Append(dictID uint64, dict []byte, rid uint64, value []byte) (page.ValuePtr, error)
- func (w *Writer) AppendFrame(dictID uint64, dict []byte, records []Record) ([]page.ValuePtr, error)
- func (w *Writer) AppendFrameWithStats(dictID uint64, dict []byte, records []Record) ([]page.ValuePtr, FrameStats, error)
- func (w *Writer) AppendFrameWithStatsInto(dictID uint64, dict []byte, records []Record, dst []page.ValuePtr) ([]page.ValuePtr, FrameStats, error)
- func (w *Writer) AppendRawFramesWritevInto(records []Record, k int, dst []page.ValuePtr) ([]page.ValuePtr, FrameStats, error)
- func (w *Writer) Close() error
- func (w *Writer) FileID() uint32
- func (w *Writer) Flush() error
- func (w *Writer) ResetCompressionHints()
- func (w *Writer) RotateTo(path string, fileID uint32) error
- func (w *Writer) SetClock(clock Clock)
- func (w *Writer) SetEncodeCostModel(model EncodeCostModel)
- func (w *Writer) SetEncodeSampleStride(stride uint64)
- func (w *Writer) SetKeepPolicy(ioNsPerStoredByte, encodeNsPerRawByte, safetyMargin float64)
- func (w *Writer) Size() int64
- func (w *Writer) Sync() error
Constants ¶
const ( Version = 1 HeaderSize = 4 + 1 + 1 + 2 + 8 + 4 )
const ( FrameVersion = 1 FrameHeaderSize = 12 MaxFrameK = 32 )
const DefaultKeepSafetyMargin = 0.10
const (
FrameFlagCompressed byte = 1 << 0
)
Variables ¶
var ( ErrCorrupt = errors.New("valuelog: corrupt record") ErrRecordTooLarge = errors.New("valuelog: record too large") ErrMissingDict = errors.New("valuelog: missing dict bytes") )
var ErrSegmentIDRange = errors.New("valuelog: segment id out of range")
var MaxDeadMappings = 64
MaxDeadMappings caps the number of old mmaps retained to avoid exhausting vm.max_map_count. Set <= 0 to disable the cap.
Each remap retains the previous mapping until the file is closed to avoid use-after-unmap with concurrent readers.
Functions ¶
func DecodeFileID ¶
func DecodeSegmentID ¶
func GenerateAutotuneValues ¶
func GenerateAutotuneValues(workload AutotuneWorkload, size, count int, seed int64) [][]byte
GenerateAutotuneValues builds deterministic samples for a workload.
func ReadAtWithDict ¶
Types ¶
type AutotuneMode ¶
type AutotuneMode uint8
const ( // AutotuneUnset indicates the caller did not explicitly configure the // autotuner mode. NormalizeAutotuneOptions maps this to a sensible default // based on whether SplitValueLog is enabled. AutotuneUnset AutotuneMode = iota AutotuneOff AutotuneMedium AutotuneAggressive )
type AutotuneOptions ¶
type AutotuneOptions struct {
Mode AutotuneMode
CandidateK []int
CandidateHistoryBytes []int
CandidateDictBytes []int
MinGainToSwitch float64
MinDwellFrames uint64
SampleStride uint64
MaxSampleBytes uint64
TrainCPUFraction float64
ProbeBytes uint64
PauseBytes uint64
DisableBelowValueBytes int
}
func NormalizeAutotuneOptions ¶
func NormalizeAutotuneOptions(opts AutotuneOptions, splitValueLog bool) AutotuneOptions
type AutotuneWorkload ¶
AutotuneWorkload describes a deterministic value generator.
func AutotuneWorkloads ¶
func AutotuneWorkloads() []AutotuneWorkload
AutotuneWorkloads returns the standard deterministic workloads used by the autotune bench suite.
func LookupAutotuneWorkload ¶
func LookupAutotuneWorkload(name string) (AutotuneWorkload, bool)
LookupAutotuneWorkload returns the workload with the given name.
type DictLookup ¶
type EncodeCostModel ¶
EncodeCostModel provides deterministic encode cost estimates (ns) for tests/benches. When set on a Writer, it overrides wall-time measurement for sampled frames.
type EncodeCostModelFunc ¶
EncodeCostModelFunc adapts a function to the EncodeCostModel interface.
type File ¶
type File struct {
ID uint32
Path string
File *os.File
RefCount atomic.Int64
IsZombie atomic.Bool
// contains filtered or unexported fields
}
File represents a value-log segment on disk.
func (*File) ReadAppend ¶
func (*File) ReadUnsafe ¶
type FrameStats ¶
type FrameStats struct {
Records int
RawPayloadBytes int
StoredPayloadBytes int
// Attempted is true when zstd encoding was executed (even if we fell back to raw).
Attempted bool
// Kept is true when compressed bytes were stored.
Kept bool
// EncodeNs is the sampled encode time (monotonic ns); 0 when not measured.
EncodeNs int64
}
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
func NewManager ¶
func (*Manager) CurrentSet ¶
CurrentSet returns a snapshot of the current value-log files.
func (*Manager) MarkZombie ¶
func (*Manager) ReadAppend ¶
func (*Manager) ReadUnsafeAppend ¶
func (*Manager) Release ¶
Release decrements the Set refcount and removes zombie files once unpinned.
func (*Manager) RemapStats ¶
func (*Manager) RemoveSegment ¶
func (*Manager) RemoveSegmentForce ¶
RemoveSegmentForce removes a segment without refcount checks. Intended for recovery cleanup before any snapshots are live.
func (*Manager) SegmentPath ¶
func (*Manager) SetDictLookup ¶
func (m *Manager) SetDictLookup(lookup DictLookup)
func (*Manager) SetDisableReadChecksum ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func (*Reader) DisableChecksum ¶
func (r *Reader) DisableChecksum()
func (*Reader) DisableValueDecode ¶
func (r *Reader) DisableValueDecode()
func (*Reader) SetDictLookup ¶
func (r *Reader) SetDictLookup(lookup DictLookup)
func (*Reader) ValidateDicts ¶
func (r *Reader) ValidateDicts()
ValidateDicts enables dictionary existence checks even when value decoding is disabled. This provides a low-cost "fail fast" validation pass during WAL replay and open.
type Set ¶
type Set struct {
Files map[uint32]*File
RefCount atomic.Int64
// contains filtered or unexported fields
}
Set is an immutable snapshot of value-log files for snapshot isolation.
type VirtualClock ¶
type VirtualClock struct {
// contains filtered or unexported fields
}
VirtualClock provides deterministic time control for tests.
func NewVirtualClock ¶
func NewVirtualClock(start time.Time) *VirtualClock
func (*VirtualClock) Advance ¶
func (c *VirtualClock) Advance(ns int64)
func (*VirtualClock) Now ¶
func (c *VirtualClock) Now() time.Time
type VirtualSink ¶
type VirtualSink struct {
Clock interface{ Advance(int64) }
NsPerByte int64
SyncPenaltyNs int64
FlushPenaltyNs int64
}
VirtualSink advances a clock based on written bytes to simulate IO wall time. Intended for deterministic tests/benchmarks.
func (*VirtualSink) Flush ¶
func (s *VirtualSink) Flush() error
func (*VirtualSink) Sync ¶
func (s *VirtualSink) Sync() error
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
func NewWriterWithSink ¶
NewWriterWithSink creates a value-log writer that writes to the provided sink. Intended for deterministic tests/benchmarks (no file-backed durability).
func (*Writer) AppendFrame ¶
func (*Writer) AppendFrameWithStats ¶
func (*Writer) AppendFrameWithStatsInto ¶
func (w *Writer) AppendFrameWithStatsInto(dictID uint64, dict []byte, records []Record, dst []page.ValuePtr) ([]page.ValuePtr, FrameStats, error)
AppendFrameWithStatsInto appends a grouped frame and fills dst with the returned pointers (dst must be at least len(records) long).
This is a performance-oriented helper to avoid allocating a new pointer slice on every frame append.
func (*Writer) AppendRawFramesWritevInto ¶
func (w *Writer) AppendRawFramesWritevInto(records []Record, k int, dst []page.ValuePtr) ([]page.ValuePtr, FrameStats, error)
AppendRawFramesWritevInto appends raw (uncompressed) grouped frames using a writev batching strategy.
This avoids concatenating payloads into a contiguous frame buffer, reducing user-space copying for large value workloads. It always flushes the writev queue before returning, so it does not retain references to the input slices.
dst must be at least len(records) long.
func (*Writer) ResetCompressionHints ¶
func (w *Writer) ResetCompressionHints()
ResetCompressionHints clears skip/backoff state for deterministic benches.
func (*Writer) SetEncodeCostModel ¶
func (w *Writer) SetEncodeCostModel(model EncodeCostModel)