badger: github.com/dgraph-io/badger/table Index | Files

package table

import "github.com/dgraph-io/badger/table"

Index

Package Files

builder.go iterator.go merge_iterator.go table.go

Constants

const (
    KB  = 1024
    MB  = KB * 1024
)

Variables

var (
    REVERSED int = 2
    NOCACHE  int = 4
)
var NumBlocks int32

func BlockEvictHandler Uses

func BlockEvictHandler(value interface{})

BlockEvictHandler is used to reuse the byte slice stored in the block on cache eviction.

func IDToFilename Uses

func IDToFilename(id uint64) string

IDToFilename does the inverse of ParseFileID

func NewFilename Uses

func NewFilename(id uint64, dir string) string

NewFilename should be named TableFilepath -- it combines the dir with the ID to make a table filepath.

func NewMergeIterator Uses

func NewMergeIterator(iters []y.Iterator, reverse bool) y.Iterator

NewMergeIterator creates a merge iterator.

func ParseFileID Uses

func ParseFileID(name string) (uint64, bool)

ParseFileID reads the file id out of a filename.

type Builder Uses

type Builder struct {
    // contains filtered or unexported fields
}

Builder is used in building a table.

func NewTableBuilder Uses

func NewTableBuilder(opts Options) *Builder

NewTableBuilder makes a new TableBuilder.

func (*Builder) Add Uses

func (b *Builder) Add(key []byte, value y.ValueStruct, valueLen uint32)

Add adds a key-value pair to the block.

func (*Builder) AddStaleKey Uses

func (b *Builder) AddStaleKey(key []byte, v y.ValueStruct, valueLen uint32)

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.

func (*Builder) Close Uses

func (b *Builder) Close()

Close closes the TableBuilder.

func (*Builder) DataKey Uses

func (b *Builder) DataKey() *pb.DataKey

DataKey returns datakey of the builder.

func (*Builder) Done Uses

func (b *Builder) Done() buildData

func (*Builder) Empty Uses

func (b *Builder) Empty() bool

Empty returns whether it's empty.

func (*Builder) Finish Uses

func (b *Builder) Finish() []byte

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.

func (*Builder) Opts Uses

func (b *Builder) Opts() *Options

func (*Builder) ReachedCapacity Uses

func (b *Builder) ReachedCapacity() bool

ReachedCapacity returns true if we... roughly (?) reached capacity?

type ConcatIterator Uses

type ConcatIterator struct {
    // contains filtered or unexported fields
}

