Documentation ¶
Index ¶
- func IDToFilename(id uint64) string
- func MemTabKeyComparator(key1, key2 []byte) int
- func MemTabKeyEqualizer(key1, key2 []byte) bool
- func NewFilename(id uint64, dir string) string
- func ParseFileID(name string) (uint64, bool)
- type Builder
- type ConcatIterator
- type Iterator
- type LSMValue
- type MemTable
- type MergeIterator
- type Table
- func (t *Table) Biggest() []byte
- func (t *Table) Close() error
- func (t *Table) DecrRef() error
- func (t *Table) DoesNotHave(key []byte) bool
- func (t *Table) Filename() string
- func (t *Table) ID() uint64
- func (t *Table) IncrRef()
- func (t *Table) NewIterator(reversed bool) *tableIterator
- func (t *Table) Size() int64
- func (t *Table) Smallest() []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IDToFilename ¶
IDToFilename does the inverse of ParseFileID
func MemTabKeyComparator ¶
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 ¶
MemTabKeyEqualizer checks for key equality ignoring the version timestamp suffix.
func NewFilename ¶
NewFilename should be named TableFilepath -- it combines the dir with the ID to make a table filepath.
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 (*Builder) Add ¶
Add adds a key-value pair to the block. If doNotRestart is true, we will not restart even if b.counter >= restartInterval.
func (*Builder) ReachedCapacity ¶
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) Seek ¶
func (s *ConcatIterator) Seek(key []byte)
Seek brings us to element >= key if reversed is false. Otherwise, <= key.
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 ¶
Decode uses the length of the slice to infer the length of the Value field.
func (*LSMValue) EncodeTo ¶
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 ¶
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 ¶
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) 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 ¶
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) DoesNotHave ¶
DoesNotHave returns true if (but not "only if") the table does not have the key. It does a bloom filter lookup.
func (*Table) IncrRef ¶
func (t *Table) IncrRef()
IncrRef increments the refcount (having to do with whether the file should be deleted)
func (*Table) NewIterator ¶
NewIterator returns a new iterator of the Table