package table
import "github.com/dgraph-io/badger/v2/table"
Index ¶
- func IDToFilename(id uint64) string
- func NewFilename(id uint64, dir string) string
- func NewMergeIterator(iters []y.Iterator, reverse bool) y.Iterator
- func ParseFileID(name string) (uint64, bool)
- type Builder
- func NewTableBuilder(opts Options) *Builder
- func (b *Builder) Add(key []byte, value y.ValueStruct, valueLen uint32)
- func (b *Builder) Close()
- func (b *Builder) DataKey() *pb.DataKey
- func (b *Builder) Empty() bool
- func (b *Builder) Finish() []byte
- func (b *Builder) ReachedCapacity(cap int64) bool
- type ConcatIterator
- func NewConcatIterator(tbls []*Table, reversed bool) *ConcatIterator
- func (s *ConcatIterator) Close() error
- func (s *ConcatIterator) Key() []byte
- func (s *ConcatIterator) Next()
- func (s *ConcatIterator) Rewind()
- func (s *ConcatIterator) Seek(key []byte)
- func (s *ConcatIterator) Valid() bool
- func (s *ConcatIterator) Value() y.ValueStruct
- type Iterator
- func (itr *Iterator) Close() error
- func (itr *Iterator) Key() []byte
- func (itr *Iterator) Next()
- func (itr *Iterator) Rewind()
- func (itr *Iterator) Seek(key []byte)
- func (itr *Iterator) Valid() bool
- func (itr *Iterator) Value() (ret y.ValueStruct)
- func (itr *Iterator) ValueCopy() (ret y.ValueStruct)
- type MergeIterator
- func (mi *MergeIterator) Close() error
- func (mi *MergeIterator) Key() []byte
- func (mi *MergeIterator) Next()
- func (mi *MergeIterator) Rewind()
- func (mi *MergeIterator) Seek(key []byte)
- func (mi *MergeIterator) Valid() bool
- func (mi *MergeIterator) Value() y.ValueStruct
- type Options
- type Table
- func OpenInMemoryTable(data []byte, id uint64, opt *Options) (*Table, error)
- func OpenTable(fd *os.File, opts Options) (*Table, error)
- func (t *Table) Biggest() []byte
- func (t *Table) Close() error
- func (t *Table) CompressionType() options.CompressionType
- func (t *Table) DecrRef() error
- func (t *Table) DoesNotHave(hash uint64) bool
- func (t *Table) EstimatedSize() uint64
- func (t *Table) Filename() string
- func (t *Table) ID() uint64
- func (t *Table) IncrRef()
- func (t *Table) KeyID() uint64
- func (t *Table) NewIterator(reversed bool) *Iterator
- func (t *Table) Size() int64
- func (t *Table) Smallest() []byte
- func (t *Table) VerifyChecksum() error
- type TableInterface
Functions ¶
func IDToFilename ¶
IDToFilename does the inverse of ParseFileID
func NewFilename ¶
NewFilename should be named TableFilepath -- it combines the dir with the ID to make a table filepath.
func NewMergeIterator ¶
NewMergeIterator creates a merge iterator.
func ParseFileID ¶
ParseFileID reads the file id out of a filename.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is used in building a table.
func NewTableBuilder ¶
NewTableBuilder makes a new TableBuilder.
func (*Builder) Add ¶
func (b *Builder) Add(key []byte, value y.ValueStruct, valueLen uint32)
Add adds a key-value pair to the block.
func (*Builder) Close ¶
func (b *Builder) Close()
Close closes the TableBuilder.
func (*Builder) DataKey ¶
DataKey returns datakey of the builder.
func (*Builder) Empty ¶
Empty returns whether it's empty.
func (*Builder) Finish ¶
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) ReachedCapacity ¶
ReachedCapacity returns true if we... roughly (?) reached capacity?
type ConcatIterator ¶
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 ¶
func NewConcatIterator(tbls []*Table, reversed bool) *ConcatIterator
NewConcatIterator creates a new concatenated iterator
func (*ConcatIterator) Close ¶
func (s *ConcatIterator) Close() error
Close implements y.Interface.
func (*ConcatIterator) Key ¶
func (s *ConcatIterator) Key() []byte
Key implements y.Interface
func (*ConcatIterator) Next ¶
func (s *ConcatIterator) Next()
Next advances our concat iterator.
func (*ConcatIterator) Rewind ¶
func (s *ConcatIterator) Rewind()
Rewind implements y.Interface
func (*ConcatIterator) Seek ¶
func (s *ConcatIterator) Seek(key []byte)
Seek brings us to element >= key if reversed is false. Otherwise, <= key.
func (*ConcatIterator) Valid ¶
func (s *ConcatIterator) Valid() bool
Valid implements y.Interface
func (*ConcatIterator) Value ¶
func (s *ConcatIterator) Value() y.ValueStruct
Value implements y.Interface
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
Iterator is an iterator for a Table.
func (*Iterator) Close ¶
Close closes the iterator (and it must be called).
func (*Iterator) Key ¶
Key follows the y.Iterator interface. Returns the key with timestamp.
func (*Iterator) Next ¶
func (itr *Iterator) Next()
Next follows the y.Iterator interface
func (*Iterator) Rewind ¶
func (itr *Iterator) Rewind()
Rewind follows the y.Iterator interface
func (*Iterator) Seek ¶
Seek follows the y.Iterator interface
func (*Iterator) Valid ¶
Valid follows the y.Iterator interface
func (*Iterator) Value ¶
func (itr *Iterator) Value() (ret y.ValueStruct)
Value follows the y.Iterator interface
func (*Iterator) ValueCopy ¶
func (itr *Iterator) ValueCopy() (ret y.ValueStruct)
ValueCopy copies the current value and returns it as decoded ValueStruct.
type MergeIterator ¶
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 ¶
func (mi *MergeIterator) Close() error
Close implements y.Iterator.
func (*MergeIterator) Key ¶
func (mi *MergeIterator) Key() []byte
Key returns the key associated with the current iterator.
func (*MergeIterator) Next ¶
func (mi *MergeIterator) Next()
Next returns the next element. If it is the same as the current key, ignore it.
func (*MergeIterator) Rewind ¶
func (mi *MergeIterator) Rewind()
Rewind seeks to first element (or last element for reverse iterator).
func (*MergeIterator) Seek ¶
func (mi *MergeIterator) Seek(key []byte)
Seek brings us to element with key >= given key.
func (*MergeIterator) Valid ¶
func (mi *MergeIterator) Valid() bool
Valid returns whether the MergeIterator is at a valid element.
func (*MergeIterator) Value ¶
func (mi *MergeIterator) Value() y.ValueStruct
Value returns the value associated with the iterator.
type Options ¶
type Options struct { // ChkMode is the checksum verification mode for Table. ChkMode options.ChecksumVerificationMode // LoadingMode is the mode to be used for loading Table. LoadingMode options.FileLoadingMode // 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 BlockCache *ristretto.Cache IndexCache *ristretto.Cache // ZSTDCompressionLevel is the ZSTD compression level used for compressing blocks. ZSTDCompressionLevel int // When LoadBloomsOnOpen is set, bloom filters will be loaded while opening // the table. Otherwise, they will be loaded lazily when they're accessed. LoadBloomsOnOpen bool }
Options contains configurable options for Table/Builder.
type Table ¶
type Table struct { sync.Mutex Checksum []byte 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 OpenInMemoryTable ¶
OpenInMemoryTable is similar to OpenTable but it opens a new table from the provided data. OpenInMemoryTable is used for L0 tables.
func OpenTable ¶
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 ¶
Biggest is its biggest key, or nil if there are none
func (*Table) Close ¶
Close closes the open table. (Releases resources back to the OS.)
func (*Table) CompressionType ¶
func (t *Table) CompressionType() options.CompressionType
CompressionType returns the compression algorithm used for block compression.
func (*Table) DecrRef ¶
DecrRef decrements the refcount and possibly deletes the table
func (*Table) DoesNotHave ¶
DoesNotHave returns true if (but not "only if") the table does not have the key hash. It does a bloom filter lookup.
func (*Table) EstimatedSize ¶
EstimatedSize returns the total size of key-values stored in this table (including the disk space occupied on the value log).
func (*Table) Filename ¶
Filename is NOT the file name. Just kidding, it is.
func (*Table) ID ¶
ID is the table's ID number (used to make the file name).
func (*Table) IncrRef ¶
func (t *Table) IncrRef()
IncrRef increments the refcount (having to do with whether the file should be deleted)
func (*Table) KeyID ¶
KeyID returns data key id.
func (*Table) NewIterator ¶
NewIterator returns a new iterator of the Table
func (*Table) Size ¶
Size is its file size in bytes
func (*Table) Smallest ¶
Smallest is its smallest key, or nil if there are none
func (*Table) VerifyChecksum ¶
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 ¶
TableInterface is useful for testing.
Source Files ¶
builder.go iterator.go merge_iterator.go table.go
- Version
- v2.2007.4 (latest)
- Published
- Aug 25, 2021
- Platform
- linux/amd64
- Imports
- 24 packages
- Last checked
- 1 week ago –
Tools for package owners.