lsmtree

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2022 License: BSD-3-Clause Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	LevelDebug logLevel = iota
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelOff
)

Variables

View Source
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")
)
View Source
var Tombstone = []byte{0xDE, 0xAD, 0xBE, 0xEF}

Tombstone is a marker for an entry that has been deleted

Functions

func FileIsOpen

func FileIsOpen(fd *os.File) bool

func GetTempFileForTesting

func GetTempFileForTesting(t *testing.T, fn func(file *os.File))

func LevelText

func LevelText(level logLevel) string

func SizeInKB

func SizeInKB(size int64) int64

func SizeInMB

func SizeInMB(size int64) int64

Types

type Batch

type Batch struct {
	Entries []*Entry
	// contains filtered or unexported fields
}

Batch is a set of entries

func NewBatch

func NewBatch() *Batch

NewBatch instantiates a new batch of entries

func (*Batch) Discard

func (b *Batch) Discard()

Discard just vaporizes a batch

func (*Batch) Len

func (b *Batch) Len() int

Len [implementing sort interface]

func (*Batch) Less

func (b *Batch) Less(i, j int) bool

Less [implementing sort interface]

func (*Batch) Size

func (b *Batch) Size() int64

Size returns the batch size in bytes

func (*Batch) Swap

func (b *Batch) Swap(i, j int)

Swap [implementing sort interface]

func (*Batch) Write

func (b *Batch) Write(key, value []byte) error

Write writes a new entry to the batch

type Entry

type Entry struct {
	Key   []byte
	Value []byte
	CRC   uint32
}

Entry represents a single entry or record

func (*Entry) Size

func (e *Entry) Size() int64

Size returns the size in bytes for an entry

func (*Entry) String

func (e *Entry) String() string

String is the stringer method for an *Entry

type EntryHeader

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

EntryHeader is mainly used for serialization

type Index

type Index struct {
	Key    []byte
	Offset int64
}

Index is a binary entry index

func (*Index) String

func (i *Index) String() string

String is the stringer method for a *Index

type Info

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

func (*Info) String

func (info *Info) String() string

type LSMTree

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

func OpenLSMTree

func OpenLSMTree(options *Options) (*LSMTree, error)

OpenLSMTree opens or creates an LSMTree instance

func (*LSMTree) Close

func (lsm *LSMTree) Close() error

Close syncs and closes the LSMTree

func (*LSMTree) Del

func (lsm *LSMTree) Del(k []byte) error

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

func (lsm *LSMTree) Get(k []byte) ([]byte, error)

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

func (lsm *LSMTree) GetBatch(keys ...[]byte) (*Batch, error)

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

func (lsm *LSMTree) GetInfo() *Info

func (*LSMTree) Has

func (lsm *LSMTree) Has(k []byte) (bool, error)

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

func (lsm *LSMTree) Put(k, v []byte) error

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

func (lsm *LSMTree) PutBatch(b *Batch) error

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.

func (*LSMTree) Sync

func (lsm *LSMTree) Sync() error

Sync forces a sync on all underlying structures no matter what the configuration

type Logger

type Logger struct {
	*log.Logger
	// contains filtered or unexported fields
}

func (*Logger) Debug

func (l *Logger) Debug(s string, a ...interface{})

func (*Logger) Error

func (l *Logger) Error(s string, a ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(s string, a ...interface{})

func (*Logger) Info

func (l *Logger) Info(s string, a ...interface{})

func (*Logger) Warn

func (l *Logger) Warn(s string, a ...interface{})

type Options

type Options struct {
	BaseDir      string
	SyncOnWrite  bool
	LoggingLevel uint8
	// contains filtered or unexported fields
}

func DefaultOptions

func DefaultOptions(base string) *Options

Jump to

Keyboard shortcuts

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