Documentation ¶
Index ¶
- Constants
- Variables
- func FileIsOpen(fd *os.File) bool
- func GetTempFileForTesting(t *testing.T, fn func(file *os.File))
- func LevelText(level logLevel) string
- func SizeInKB(size int64) int64
- func SizeInMB(size int64) int64
- type Batch
- type Entry
- type EntryHeader
- type Index
- type Info
- type LSMTree
- func (lsm *LSMTree) Close() error
- func (lsm *LSMTree) Del(k []byte) error
- func (lsm *LSMTree) Get(k []byte) ([]byte, error)
- func (lsm *LSMTree) GetBatch(keys ...[]byte) (*Batch, error)
- func (lsm *LSMTree) GetInfo() *Info
- func (lsm *LSMTree) Has(k []byte) (bool, error)
- func (lsm *LSMTree) Put(k, v []byte) error
- func (lsm *LSMTree) PutBatch(b *Batch) error
- func (lsm *LSMTree) Sync() error
- type Logger
- type Options
Constants ¶
const ( NUL = asciiNull SOH = asciiStartOfHeading STX = asciiStartOfText ETX = asciiEndOfText EOT = asciiEndOfTransmission ENQ = asciiEnquiry ACK = asciiAcknowledge BEL = asciiBell BS = asciiBackspace TAB = asciiHorizontalTab LF = asciiLineFeed // Line feed. Also known as a new line. VT = asciiVerticalTab FF = asciiFormFeed // Form feed. Also known as a new page. CR = asciiCarriageReturn SO = asciiShiftOut SI = asciiShiftIn DLE = asciiDataLineEscape DC1 = asciiDeviceControl1 DC2 = asciiDeviceControl2 DC3 = asciiDeviceControl3 DC4 = asciiDeviceControl4 NAK = asciiNegativeAcknowledge SYN = asciiSynchronousIdle ETB = asciiEndOfTransmissionBlock CAN = asciiCancel EM = asciiEndOfMedium SUB = asciiSubstitute ESC = asciiEscape FS = asciiFileSeparator // End of file. Or between a concatenation of what might otherwise be separate files. GS = asciiGroupSeparator // Between sections of data. Not needed in simple data files. RS = asciiRecordSeparator // End of a record or row. US = asciiUnitSeparator // Between fields of a record, or members of a row. DEL = asciiDelete )
const ( LevelDebug logLevel = iota LevelInfo LevelWarn LevelError LevelFatal LevelOff )
Variables ¶
var ( ErrKeyNotFound = errors.New("lsmtree: key not found") ErrFoundTombstone = errors.New("lsmtree: found tombstone or empty value") ErrNoDataFound = errors.New("lsmtree: no data found") ErrNotFound = errors.New("lsmtree: entry not found") ErrIncompleteSet = errors.New("lsmtree: incomplete batch or set") ErrFlushThreshold = errors.New("lsmtree: flush threshold has been reached") ErrBadKey = errors.New("lsmtree: bad key") ErrKeyTooLarge = errors.New("lsmtree: key too large") ErrBadValue = errors.New("lsmtree: bad value") ErrValueTooLarge = errors.New("lsmtree: value too large") ErrWritingEntry = errors.New("lsmtree: error write entry") ErrReadingEntry = errors.New("lsmtree: error reading entry") ErrNilEntry = errors.New("lsmtree: error got nil entry") ErrNilIndex = errors.New("lsmtree: error got nil index") ErrBadChecksum = errors.New("lsmtree: bad checksum") ErrFileClosed = errors.New("lsmtree: file is closed") )
var Tombstone = []byte{0xDE, 0xAD, 0xBE, 0xEF}
Tombstone is a marker for an entry that has been deleted
Functions ¶
func FileIsOpen ¶
Types ¶
type Batch ¶
type Batch struct { Entries []*Entry // contains filtered or unexported fields }
Batch is a set of entries
type EntryHeader ¶
type EntryHeader struct {
// contains filtered or unexported fields
}
EntryHeader is mainly used for serialization
type LSMTree ¶
type LSMTree struct {
// contains filtered or unexported fields
}
func OpenLSMTree ¶
OpenLSMTree opens or creates an LSMTree instance
func (*LSMTree) Del ¶
Del takes a key and overwrites the record with a Tombstone or a 'deleted' or nil entry. It leaves the key in the LSMTree so that future table versions can properly merge.
func (*LSMTree) Get ¶
Get takes a key and attempts to find a match in the LSMTree. If a match cannot be found Get returns a nil value and ErrNotFound. Get first checks the bloom filter, then the mem-table. If it is still not found it attempts to do a binary search on the for the key in the ss-index and if that yields no result it will try to find the entry by doing a linear search of the ss-table itself.
func (*LSMTree) GetBatch ¶
GetBatch attempts to find entries matching the keys provided. If a matching entry is found, it is added to the batch that is returned. If a matching entry cannot be found it is simply skipped and not added to the batch. GetBatch will return a nil error if all the matching entries were found. If it found some but not all, GetBatch will return ErrIncompleteSet along with the batch of entries that it could find. If it could not find any matches at all, the batch will be nil and GetBatch will return an ErrNotFound
func (*LSMTree) Has ¶
Has returns a boolean signaling weather or not the key is in the LSMTree. It should be noted that in some cases this may return a false positive, but it should never return a false negative.
func (*LSMTree) Put ¶
Put takes a key and a value and adds them to the LSMTree. If the entry already exists, it should overwrite the old entry.
func (*LSMTree) PutBatch ¶
PutBatch takes a batch of entries and adds all of them at one time. It acts a bit like a transaction. If you have a configuration option of SyncOnWrite: true it will be disabled temporarily and the batch will sync at the end of all the writes. This is to give a slight performance advantage. It should be worth noting that very large batches may have an impact on performance and may also cause frequent ss-table flushes which may result in fragmentation.