package table

Import Path
	github.com/dgraph-io/badger/v4/table (on go.dev)

Dependency Relation
	imports 28 packages, and imported by one package


Package-Level Type Names (total 8)
/* sort by: | */
func BlockEvictHandler(b *Block)
Builder is used in building a table. Add adds a key-value pair to the block. AddStaleKey is same is Add function but it also increments the internal staleDataSize counter. This value will be used to prioritize this table for compaction. Close closes the TableBuilder. DataKey returns datakey of the builder. (*Builder) Done() buildData Empty returns whether it's empty. Finish finishes the table by appending the index. The table structure looks like +---------+------------+-----------+---------------+ | Block 1 | Block 2 | Block 3 | Block 4 | +---------+------------+-----------+---------------+ | Block 5 | Block 6 | Block ... | Block N | +---------+------------+-----------+---------------+ | Index | Index Size | Checksum | Checksum Size | +---------+------------+-----------+---------------+ In case the data is encrypted, the "IV" is added to the end of the index. (*Builder) Opts() *Options ReachedCapacity returns true if we... roughly (?) reached capacity? func NewTableBuilder(opts Options) *Builder func CreateTable(fname string, builder *Builder) (*Table, error)
ConcatIterator concatenates the sequences defined by several iterators. (It only works with TableIterators, probably just because it's faster to not be so generic.) Close implements y.Interface. Key implements y.Interface Next advances our concat iterator. Rewind implements y.Interface Seek brings us to element >= key if reversed is false. Otherwise, <= key. Valid implements y.Interface Value implements y.Interface *ConcatIterator : github.com/dgraph-io/badger/v4/y.Iterator *ConcatIterator : github.com/prometheus/common/expfmt.Closer *ConcatIterator : io.Closer func NewConcatIterator(tbls []*Table, opt int) *ConcatIterator
Iterator is an iterator for a Table. Close closes the iterator (and it must be called). Key follows the y.Iterator interface. Returns the key with timestamp. Next follows the y.Iterator interface Rewind follows the y.Iterator interface Seek follows the y.Iterator interface Valid follows the y.Iterator interface Value follows the y.Iterator interface ValueCopy copies the current value and returns it as decoded ValueStruct. *Iterator : github.com/dgraph-io/badger/v4/y.Iterator *Iterator : github.com/prometheus/common/expfmt.Closer *Iterator : io.Closer func (*Table).NewIterator(opt int) *Iterator
MergeIterator merges multiple iterators. NOTE: MergeIterator owns the array of iterators and is responsible for closing them. Close implements y.Iterator. Key returns the key associated with the current iterator. Next returns the next element. If it is the same as the current key, ignore it. Rewind seeks to first element (or last element for reverse iterator). Seek brings us to element with key >= given key. Valid returns whether the MergeIterator is at a valid element. Value returns the value associated with the iterator. *MergeIterator : github.com/dgraph-io/badger/v4/y.Iterator *MergeIterator : github.com/prometheus/common/expfmt.Closer *MergeIterator : io.Closer
Options contains configurable options for Table/Builder. AllocPool *z.AllocatorPool Block cache is used to cache decompressed and decrypted blocks. BlockSize is the size of each block inside SSTable in bytes. BloomFalsePositive is the false positive probabiltiy of bloom filter. ChkMode is the checksum verification mode for Table. Compression indicates the compression algorithm used for block compression. DataKey is the key used to decrypt the encrypted text. IndexCache *ristretto.Cache[uint64, *fb.TableIndex] MetricsEnabled bool Open tables in read only mode. Maximum size of the table. ZSTDCompressionLevel is the ZSTD compression level used for compressing blocks. func (*Builder).Opts() *Options func NewTableBuilder(opts Options) *Builder func OpenInMemoryTable(data []byte, id uint64, opt *Options) (*Table, error) func OpenTable(mf *z.MmapFile, opts Options) (*Table, error)
Table represents a loaded table file with the info we have about it. Checksum []byte CreatedAt time.Time // Set to true if the table is on level 0 and opened in memory. MmapFile *z.MmapFile MmapFile.Data []byte MmapFile.Fd *os.File Mutex sync.Mutex AllocateSlice allocates a slice of the given size at the given offset. Biggest is its biggest key, or nil if there are none BloomFilterSize returns the size of the bloom filter in bytes stored in memory. Bytes returns data starting from offset off of size sz. If there's not enough data, it would return nil slice and io.EOF. Close would close the file. It would also truncate the file if maxSz >= 0. CompressionType returns the compression algorithm used for block compression. DecrRef decrements the refcount and possibly deletes the table ( Table) Delete() error DoesNotHave returns true if and only if the table does not have the key hash. It does a bloom filter lookup. Filename is NOT the file name. Just kidding, it is. ID is the table's ID number (used to make the file name). IncrRef increments the refcount (having to do with whether the file should be deleted) IndexSize is the size of table index in bytes. KeyCount is the total number of keys in this table. KeyID returns data key id. KeySplits splits the table into at least n ranges based on the block offsets. Lock locks m. If the lock is already in use, the calling goroutine blocks until the mutex is available. MaxVersion returns the maximum version across all keys stored in this table. NewIterator returns a new iterator of the Table ( Table) NewReader(offset int) io.Reader OnDiskSize returns the total size of key-values stored in this table (including the disk space occupied on the value log). Size is its file size in bytes Slice returns the slice at the given offset. Smallest is its smallest key, or nil if there are none StaleDataSize is the amount of stale data (that can be dropped by a compaction )in this SST. ( Table) Sync() error Truncate would truncate the mmapped file to the given size. On Linux, we truncate the underlying file and then call mremap, but on other systems, we unmap first, then truncate, then re-map. TryLock tries to lock m and reports whether it succeeded. Note that while correct uses of TryLock do exist, they are rare, and use of TryLock is often a sign of a deeper problem in a particular use of mutexes. UncompressedSize is the size uncompressed data stored in this file. Unlock unlocks m. It is a run-time error if m is not locked on entry to Unlock. A locked [Mutex] is not associated with a particular goroutine. It is allowed for one goroutine to lock a Mutex and then arrange for another goroutine to unlock it. VerifyChecksum verifies checksum for all blocks of table. This function is called by OpenTable() function. This function is also called inside levelsController.VerifyChecksum(). *Table : TableInterface Table : github.com/polarsignals/frostdb.Sync *Table : sync.Locker func CreateTable(fname string, builder *Builder) (*Table, error) func OpenInMemoryTable(data []byte, id uint64, opt *Options) (*Table, error) func OpenTable(mf *z.MmapFile, opts Options) (*Table, error) func NewConcatIterator(tbls []*Table, opt int) *ConcatIterator
TableInterface is useful for testing. ( TableInterface) Biggest() []byte ( TableInterface) DoesNotHave(hash uint32) bool ( TableInterface) MaxVersion() uint64 ( TableInterface) Smallest() []byte *Table
Package-Level Functions (total 10)
BlockEvictHandler is used to reuse the byte slice stored in the block on cache eviction.
func CreateTable(fname string, builder *Builder) (*Table, error)
IDToFilename does the inverse of ParseFileID
NewConcatIterator creates a new concatenated iterator
NewFilename should be named TableFilepath -- it combines the dir with the ID to make a table filepath.
NewMergeIterator creates a merge iterator.
NewTableBuilder makes a new TableBuilder.
OpenInMemoryTable is similar to OpenTable but it opens a new table from the provided data. OpenInMemoryTable is used for L0 tables.
OpenTable assumes file has only one table and opens it. Takes ownership of fd upon function entry. Returns a table with one reference count on it (decrementing which may delete the file! -- consider t.Close() instead). The fd has to writeable because we call Truncate on it before deleting. Checksum for all blocks of table is verified based on value of chkMode.
ParseFileID reads the file id out of a filename.
Package-Level Variables (total 3)
Package-Level Constants (total 2)
const KB = 1024
const MB = 1048576