table

package
v0.0.0-...-de123dd Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 4, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RunPrefix            = "level"
	MaxTableCacheTime    = time.Minute
	DefaultLeveledBase   = 5
	DefaultLeveledCount  = 10
	DefaultLeveledSize   = 2 << 26
	DefaultLeveledFactor = 10
)
View Source
const (

	// MaxBlockSize defines the maximum size of a table block. By default 64 KiB.
	MaxBlockSize = 2 << 16
	// MaxCacheSize defines the maximum number of blocks cached in memory. By default 8 MiB.
	MaxCacheSize = 128
)

Variables

View Source
var DefaultBucket = ratelimit.NewBucketWithRate(2<<21, 2<<22)

Functions

func Find

func Find(block, key []byte) [][]byte

Find looks for a row with the given key in the block.

func Merge

func Merge(name string, left *Table, right *Table) error

Merge combines two tables into one.

func Next

func Next(block []byte, offset int64) ([]byte, []byte, int64, bool)

Next reads the next row from the block and returns the key, value and offset.

func RemoveTableLogs

func RemoveTableLogs(prefix string) error

RemoveTableLogs drops all tables logs associated with tables with the given prefix.

func Seek

func Seek(file *File, offset int64) ([]byte, int64, bool)

Seek searches the file for a block at the given offset.

Types

type BlockScanner

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

func ScanBlocks

func ScanBlocks(file *File) BlockScanner

ScanBlocks returns a block scanner for the given file.

func (*BlockScanner) Block

func (scanner *BlockScanner) Block() []byte

func (*BlockScanner) Next

func (scanner *BlockScanner) Next() bool

func (*BlockScanner) Peek

func (scanner *BlockScanner) Peek() bool

func (*BlockScanner) Skip

func (scanner *BlockScanner) Skip()

type File

type File struct {
	*os.File
	sync.Mutex
}

type LeveledCompaction

type LeveledCompaction struct {
	Name                                    string
	BaseSize, LevelSize, LevelSizeFactor    int64
	BaseCount, LevelCount, LevelCountFactor int

	Base   []*Table
	Levels []*Run
	// contains filtered or unexported fields
}

func NewLeveledCompaction

func NewLeveledCompaction(name string) *LeveledCompaction

func (*LeveledCompaction) Add

func (compaction *LeveledCompaction) Add(table *Table) error

func (*LeveledCompaction) Close

func (compaction *LeveledCompaction) Close() error

func (*LeveledCompaction) Get

func (compaction *LeveledCompaction) Get(key []byte) [][]byte

func (*LeveledCompaction) Restore

func (compaction *LeveledCompaction) Restore(tables []*Table) error

type MTable

type MTable struct {
	Name string
	// contains filtered or unexported fields
}

MTable represents an in-memory table.

func NewMTable

func NewMTable(log io.ReadWriteCloser, name string) (*MTable, error)

NewMTable initializes a new in-memory table.

func NewMTableFromFile

func NewMTableFromFile(name string) (*MTable, error)

NewMTableFromFile initializes a new MTable backed by disk.

func Recover

func Recover(prefix, name string) (*MTable, error)

Recover recovers a set of memtables matched by the given prefix and stores a merged version inside a single memtable.

func (*MTable) All

func (table *MTable) All() []MTableRecord

All returns all stored MTable records.

func (*MTable) Cleanup

func (table *MTable) Cleanup() error

Cleanup removes the table log from disk.

func (*MTable) Close

func (table *MTable) Close() error

Close closes the mtable log.

func (*MTable) Compact

func (table *MTable) Compact() error

Compact compacts the memtable to a disk-backed table. This does not remove the memtable log file.

func (*MTable) Get

func (table *MTable) Get(key []byte) [][]byte

func (*MTable) Merge

func (table *MTable) Merge(newer *MTable) error

Merge combines the newer memtable into this one.

func (*MTable) Put

func (table *MTable) Put(key, value []byte) error

Put adds a new key value pair to the table.

func (*MTable) ReadFrom

func (mtable *MTable) ReadFrom(cached io.Reader) (int64, error)

ReadFrom reads from an existing mtable log.

func (*MTable) Size

func (table *MTable) Size() int64

type MTableRecord

type MTableRecord struct {
	Key    []byte
	Values [][]byte
}

MTableRecord represents a single record in the MTable.

type RowScanner

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

func ScanRows

func ScanRows(block []byte) RowScanner

ScanRows returns a row scanner for the given block.

func (*RowScanner) Key

func (scanner *RowScanner) Key() []byte

func (*RowScanner) Next

func (scanner *RowScanner) Next() bool

