table

package
v0.0.0-...-41febbd Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IDToFilename

func IDToFilename(id uint64) string

IDToFilename does the inverse of ParseFileID

func MemTabKeyComparator

func MemTabKeyComparator(key1, key2 []byte) int

MemTabKeyComparator checks the key without timestamp and checks the timestamp if keyNoTs is same. a<timestamp> would be sorted higher than aa<timestamp> if we use bytes.compare All keys should have timestamp.

func MemTabKeyEqualizer

func MemTabKeyEqualizer(key1, key2 []byte) bool

MemTabKeyEqualizer checks for key equality ignoring the version timestamp suffix.

func NewFilename

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 ParseFileID

func ParseFileID(name string) (uint64, bool)

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

func NewTableBuilder() *Builder

NewTableBuilder makes a new TableBuilder.

func (*Builder) Add

func (b *Builder) Add(key []byte, value LSMValue) error

Add adds a key-value pair to the block. If doNotRestart is true, we will not restart even if b.counter >= restartInterval.

func (*Builder) Close

func (b *Builder) Close()

Close closes the TableBuilder.

func (*Builder) Empty

func (b *Builder) Empty() bool

Empty returns whether it's empty.

func (*Builder) Finish

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

Finish finishes the table by appending the index.

func (*Builder) ReachedCapacity

func (b *Builder) ReachedCapacity(cap int64) bool

TODO: vvv this was the comment on ReachedCapacity. FinalSize returns the *rough* final size of the array, counting the header which is not yet written. TODO: Look into why there is a discrepancy. I suspect it is because of Write(empty, empty) at the end. The diff can vary. 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() LSMValue

Value implements y.Interface

type Iterator

type Iterator interface {
	Key() []byte
	Value() LSMValue
	Valid() bool
	Next()
	Rewind()
	Seek(key []byte)
	Close() error
}

Iterator is an interface for a basic iterator. All iterators should be closed so that file garbage collection works.

type LSMValue

type LSMValue struct {
	// Internal meta, it means how to handle this LSM value.
	Meta byte

	// User defined meta.
	UserMeta byte

	// Tne expires of value.
	ExpiresAt uint64

	// It will be value address or value self.
	Value []byte

	// This field is not serialized. Only for internal usage.
	Version uint64
}

LSMValue represents the value info that can be associated with a key but also the internal Meta field.

func (*LSMValue) Decode

func (v *LSMValue) Decode(b []byte)

Decode uses the length of the slice to infer the length of the Value field.

func (*LSMValue) Encode

func (v *LSMValue) Encode(b []byte)

Encode expects a slice of length at least v.EncodedSize().

func (*LSMValue) EncodeTo

func (v *LSMValue) EncodeTo(buf *bytes.Buffer)

EncodeTo should be kept in sync with the Encode function above. The reason this function exists is to avoid creating byte arrays per key-value pair in table/builder.go.

func (*LSMValue) EncodedSize

func (v *LSMValue) EncodedSize() uint16

EncodedSize is the size of the ValueStruct when encoded

type MemTable

type MemTable interface {
	IncrRef()
	DecrRef()
	MemSize() int64
	Empty() bool
	Put(key []byte, value LSMValue)
	Get(key []byte) LSMValue
	NewIterator() *util.Iterator
	NewUniIterator(reversed bool) *util.UniIterator
}

MemTable the interface of memtable

func NewMemTable

func NewMemTable(arenaSize int64) MemTable

NewMemTable make a new empty mem table.

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 NewMergeIterator

func NewMergeIterator(iters []Iterator, reversed bool) *MergeIterator

NewMergeIterator returns a new MergeIterator from a list of Iterators.

func (*MergeIterator) Close

func (s *MergeIterator) Close() error

Close implements Iterator

func (*MergeIterator) Key

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

Key returns the key associated with the current iterator

func (*MergeIterator) Next

func (s *MergeIterator) Next()

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

func (*MergeIterator) Rewind

func (s *MergeIterator) Rewind()

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

func (*MergeIterator) Seek

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

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

func (*MergeIterator) Valid

func (s *MergeIterator) Valid() bool

Valid returns whether the MergeIterator is at a valid element.

func (*MergeIterator) Value

func (s *MergeIterator) Value() LSMValue

Value returns the value associated with the iterator.

type Table

type Table struct {

	// ss table content checksum
	Checksum []byte

	sync.Mutex
	// contains filtered or unexported fields
}

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

func OpenTable

func OpenTable(fd *os.File, cksum []byte) (*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.

func (*Table) Biggest

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

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

func (*Table) Close

func (t *Table) Close() error

Close closes the open table. (Releases resources back to the OS.)

func (*Table) DecrRef

func (t *Table) DecrRef() error

DecrRef decrements the refcount and possibly deletes the table

func (*Table) DoesNotHave

func (t *Table) DoesNotHave(key []byte) bool

DoesNotHave returns true if (but not "only if") the table does not have the key. It does a bloom filter lookup.

func (*Table) Filename

func (t *Table) Filename() string

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

func (*Table) ID

func (t *Table) ID() uint64

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) NewIterator

func (t *Table) NewIterator(reversed bool) *tableIterator

NewIterator returns a new iterator of the Table

func (*Table) Size

func (t *Table) Size() int64

Size is its file size in bytes

func (*Table) Smallest

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

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

Jump to

Keyboard shortcuts

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