lsm

package
v0.0.0-...-4e12403 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongRange    = errors.New("Data is smaller that the range requested")
	ErrItemDiskWrite = errors.New("The disk items are inmutable")
)
View Source
var (
	ErrInvalidTTL = errors.New("The ttl is ouf of the possible ranges")
)
View Source
var (
	ErrItemNotFound = errors.New("Item not found")
)
View Source
var (
	// ErrReadingItemDisk is the error reponse if the range is not correct
	ErrReadingItemDisk = errors.New("The bytes read don't match with the body size definition")
)

Functions

func RemoveContents

func RemoveContents(dir string) error

Types

type Config

type Config struct {
	MinLSMTTLString string
	MinLSMTTL       time.Duration
	Dir             string
	ExtraTTLString  string
	ExtraTTL        time.Duration
}

type EvictFunc

type EvictFunc func(key interface{}, value interface{})

type Item

type Item interface {
	Write(b []byte) (int, error)
	WriteTo(io.Writer) (int64, error)
	WriteToRange(io.Writer, int64, int64) (int64, error)
	ValidRange(reqStart, reqEnd int64) (from, to, length int64, err error)
	Bytes() []byte
	GetHIT() uint64
	Len() int
	GetStatusCode() int
	GetHeader() http.Header
	Done()
}

type ItemDisk

type ItemDisk struct {
	Key        uint64
	StatusCode int
	VFile      *VFile
	Off        int64
	HeadSize   int64
	BodySize   int64
	HIT        uint64
	// contains filtered or unexported fields
}

ItemDisk is the struct that define the location of this item. Like the file where is stored and also the possition in the file for each element

func (*ItemDisk) Bytes

func (itd *ItemDisk) Bytes() []byte

Bytes will return the full content of the item in slice of bytes NOTE: Don't use for critical operations, it works without a sync.Pool, use WriteTo instead.

func (*ItemDisk) Done

func (itd *ItemDisk) Done()

Done is a way to mark the item as "unused" so the expiration process can remove from the tree and sent it back to the pool

func (*ItemDisk) GetHIT

func (itd *ItemDisk) GetHIT() uint64

GetHIT will return the total hits accumulated by this item

func (*ItemDisk) GetHeader

func (itd *ItemDisk) GetHeader() http.Header

GetHeader will read the header stored in bytes in the disk parse with the standar lib and return the interface http.Header

func (*ItemDisk) GetStatusCode

func (itd *ItemDisk) GetStatusCode() int

GetStatusCode will return the HTTP reponse code of this item

func (*ItemDisk) Len

func (itd *ItemDisk) Len() int

Len will return the total size of the content of this key

func (*ItemDisk) ValidRange

func (itd *ItemDisk) ValidRange(reqStart, reqEnd int64) (from, to, length int64, err error)

func (*ItemDisk) Write

func (itd *ItemDisk) Write(b []byte) (int, error)

func (*ItemDisk) WriteTo

func (itd *ItemDisk) WriteTo(w io.Writer) (int64, error)

WriteTo will write the content of the item that is located in the disk in the io.Writer provided

func (*ItemDisk) WriteToRange

func (itd *ItemDisk) WriteToRange(w io.Writer, from, to int64) (int64, error)

WriteToRange going to return an slice of bytes of an specific range

type ItemMem

type ItemMem struct {
	Key        uint64
	StatusCode int
	Header     http.Header
	Data       []byte
	HIT        uint64
	// contains filtered or unexported fields
}

ItemMem is the struct that store all the information related with the item. If the body is too big, then will be write in a temporary file that is also defined in the struct

func (*ItemMem) Bytes

func (itm *ItemMem) Bytes() []byte

Bytes will return the full content of the item in slice of bytes

func (*ItemMem) Close

func (itm *ItemMem) Close()

Close will close and remove the underline file if is defined

func (*ItemMem) Done

func (itm *ItemMem) Done()

Done is a way to mark the item as "unused" so the expiration process can remove from the tree and sent it back to the pool

func (*ItemMem) GetHIT

func (itm *ItemMem) GetHIT() uint64

GetHIT will return the total hits accumulated by this item

func (*ItemMem) GetHeader

func (itm *ItemMem) GetHeader() http.Header

GetHeader will read the header stored in bytes in the disk parse with the standar lib and return the interface http.Header

func (*ItemMem) GetStatusCode

func (itm *ItemMem) GetStatusCode() int

GetStatusCode will return the HTTP reponse code of this item

func (*ItemMem) Len

func (itm *ItemMem) Len() int

Len will return the total size of the content of this key

func (*ItemMem) ValidRange

func (itm *ItemMem) ValidRange(reqStart, reqEnd int64) (from, to, length int64, err error)

func (*ItemMem) Write

func (itm *ItemMem) Write(b []byte) (int, error)

func (*ItemMem) WriteTo

func (itm *ItemMem) WriteTo(w io.Writer) (n int64, err error)

WriteTo will write the bytes of the item in the provided io.Writer interface

func (*ItemMem) WriteToRange

func (itm *ItemMem) WriteToRange(w io.Writer, from, to int64) (int64, error)

WriteToRange going to return an slice of bytes of an specific range

type LSM

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

func New

func New(cfg *Config) *LSM

func (*LSM) Delete

func (c *LSM) Delete(key uint64)

func (*LSM) Get

func (c *LSM) Get(key uint64) (Item, bool, error)

func (*LSM) NewItem

func (c *LSM) NewItem(l int) *ItemMem

func (*LSM) Reload

func (c *LSM) Reload(cfg *Config)

func (*LSM) Set

func (c *LSM) Set(key uint64, itm *ItemMem, ttl time.Duration)

type VFile

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

func VFileNew

func VFileNew(ttl time.Duration, cfg *Config) *VFile

func (*VFile) AutoExpire

func (vf *VFile) AutoExpire()

AutoExpire will close all the open files related and define a time to close everything and delete the file

func (*VFile) Close

func (vf *VFile) Close() error

Close force the expiration of this file, will not wait for the TTL

func (*VFile) CloseReader

func (vf *VFile) CloseReader() error

CloseReader will close the "reader" file

func (*VFile) CloseWriter

func (vf *VFile) CloseWriter() error

CloseWriter will close the "writer" file

func (*VFile) Expired

func (vf *VFile) Expired() bool

func (*VFile) ReadAt

func (vf *VFile) ReadAt(b []byte, off int64) (int, error)

func (*VFile) Seek

func (vf *VFile) Seek() int64

Seek return the last "byte" position in the file

func (*VFile) Write

func (vf *VFile) Write(b []byte) (int, error)

type VLog

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

func VlogNew

func VlogNew(cfg *Config) *VLog

func (*VLog) Get

func (vl *VLog) Get(itd *ItemDisk) error

func (*VLog) Set

func (vl *VLog) Set(itm *ItemMem, ttl time.Duration) error

func (*VLog) SetAfterWrite

func (vl *VLog) SetAfterWrite(fn func(itd *ItemDisk, ttl time.Duration))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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