Documentation
¶
Index ¶
- Constants
- Variables
- func BatchPutStruct[T any](b *Batch, key []byte, v *T) error
- func CompareKeys(a, b []byte) int
- func DecodeJson(data []byte, dest any) error
- func DecodeMsgpack(data []byte) (map[string]any, error)
- func EncodeEntry(e Entry) []byte
- func EncodeJson(data any) ([]byte, error)
- func EncodeMsgpack(record map[string]any) ([]byte, error)
- func EncodeValue(v Value) []byte
- func GetStruct[T any](s *Store, key []byte) (*T, error)
- func GetStructInto[T any](s *Store, key []byte, dest *T) error
- func GetStructZeroCopy[T any](s *Store, key []byte, fn func(v *T) error) error
- func NewLRUCache(capacity int64) *lruCache
- func NewSSTableWriter(id uint32, path string, numKeys uint, opts Options) (*sstableWriter, error)
- func PutStruct[T any](s *Store, key []byte, v *T) error
- func PutStructs[T any](s *Store, items []KeyValue[T]) error
- func SSTableFilename(id uint32) string
- func SSTablePath(dir string, id uint32) string
- func ScanPrefixJson[T any](s *Store, prefix []byte, fn func(key []byte, val *T) bool) error
- func ScanPrefixStructs[T any](s *Store, prefix []byte, fn func(key []byte, val *T) bool) error
- func ScanPrefixStructsZeroCopy[T any](s *Store, prefix []byte, fn func(key []byte, val *T) bool) error
- func ScanRangeJson[T any](s *Store, start, end []byte, fn func(key []byte, val *T) bool) error
- func ScanRangeStructs[T any](s *Store, start, end []byte, fn func(key []byte, val *T) bool) error
- func ScanRangeStructsZeroCopy[T any](s *Store, start, end []byte, fn func(key []byte, val *T) bool) error
- type AggregateResult
- type Batch
- func (b *Batch) Delete(key []byte)
- func (b *Batch) Len() int
- func (b *Batch) Put(key []byte, value Value)
- func (b *Batch) PutBytes(key, value []byte)
- func (b *Batch) PutInt64(key []byte, value int64)
- func (b *Batch) PutJson(key []byte, data any) error
- func (b *Batch) PutMap(key []byte, fields map[string]any) error
- func (b *Batch) PutString(key []byte, value string)
- func (b *Batch) Reset()
- type Block
- type BlockEntry
- type BloomFilter
- type CacheStats
- type CompactionStyle
- type CompressionType
- type Entry
- type Index
- type IndexEntry
- type KeyLocation
- type KeyValue
- type LevelStats
- type Manifest
- type Options
- type PrefixTableInfo
- type SSTable
- func (sst *SSTable) Close() error
- func (sst *SSTable) DecRef()
- func (sst *SSTable) Get(key []byte, cache *lruCache, verifyChecksum bool) (Entry, bool, error)
- func (sst *SSTable) IncRef()
- func (sst *SSTable) MarkForRemoval()
- func (sst *SSTable) MaxKey() []byte
- func (sst *SSTable) MemorySize() int64
- func (sst *SSTable) MinKey() []byte
- func (sst *SSTable) Size() int64
- type SSTableFooter
- type SSTableMeta
- type ScanProgress
- type ScanStats
- type Store
- func (s *Store) Aggregate(prefix []byte, field string) (AggregateResult, error)
- func (s *Store) Avg(prefix []byte, field string) (float64, error)
- func (s *Store) Close() error
- func (s *Store) Compact() error
- func (s *Store) Count(prefix []byte) (int64, error)
- func (s *Store) Delete(key []byte) error
- func (s *Store) DeletePrefix(prefix []byte) (int64, error)
- func (s *Store) DeleteRange(start, end []byte) (int64, error)
- func (s *Store) ExplainPrefix(prefix []byte) []PrefixTableInfo
- func (s *Store) FindKey(key []byte) *KeyLocation
- func (s *Store) Flush() error
- func (s *Store) Get(key []byte) (Value, error)
- func (s *Store) GetBool(key []byte) (bool, error)
- func (s *Store) GetBytes(key []byte) ([]byte, error)
- func (s *Store) GetFloat64(key []byte) (float64, error)
- func (s *Store) GetInt64(key []byte) (int64, error)
- func (s *Store) GetJson(key []byte, dest any) error
- func (s *Store) GetMap(key []byte) (map[string]any, error)
- func (s *Store) GetMapZeroCopy(key []byte, fn func(m map[string]any) error) error
- func (s *Store) GetString(key []byte) (string, error)
- func (s *Store) Increment(key []byte, delta int64) (int64, error)
- func (s *Store) Max(prefix []byte, field string) (float64, error)
- func (s *Store) Min(prefix []byte, field string) (float64, error)
- func (s *Store) Put(key []byte, value Value) error
- func (s *Store) PutBool(key []byte, value bool) error
- func (s *Store) PutBytes(key, value []byte) error
- func (s *Store) PutFloat64(key []byte, value float64) error
- func (s *Store) PutIfEquals(key []byte, value Value, expected Value) error
- func (s *Store) PutIfNotExists(key []byte, value Value) error
- func (s *Store) PutInt64(key []byte, value int64) error
- func (s *Store) PutJson(key []byte, data any) error
- func (s *Store) PutMap(key []byte, fields map[string]any) error
- func (s *Store) PutString(key []byte, value string) error
- func (s *Store) ScanPrefix(prefix []byte, fn func(key []byte, value Value) bool) error
- func (s *Store) ScanPrefixMaps(prefix []byte, fn func(key []byte, m map[string]any) bool) error
- func (s *Store) ScanPrefixMapsZeroCopy(prefix []byte, fn func(key []byte, m map[string]any) bool) error
- func (s *Store) ScanPrefixWithStats(prefix []byte, fn func(key []byte, value Value) bool, progress ScanProgress) (ScanStats, error)
- func (s *Store) ScanRange(start, end []byte, fn func(key []byte, value Value) bool) error
- func (s *Store) ScanRangeMaps(start, end []byte, fn func(key []byte, m map[string]any) bool) error
- func (s *Store) Stats() StoreStats
- func (s *Store) Sum(prefix []byte, field string) (float64, error)
- func (s *Store) Sync() error
- func (s *Store) WriteBatch(batch *Batch) error
- type StoreStats
- type TableMeta
- type Value
- func BoolValue(v bool) Value
- func BytesValue(v []byte) Value
- func DecodeValue(data []byte) (Value, int, error)
- func DecodeValueZeroCopy(data []byte) (Value, int, error)
- func Float64Value(v float64) Value
- func Int64Value(v int64) Value
- func MsgpackValue(data []byte) Value
- func RecordValue(fields map[string]any) Value
- func StringValue(v string) Value
- func TombstoneValue() Value
- type ValueType
- type WALSyncMode
Constants ¶
const ( SSTableMagic uint64 = 0x544B5653_00000001 // "TKVS" + version 1 SSTableVersion uint32 = 1 )
SSTable magic number and version
SSTableFooterSize is the fixed size of the footer in bytes.
Variables ¶
var ( ErrInvalidManifest = errors.New("invalid manifest file") ErrManifestCorrupt = errors.New("manifest file corrupted") ErrManifestNotFound = errors.New("manifest file not found") )
var ( ErrStoreClosed = errors.New("store is closed") ErrStoreLocked = errors.New("store is locked by another process") ErrKeyExists = errors.New("key already exists") ErrConditionFailed = errors.New("condition failed") ErrTypeMismatch = errors.New("value type mismatch") )
Errors
var ( ErrKeyNotFound = errors.New("key not found") ErrInvalidValue = errors.New("invalid value encoding") ErrCorruptedData = errors.New("corrupted data") ErrChecksumMismatch = errors.New("checksum mismatch") )
Common errors
var (
ErrInvalidSSTable = errors.New("invalid sstable format")
)
Errors
Functions ¶
func BatchPutStruct ¶ added in v0.10.0
BatchPutStruct adds a struct to a batch using cached encoder.
func CompareKeys ¶
CompareKeys performs lexicographic comparison of two keys. Returns -1 if a < b, 0 if a == b, 1 if a > b. Uses bytes.Compare which is assembly-optimized on most platforms.
func DecodeJson ¶ added in v0.7.0
DecodeJson decodes JSON bytes into the provided destination.
func DecodeMsgpack ¶ added in v0.7.0
DecodeMsgpack decodes msgpack bytes into a record map.
func EncodeEntry ¶
EncodeEntry serializes an entry (key + value + sequence) to bytes.
func EncodeJson ¶ added in v0.7.0
EncodeJson encodes any value to JSON bytes.
func EncodeMsgpack ¶ added in v0.7.0
EncodeMsgpack encodes a record map to msgpack bytes.
func GetStruct ¶ added in v0.10.0
GetStruct retrieves and decodes a struct using pre-registered decoder (faster than method version). Use this in hot paths where performance matters.
func GetStructInto ¶ added in v0.10.0
GetStructInto retrieves and decodes a struct into an existing pointer. Avoids allocation when you already have a destination.
func GetStructZeroCopy ¶ added in v0.10.0
GetStructZeroCopy retrieves a struct with zero-copy strings. Strings are only valid within the callback - they point into the database buffer. This is the fastest way to read structs when you only need temporary access.
func NewLRUCache ¶
func NewLRUCache(capacity int64) *lruCache
NewLRUCache creates a new LRU cache with the given capacity in bytes.
func NewSSTableWriter ¶
NewSSTableWriter creates a new SSTable writer with bloom filter enabled. For internal use, use newSSTableWriter which allows disabling bloom filters.
func PutStructs ¶ added in v0.10.0
PutStructs writes multiple structs in parallel using cached encoder. Parallelizes encoding across CPU cores, then writes atomically.
func SSTableFilename ¶ added in v0.5.0
SSTableFilename returns the filename for an SSTable with the given ID.
func SSTablePath ¶ added in v0.5.0
SSTablePath returns the path for an SSTable with the given ID.
func ScanPrefixJson ¶ added in v0.7.1
ScanPrefixJson scans keys with the given prefix and decodes JSON values into a struct.
func ScanPrefixStructs ¶ added in v0.7.1
ScanPrefixStructs scans keys with the given prefix and decodes each value into a struct. Uses pre-registered decoder for best performance.
func ScanPrefixStructsZeroCopy ¶ added in v0.10.0
func ScanPrefixStructsZeroCopy[T any](s *Store, prefix []byte, fn func(key []byte, val *T) bool) error
ScanPrefixStructsZeroCopy scans keys with prefix using zero-copy decoding. Struct string fields are only valid within the callback - copy any you need.
func ScanRangeJson ¶ added in v0.7.1
ScanRangeJson scans keys in [start, end) and decodes JSON values into a struct.
func ScanRangeStructs ¶ added in v0.7.1
ScanRangeStructs scans keys in [start, end) and decodes each value into a struct. Uses pre-registered decoder for best performance.
Types ¶
type AggregateResult ¶ added in v0.7.0
type AggregateResult struct {
Count int64
Sum float64
Min float64
Max float64
// contains filtered or unexported fields
}
AggregateResult holds the result of an aggregation query.
func (AggregateResult) Avg ¶ added in v0.7.0
func (r AggregateResult) Avg() float64
Avg returns the average, or 0 if no values.
type Batch ¶ added in v0.6.0
type Batch struct {
// contains filtered or unexported fields
}
Batch accumulates multiple operations to be applied atomically.
func NewBatch ¶ added in v0.6.0
func NewBatch() *Batch
NewBatch creates a new batch for atomic writes.
type Block ¶
type Block struct {
Type uint8
Entries []BlockEntry
// contains filtered or unexported fields
}
Block represents a decompressed data block.
func DecodeBlock ¶
DecodeBlock decompresses and parses a block. The returned Block's entries reference the internal decompressed buffer, so the Block should not be modified and is only valid while cached. Call Block.Release() when done to return the buffer to the pool.
func (*Block) DecRef ¶ added in v0.11.1
DecRef decrements the block's reference count. When the count reaches zero, the buffer is returned to the pool. Returns true if the block was released (refcount hit 0).
func (*Block) IncRef ¶ added in v0.11.1
func (b *Block) IncRef()
IncRef increments the block's reference count. Call this when taking a reference to a cached block.
type BlockEntry ¶
BlockEntry represents a key-value pair within a block.
type BloomFilter ¶
type BloomFilter struct {
// contains filtered or unexported fields
}
BloomFilter wraps a bloom filter with serialization.
func DeserializeBloomFilter ¶
func DeserializeBloomFilter(data []byte) (*BloomFilter, error)
DeserializeBloomFilter recreates a bloom filter from bytes.
func NewBloomFilter ¶
func NewBloomFilter(numKeys uint, fpRate float64) *BloomFilter
NewBloomFilter creates a bloom filter for the expected number of keys.
func (*BloomFilter) Add ¶
func (bf *BloomFilter) Add(key []byte)
Add adds a key to the bloom filter.
func (*BloomFilter) MayContain ¶
func (bf *BloomFilter) MayContain(key []byte) bool
MayContain returns true if the key might be in the set. False positives are possible, but false negatives are not.
func (*BloomFilter) Serialize ¶
func (bf *BloomFilter) Serialize() ([]byte, error)
Serialize encodes the bloom filter for storage.
type CacheStats ¶
CacheStats contains cache statistics.
func (CacheStats) HitRate ¶
func (s CacheStats) HitRate() float64
HitRate returns the cache hit rate as a percentage.
type CompactionStyle ¶
type CompactionStyle int
CompactionStyle determines the compaction strategy.
const ( // CompactionStyleLeveled uses leveled compaction (read-optimized). CompactionStyleLeveled CompactionStyle = iota // CompactionStyleSizeTiered uses size-tiered compaction (write-optimized). CompactionStyleSizeTiered )
type CompressionType ¶ added in v0.4.0
type CompressionType int
CompressionType determines the compression algorithm.
const ( // CompressionZstd uses zstd compression (good compression, fast). CompressionZstd CompressionType = iota // CompressionSnappy uses snappy compression (faster, less compression). CompressionSnappy // CompressionNone disables compression. CompressionNone // CompressionMinLZ uses minlz compression (very fast, good compression). CompressionMinLZ )
type Entry ¶
type Entry struct {
Key []byte
Value Value
Sequence uint64 // Monotonic sequence number for ordering
}
Entry represents a key-value pair with metadata.
type Index ¶
type Index struct {
Entries []IndexEntry
MinKey []byte
MaxKey []byte
NumKeys uint64
}
Index provides efficient key lookup within an SSTable.
func DeserializeIndex ¶
DeserializeIndex recreates an index from bytes.
func (*Index) MemorySize ¶ added in v0.4.0
MemorySize returns the exact memory usage of this index in bytes.
type IndexEntry ¶
type IndexEntry struct {
Key []byte // First key in the block (separator key)
BlockOffset uint64 // File offset to the block
BlockSize uint32 // Size of the compressed block
}
IndexEntry represents a sparse index entry pointing to a data block.
type KeyLocation ¶ added in v0.6.0
KeyLocation describes where a key is stored.
type LevelStats ¶
LevelStats contains statistics for a single level.
type Manifest ¶ added in v0.5.0
type Manifest struct {
// contains filtered or unexported fields
}
Manifest tracks all SSTables and their metadata. It's an append-only log that allows fast store recovery without reading every SSTable file.
func OpenManifest ¶ added in v0.5.0
OpenManifest opens or creates a manifest file.
func (*Manifest) DeleteTables ¶ added in v0.5.0
DeleteTables records removal of multiple SSTables atomically.
type Options ¶
type Options struct {
// Dir is the base directory for all data files.
Dir string
// MemtableSize is the max memtable size in bytes before flush.
// Default: 4MB
MemtableSize int64
// BlockCacheSize is the LRU cache size in bytes.
// Set to 0 for minimal memory usage (no caching).
// Default: 64MB
BlockCacheSize int64
// BlockSize is the target block size before compression.
// Default: 16KB
BlockSize int
// CompressionType determines which compression algorithm to use.
// Default: CompressionMinLZ
CompressionType CompressionType
// CompressionLevel is the compression level (ignored for snappy/none).
// For zstd: 1 = fastest, 3 = default, higher = better compression.
// For minlz: 1 = fastest, 2 = balanced, 3 = smallest.
// Default: 1 (fastest)
CompressionLevel int
// BloomFPRate is the target false positive rate for bloom filters.
// Default: 0.01 (1%)
BloomFPRate float64
// CompactionStyle determines the compaction strategy.
// Default: CompactionStyleLeveled
CompactionStyle CompactionStyle
// L0CompactionTrigger is the number of L0 files that triggers compaction.
// Default: 4
L0CompactionTrigger int
// L0CompactionBatchSize limits how many L0 files to compact at once.
// Lower values mean faster individual compactions but more total compactions.
// Default: 0 (no limit - compact all L0 files)
L0CompactionBatchSize int
// MaxLevels is the maximum number of LSM levels.
// Default: 7
MaxLevels int
// LevelSizeMultiplier is the size ratio between adjacent levels.
// Default: 10
LevelSizeMultiplier int
// L1MaxSize is the maximum size of L1 level in bytes.
// L2+ sizes are calculated as L1MaxSize * LevelSizeMultiplier^(level-1).
// Default: 10MB (0 = use default)
L1MaxSize int64
// WALSyncMode determines when WAL is synced to disk.
// Default: WALSyncPerBatch
WALSyncMode WALSyncMode
// FlushInterval is the automatic flush interval.
// Default: 30s
FlushInterval time.Duration
// CompactionInterval is how often to check for compaction.
// Default: 1s
CompactionInterval time.Duration
// VerifyChecksums enables checksum verification on reads.
// Default: true
VerifyChecksums bool
// DisableBloomFilter disables bloom filters for minimal memory.
// Default: false
DisableBloomFilter bool
}
Options configures the Store behavior.
func DefaultOptions ¶
DefaultOptions returns production-ready defaults for the given directory.
func HighPerformanceOptions ¶
HighPerformanceOptions returns options optimized for performance.
func LowMemoryOptions ¶
LowMemoryOptions returns options for memory-constrained environments. Suitable for running billions of records on systems with <1GB RAM.
type PrefixTableInfo ¶ added in v0.9.1
type PrefixTableInfo struct {
Level int
TableID uint32
MinKey []byte
MaxKey []byte
NumKeys uint64
InRange bool // Prefix is within [MinKey, MaxKey]
HasMatch bool // Table actually contains keys with this prefix
FirstMatch []byte // First matching key (if HasMatch)
}
PrefixTableInfo describes an SSTable's relationship to a prefix.
type SSTable ¶
type SSTable struct {
ID uint32
Path string
Level int
Meta SSTableMeta
Index *Index
BloomFilter *BloomFilter
// contains filtered or unexported fields
}
SSTable represents an on-disk sorted string table.
func OpenSSTable ¶
OpenSSTable opens an existing SSTable file (eagerly loads index and bloom filter).
func OpenSSTableFromManifest ¶ added in v0.5.0
OpenSSTableFromManifest opens an SSTable using metadata from the manifest. Index and bloom filter are loaded lazily on first access.
func (*SSTable) DecRef ¶ added in v0.10.1
func (sst *SSTable) DecRef()
DecRef decrements the reference count. If the count reaches zero and the table is marked for removal, the file is closed and removed.
func (*SSTable) Get ¶
Get retrieves a value from the SSTable. Returns the entry, whether it was found, and any error.
func (*SSTable) IncRef ¶ added in v0.10.1
func (sst *SSTable) IncRef()
IncRef increments the reference count. Call this before using the SSTable in a goroutine that may outlive the current scope.
func (*SSTable) MarkForRemoval ¶ added in v0.10.1
func (sst *SSTable) MarkForRemoval()
MarkForRemoval marks this SSTable for removal after compaction. The file will be closed when all references are released.
func (*SSTable) MemorySize ¶ added in v0.4.0
MemorySize returns the in-memory size (index + bloom filter).
type SSTableFooter ¶
type SSTableFooter struct {
}
SSTableFooter is the fixed-size footer at the end of each SSTable.
type SSTableMeta ¶
type SSTableMeta struct {
Level int
MinSequence uint64
MaxSequence uint64
NumTombstones uint64
CreatedAt int64
}
SSTableMeta contains metadata about the SSTable.
type ScanProgress ¶ added in v0.8.0
ScanProgress is called periodically during scan operations to report progress. Return false to stop the scan early.
type ScanStats ¶ added in v0.8.0
type ScanStats struct {
BlocksLoaded int64 // Number of SSTable blocks accessed (disk + cache)
BlocksCacheHit int64 // Number of blocks served from cache
BlocksDiskRead int64 // Number of blocks read from disk
KeysExamined int64 // Total keys examined (including duplicates and tombstones)
TablesChecked int64 // Number of SSTables checked for prefix
TablesAdded int64 // Number of SSTables added to scanner (had matching entries)
}
ScanStats tracks statistics during scan operations.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the main key-value store.
func (*Store) Aggregate ¶ added in v0.7.0
func (s *Store) Aggregate(prefix []byte, field string) (AggregateResult, error)
Aggregate computes multiple aggregations in a single scan. For simple numeric values, pass empty string for field.
func (*Store) Avg ¶ added in v0.7.0
Avg returns the average of a numeric field across all records matching the prefix.
func (*Store) Compact ¶
Compact forces compaction of all L0 tables to L1. This makes reads faster by converting overlapping L0 tables to disjoint L1 tables.
func (*Store) DeletePrefix ¶ added in v0.6.0
DeletePrefix deletes all keys with the given prefix. Returns the number of keys deleted.
func (*Store) DeleteRange ¶ added in v0.6.0
DeleteRange deletes all keys in the range [start, end). This is more efficient than deleting keys one by one. Returns the number of keys deleted.
func (*Store) ExplainPrefix ¶ added in v0.9.1
func (s *Store) ExplainPrefix(prefix []byte) []PrefixTableInfo
ExplainPrefix returns information about which tables contain a given prefix.
func (*Store) FindKey ¶ added in v0.6.0
func (s *Store) FindKey(key []byte) *KeyLocation
FindKey returns the location of a key, or nil if in memtable or not found.
func (*Store) GetFloat64 ¶
GetFloat64 retrieves a float64 value by key.
func (*Store) GetJson ¶ added in v0.7.0
GetJson retrieves a JSON string and decodes it into the provided destination.
func (*Store) GetMapZeroCopy ¶ added in v0.10.0
GetMapZeroCopy retrieves a map with zero-copy strings. Strings are only valid within the callback - they point into the database buffer. Copy any strings you need to retain before the callback returns.
func (*Store) Increment ¶ added in v0.6.0
Increment atomically adds delta to an int64 value and returns the new value. If key doesn't exist, it's treated as 0. Returns error if existing value is not an int64.
func (*Store) Max ¶ added in v0.7.0
Max returns the maximum of a numeric field across all records matching the prefix.
func (*Store) Min ¶ added in v0.7.0
Min returns the minimum of a numeric field across all records matching the prefix.
func (*Store) PutFloat64 ¶
PutFloat64 stores a float64 value.
func (*Store) PutIfEquals ¶ added in v0.6.0
PutIfEquals stores a value only if the current value equals expected. Returns ErrConditionFailed if values don't match, ErrKeyNotFound if key doesn't exist.
func (*Store) PutIfNotExists ¶ added in v0.6.0
PutIfNotExists stores a value only if the key doesn't exist. Returns ErrKeyExists if the key already exists.
func (*Store) PutJson ¶ added in v0.7.0
PutJson stores a record as a JSON string. Use this when you want human-readable storage instead of binary msgpack.
func (*Store) ScanPrefix ¶
ScanPrefix iterates over all keys with the given prefix in sorted order. The callback receives the key and value bytes directly (zero-copy). Return false from the callback to stop iteration. Keys are deduplicated (newest version wins) and tombstones are skipped.
func (*Store) ScanPrefixMaps ¶ added in v0.7.1
ScanPrefixMaps scans keys with the given prefix and decodes each value as a map.
func (*Store) ScanPrefixMapsZeroCopy ¶ added in v0.10.0
func (s *Store) ScanPrefixMapsZeroCopy(prefix []byte, fn func(key []byte, m map[string]any) bool) error
ScanPrefixMapsZeroCopy scans keys with prefix using zero-copy decoding. Map strings are only valid within the callback - copy any you need to retain.
func (*Store) ScanPrefixWithStats ¶ added in v0.8.0
func (s *Store) ScanPrefixWithStats(prefix []byte, fn func(key []byte, value Value) bool, progress ScanProgress) (ScanStats, error)
ScanPrefixWithStats is like ScanPrefix but also returns scan statistics. The progress callback (if non-nil) is called periodically during the scan.
func (*Store) ScanRange ¶ added in v0.7.0
ScanRange iterates over all keys in the range [start, end) in sorted order. The callback receives the key and value bytes directly (zero-copy). Return false from the callback to stop iteration.
func (*Store) ScanRangeMaps ¶ added in v0.7.1
ScanRangeMaps scans keys in [start, end) and decodes each value as a map.
func (*Store) Sum ¶ added in v0.7.0
Sum returns the sum of a numeric field across all records matching the prefix. For simple numeric values (no field), pass empty string for field.
func (*Store) Sync ¶ added in v0.8.3
Sync ensures all written data is durable by syncing the WAL. This is faster than Flush() because it doesn't create an SSTable. Data remains in the memtable and will be recovered from WAL on restart. Use this for frequent durability checkpoints; use Flush() less frequently to convert memtable data to SSTables.
Sync does not block on pending writes - it syncs whatever is currently in the WAL buffer. This allows Sync to proceed even during backpressure.
func (*Store) WriteBatch ¶ added in v0.6.0
WriteBatch atomically applies all operations in the batch. All operations are written to wal together before applying to memtable.
type StoreStats ¶
type StoreStats struct {
MemtableSize int64
MemtableCount int64
IndexMemory int64 // Total in-memory size of indexes and bloom filters
CacheStats CacheStats
Levels []LevelStats
}
StoreStats contains store statistics.
type TableMeta ¶ added in v0.5.0
type TableMeta struct {
ID uint32
Level int
MinKey []byte
MaxKey []byte
NumKeys uint64
FileSize int64
// Offsets for lazy loading (relative to SSTable file)
IndexOffset uint64
IndexSize uint32
BloomOffset uint64
BloomSize uint32
}
TableMeta contains SSTable metadata stored in the manifest. This allows opening the store without reading each SSTable's index.
type Value ¶
type Value struct {
Type ValueType
// Inline storage for primitives
Int64 int64
Float64 float64
Bool bool
// For strings/bytes - either inline data or pointer to block
Bytes []byte // Used for inline storage (small values)
Pointer *dataPointer // Used for large values stored in data blocks
// For records - map of field name to value
Record map[string]any // Used for ValueTypeRecord
}
Value represents a typed value in the store.
func DecodeValue ¶
DecodeValue deserializes a value from bytes. Returns the value and number of bytes consumed.
func DecodeValueZeroCopy ¶
DecodeValueZeroCopy deserializes a value without copying byte data. The returned Value's Bytes field points into the input data slice. Caller must ensure data outlives the returned Value. This is faster but the Value is only valid while data is valid.
func Float64Value ¶
Float64Value creates a Value containing a float64.
func MsgpackValue ¶ added in v0.7.0
MsgpackValue creates a Value containing raw msgpack bytes. This is more efficient than RecordValue for storing structs.
func RecordValue ¶ added in v0.7.0
RecordValue creates a Value containing a structured record.
func StringValue ¶
StringValue creates a Value containing a string.
func TombstoneValue ¶
func TombstoneValue() Value
TombstoneValue creates a tombstone Value for deletions.
func (*Value) EncodedSize ¶
EncodedSize returns the serialized size of a value.
func (Value) IsTombstone ¶
IsTombstone returns true if this value represents a deletion.
type WALSyncMode ¶
type WALSyncMode int
WALSyncMode determines when WAL is synced to disk.
const ( // WALSyncNone never syncs. Fastest but may lose data on crash. WALSyncNone WALSyncMode = iota // WALSyncPerBatch syncs after each batch of writes. Good balance. WALSyncPerBatch // WALSyncPerWrite syncs after each write. Slowest but safest. WALSyncPerWrite )