Documentation
¶
Overview ¶
Package sstable implements immutable sorted string tables: the on-disk read layer of an LSM tree. A table holds key-sorted entries in CRC-checked data blocks, followed by a block index, a bloom filter, and a fixed-size footer. Values are opaque byte payloads; the encoding of value contents is the caller's responsibility, mirroring internal/wal.
Index ¶
- Constants
- type Cache
- type CacheStats
- type Iterator
- type Options
- type Reader
- func (r *Reader) Close() error
- func (r *Reader) Count() uint64
- func (r *Reader) Get(key []byte) ([]byte, bool, error)
- func (r *Reader) Iter() *Iterator
- func (r *Reader) IterFrom(start []byte) *Iterator
- func (r *Reader) Largest() []byte
- func (r *Reader) SetCache(c *Cache)
- func (r *Reader) Smallest() []byte
- type Writer
Constants ¶
const ( // DefaultBlockSize is the target uncompressed size of a data block. DefaultBlockSize = 4 * 1024 // DefaultBitsPerKey sizes the bloom filter at ~1% false positives. DefaultBitsPerKey = 10 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a byte-capped LRU over decompressed data blocks, shared by any number of Readers. A hit serves a block without the disk read, CRC check, or decompression a cold read pays. Point lookups populate the cache; iterators only consult it, so full-table scans and compactions cannot evict the hot set. Safe for concurrent use. A nil *Cache is valid and caches nothing.
func NewCache ¶
NewCache returns a cache holding up to capacityBytes of decompressed blocks. capacityBytes <= 0 returns nil (caching disabled).
func (*Cache) Stats ¶
func (c *Cache) Stats() CacheStats
Stats returns current counters. Safe on a nil cache (all zeros).
type CacheStats ¶
type CacheStats struct {
Hits uint64
Misses uint64
Bytes int64 // charged bytes currently held, including overhead
Entries int
}
CacheStats is a point-in-time snapshot of cache effectiveness and size.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator walks a table's entries in key order:
it := r.Iter()
for it.Next() {
use(it.Key(), it.Value())
}
if err := it.Err(); err != nil { ... }
Key and Value remain valid only until the next call to Next and must not be modified: they may alias a block shared through the block cache.
type Options ¶
type Options struct {
// BlockSize is the target uncompressed size of a data block in bytes.
BlockSize int
// BitsPerKey sizes the bloom filter; 10 gives ~1% false positives.
BitsPerKey int
// DisableCompression stores every data block raw. By default each block
// is s2-compressed, falling back to raw per block when compression does
// not shrink it.
DisableCompression bool
}
Options configure table construction. The zero value selects defaults.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader serves point lookups and ordered scans from a finished table. The block index and bloom filter live in memory; data blocks are read on demand, one ReadAt per lookup. Safe for concurrent use.
func NewReader ¶
NewReader opens a table from any io.ReaderAt of the given size, verifying the footer, index, and bloom filter CRCs up front. Data block CRCs are verified on each read.
func Open ¶
Open opens the table file at path. The returned Reader owns the file handle; call Close when done.
func (*Reader) Close ¶
Close releases the underlying file handle when the Reader was created via Open; otherwise it is a no-op.
func (*Reader) Get ¶
Get returns the value stored for key. The returned slice does not alias reader-internal state and is safe to retain.
func (*Reader) Iter ¶
Iter returns an iterator over all entries in key order, positioned before the first entry. Not safe for concurrent use, but independent iterators from the same Reader are.
func (*Reader) IterFrom ¶
IterFrom returns an iterator positioned before the first entry with key >= start, using the block index to skip earlier blocks (the same binary search Get uses). A nil or empty start behaves like Iter.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer builds an SSTable by streaming sorted entries to w. Keys must be added in strictly increasing byte order. The caller owns durability: write to a temp file, Finish, fsync, then rename into place.
Not safe for concurrent use.
func NewWriter ¶
NewWriter returns a Writer that streams a table to w. A zero Options selects DefaultBlockSize and DefaultBitsPerKey.