ConcatIterator concatenates the sequences defined by several iterators. (It only works with TableIterators, probably just because it's faster to not be so generic.)

func NewConcatIterator Uses

func NewConcatIterator(tbls []*Table, opt int) *ConcatIterator

NewConcatIterator creates a new concatenated iterator

func (*ConcatIterator) Close Uses

func (s *ConcatIterator) Close() error

Close implements y.Interface.

func (*ConcatIterator) Key Uses

func (s *ConcatIterator) Key() []byte

Key implements y.Interface

func (*ConcatIterator) Next Uses

func (s *ConcatIterator) Next()

Next advances our concat iterator.

func (*ConcatIterator) Rewind Uses

func (s *ConcatIterator) Rewind()

Rewind implements y.Interface

func (*ConcatIterator) Seek Uses

func (s *ConcatIterator) Seek(key []byte)

Seek brings us to element >= key if reversed is false. Otherwise, <= key.

func (*ConcatIterator) Valid Uses

func (s *ConcatIterator) Valid() bool

Valid implements y.Interface

func (*ConcatIterator) Value Uses

func (s *ConcatIterator) Value() y.ValueStruct

Value implements y.Interface

type Iterator Uses

type Iterator struct {
    // contains filtered or unexported fields
}

Iterator is an iterator for a Table.

func (*Iterator) Close Uses

func (itr *Iterator) Close() error

Close closes the iterator (and it must be called).

func (*Iterator) Key Uses

func (itr *Iterator) Key() []byte

Key follows the y.Iterator interface. Returns the key with timestamp.

func (*Iterator) Next Uses

func (itr *Iterator) Next()

Next follows the y.Iterator interface

func (*Iterator) Rewind Uses

func (itr *Iterator) Rewind()

Rewind follows the y.Iterator interface

func (*Iterator) Seek Uses

func (itr *Iterator) Seek(key []byte)

Seek follows the y.Iterator interface

func (*Iterator) Valid Uses

func (itr *Iterator) Valid() bool

Valid follows the y.Iterator interface

func (*Iterator) Value Uses

func (itr *Iterator) Value() (ret y.ValueStruct)

Value follows the y.Iterator interface

func (*Iterator) ValueCopy Uses

func (itr *Iterator) ValueCopy() (ret y.ValueStruct)

ValueCopy copies the current value and returns it as decoded ValueStruct.

type MergeIterator Uses

type MergeIterator struct {
    // contains filtered or unexported fields
}

MergeIterator merges multiple iterators. NOTE: MergeIterator owns the array of iterators and is responsible for closing them.

func (*MergeIterator) Close Uses

func (mi *MergeIterator) Close() error

Close implements y.Iterator.

func (*MergeIterator) Key Uses

func (mi *MergeIterator) Key() []byte

Key returns the key associated with the current iterator.

func (*MergeIterator) Next Uses

func (mi *MergeIterator) Next()

Next returns the next element. If it is the same as the current key, ignore it.

func (*MergeIterator) Rewind Uses

func (mi *MergeIterator) Rewind()

Rewind seeks to first element (or last element for reverse iterator).

func (*MergeIterator) Seek Uses

func (mi *MergeIterator) Seek(key []byte)

Seek brings us to element with key >= given key.

func (*MergeIterator) Valid Uses

func (mi *MergeIterator) Valid() bool

Valid returns whether the MergeIterator is at a valid element.

func (*MergeIterator) Value Uses

func (mi *MergeIterator) Value() y.ValueStruct

Value returns the value associated with the iterator.

type Options Uses

type Options struct {

    // Open tables in read only mode.
    ReadOnly bool

    // Maximum size of the table.
    TableSize uint64

    // ChkMode is the checksum verification mode for Table.
    ChkMode options.ChecksumVerificationMode

    // BloomFalsePositive is the false positive probabiltiy of bloom filter.
    BloomFalsePositive float64

    // BlockSize is the size of each block inside SSTable in bytes.
    BlockSize int

    // DataKey is the key used to decrypt the encrypted text.
    DataKey *pb.DataKey

    // Compression indicates the compression algorithm used for block compression.
    Compression options.CompressionType

    // Block cache is used to cache decompressed and decrypted blocks.
    BlockCache *ristretto.Cache
    IndexCache *ristretto.Cache

    AllocPool *z.AllocatorPool

    // ZSTDCompressionLevel is the ZSTD compression level used for compressing blocks.
    ZSTDCompressionLevel int
    // contains filtered or unexported fields
}

Options contains configurable options for Table/Builder.

type Table Uses

type Table struct {
    sync.Mutex
    *z.MmapFile

    Checksum  []byte
    CreatedAt time.Time

    IsInmemory bool // Set to true if the table is on level 0 and opened in memory.
    // contains filtered or unexported fields
}

Table represents a loaded table file with the info we have about it.

func CreateTable Uses

func CreateTable(fname string, builder *Builder) (*Table, error)

func OpenInMemoryTable Uses

func OpenInMemoryTable(data []byte, id uint64, opt *Options) (*Table, error)

OpenInMemoryTable is similar to OpenTable but it opens a new table from the provided data. OpenInMemoryTable is used for L0 tables.

func OpenTable Uses

func OpenTable(mf *z.MmapFile, opts Options) (*Table, error)

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.

func (*Table) Biggest Uses

func (t *Table) Biggest() []byte

Biggest is its biggest key, or nil if there are none

func (*Table) BloomFilterSize Uses

func (t *Table) BloomFilterSize() int

BloomFilterSize returns the size of the bloom filter in bytes stored in memory.

func (*Table) CompressionType Uses

func (t *Table) CompressionType() options.CompressionType

CompressionType returns the compression algorithm used for block compression.

func (*Table) DecrRef Uses

func (t *Table) DecrRef() error

DecrRef decrements the refcount and possibly deletes the table

func (*Table) DoesNotHave Uses

func (t *Table) DoesNotHave(hash uint32) bool

DoesNotHave returns true if and only if the table does not have the key hash. It does a bloom filter lookup.

func (*Table) Filename Uses

func (t *Table) Filename() string

Filename is NOT the file name. Just kidding, it is.

func (*Table) ID Uses

func (t *Table) ID() uint64

ID is the table's ID number (used to make the file name).

func (*Table) IncrRef Uses

func (t *Table) IncrRef()

IncrRef increments the refcount (having to do with whether the file should be deleted)

func (*Table) IndexSize Uses

func (t *Table) IndexSize() int

IndexSize is the size of table index in bytes.

func (*Table) KeyCount Uses

func (t *Table) KeyCount() uint32

KeyCount is the total number of keys in this table.

func (*Table) KeyID Uses

func (t *Table) KeyID() uint64

KeyID returns data key id.

func (*Table) KeySplits Uses

func (t *Table) KeySplits(n int, prefix []byte) []string

KeySplits splits the table into at least n ranges based on the block offsets.

func (*Table) MaxVersion Uses

func (t *Table) MaxVersion() uint64

MaxVersion returns the maximum version across all keys stored in this table.

func (*Table) NewIterator Uses

func (t *Table) NewIterator(opt int) *Iterator

NewIterator returns a new iterator of the Table

func (*Table) OnDiskSize Uses

func (t *Table) OnDiskSize() uint32

OnDiskSize returns the total size of key-values stored in this table (including the disk space occupied on the value log).

func (*Table) Size Uses

func (t *Table) Size() int64

Size is its file size in bytes

func (*Table) Smallest Uses

func (t *Table) Smallest() []byte

Smallest is its smallest key, or nil if there are none

func (*Table) StaleDataSize Uses

func (t *Table) StaleDataSize() uint32

StaleDataSize is the amount of stale data (that can be dropped by a compaction )in this SST.

func (*Table) UncompressedSize Uses

func (t *Table) UncompressedSize() uint32

UncompressedSize is the size uncompressed data stored in this file.

func (*Table) VerifyChecksum Uses

func (t *Table) VerifyChecksum() error

VerifyChecksum verifies checksum for all blocks of table. This function is called by OpenTable() function. This function is also called inside levelsController.VerifyChecksum().

type TableInterface Uses

type TableInterface interface {
    Smallest() []byte
    Biggest() []byte
    DoesNotHave(hash uint32) bool
}

TableInterface is useful for testing.

Package table imports 26 packages (graph) and is imported by 37 packages. Updated 2021-01-25. Refresh now. Tools for package owners.