func (*RowScanner) Peek

func (scanner *RowScanner) Peek() bool

func (*RowScanner) Skip

func (scanner *RowScanner) Skip()

func (*RowScanner) Value

func (scanner *RowScanner) Value() []byte

type Run

type Run struct {
	Name     string
	Tables   []*Table
	MaxSize  int64
	MaxCount int
	// contains filtered or unexported fields
}

func (*Run) Close

func (run *Run) Close() error

func (*Run) Get

func (run *Run) Get(key []byte) [][]byte

Get retrieves the table associated with the given key. Since a table may cease to exist after the max table cache time the table has to be fetched each time it is looked up.

func (*Run) Join

func (run *Run) Join(tables []*Table, begin, end int) error

Join inserts a table vector replacing the tables at the given range. The tables are not range checked before insertion.

func (*Run) Merge

func (run *Run) Merge(table *Table) error

Merge merges the given table into the run.

func (*Run) Overflow

func (run *Run) Overflow() bool

Overflow returns true if there are more tables in the run than allowed.

func (*Run) Push

func (run *Run) Push(table *Table) bool

Push inserts a single table back into the run. The table should have been evicted from the run beforehand. If the table can not be inserted without violating the non-intersecting interval property the function returns false.

type Scanner

type Scanner interface {
	Next() bool
	Key() []byte
	Value() []byte
}

type Table

type Table struct {
	Name string
	File *File

	// Table key range
	Begin, End []byte

	// Performance optimizations
	Index  *index.Index
	Filter *index.Filter
	Cache  *index.Cache
	// contains filtered or unexported fields
}

Table is a key-sorted list of key-value pairs stored on disk. It is backed by multiple performance and size optimizations, such as block-based compression, key filtering using bloom filters, ARC cache for block accesses and RB tree based key indexing.

func Open

func Open(name string) (*Table, error)

Open a table-triple and initializes the table file and loads index and filter into memory.

func OpenTables

func OpenTables(glob string) ([]*Table, error)

OpenTables opens a slice of tables identified by a common prefix.

func (*Table) Close

func (table *Table) Close() error

Close closes a table file.

func (*Table) Delete

func (table *Table) Delete() error

Delete closes a table file and removes it from disk.

func (*Table) Get

func (table *Table) Get(key []byte) [][]byte

Get returns the matching value to a key.

func (*Table) Range

func (table *Table) Range(key []byte) bool

func (*Table) Scan

func (table *Table) Scan() *TableScanner

type TableScanner

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

func (*TableScanner) Compare

func (scanner *TableScanner) Compare(other *TableScanner) (int, []byte, []byte)

func (*TableScanner) Key

func (scanner *TableScanner) Key() []byte

func (*TableScanner) Next

func (scanner *TableScanner) Next() bool

func (*TableScanner) Peek

func (scanner *TableScanner) Peek() bool

func (*TableScanner) Skip

func (scanner *TableScanner) Skip()

func (*TableScanner) Value

func (scanner *TableScanner) Value() []byte

type WTable

type WTable struct {
	Name string
	// contains filtered or unexported fields
}

WTable is an unfinished table in write mode. Values can only be written by increasing key order. WTable is not safe to use with multiple goroutines concurrently.

func OpenWTable

func OpenWTable(name string, readWriteCloser io.ReadWriteCloser, bucket *ratelimit.Bucket) (*WTable, error)

OpenWTable opens a new write-only table.

func OpenWTableFromFile

func OpenWTableFromFile(name string, bucket *ratelimit.Bucket) (*WTable, error)

func (*WTable) Append

func (table *WTable) Append(key, value []byte) error

func (*WTable) Close

func (table *WTable) Close() error

func (*WTable) Flush

func (table *WTable) Flush() error

func (*WTable) FlushFilter

func (table *WTable) FlushFilter() error

func (*WTable) FlushIndex

func (table *WTable) FlushIndex() error

func (*WTable) Size

func (table *WTable) Size() int64

type WritableAutoflushTable

type WritableAutoflushTable struct {
	Basename string
	MaxSize  int64
	Written  []string
	// contains filtered or unexported fields
}

func OpenWritableWithAutoflush

func OpenWritableWithAutoflush(name string, size int64, bucket *ratelimit.Bucket) *WritableAutoflushTable

func (*WritableAutoflushTable) Append

func (table *WritableAutoflushTable) Append(key, value []byte) error

func (*WritableAutoflushTable) Close

func (table *WritableAutoflushTable) Close() error

Directories

Path Synopsis
Package index contains data structures to help cope with caches, indices and key filters.
Package index contains data structures to help cope with caches, indices and key filters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL