Documentation ¶
Index ¶
- Constants
- func EncodeMeta(dir *Directory) *bytes.Buffer
- func FindBucketNumber(fileSize int64) int64
- func FindTwoToPowerOfN(v uint) uint
- func NextPowerOfTwo(v uint) uint
- type ByteRecord
- type Directory
- type MmapKVStore
- func (s *MmapKVStore) Close()
- func (s *MmapKVStore) DumpPage(pageId int) string
- func (s *MmapKVStore) Get(k string) string
- func (s *MmapKVStore) Meta() *Directory
- func (store *MmapKVStore) Open(absolutePath string)
- func (s *MmapKVStore) Put(k, v string) error
- func (s *MmapKVStore) RestoreMETA()
- func (s *MmapKVStore) Rm(absolutePath string)
- type Page
- type PageIterator
- type Record
- type RecordWriter
Constants ¶
const ( PAGE_SIZE = 4096 PAGE_USE_OFFSET = 4094 PAGE_LOCAL_DEPTH_OFFSET = 4092 )
const ( RECORD_HEADER_SIZE = 2 RECORD_TOTAL_HEADER_SIZE = 4 )
const ( FILE_NAME = "bluck.data" META_FILE_NAME = "bluck.meta" DB_DEFAULT_FOLDER = "/tmp/" )
Variables ¶
This section is empty.
Functions ¶
func EncodeMeta ¶
func FindBucketNumber ¶
func FindTwoToPowerOfN ¶
func NextPowerOfTwo ¶
Types ¶
type ByteRecord ¶
type ByteRecord []byte
A Record that is mapped on a byte slice
func (ByteRecord) Write ¶
func (r ByteRecord) Write(key, val string)
Record order = [key, value, lenVal, lenKey] Write does it fast because it skips "String to Byte Slice conversion", using copy(dst, src[]) special case with string
type Directory ¶
type Directory struct { Table []int `json:"table"` Gd uint `json:"globalDepth"` LastPageId int `json:"LastPageId"` // contains filtered or unexported fields }
func DecodeMeta ¶
type MmapKVStore ¶
func (*MmapKVStore) Close ¶
func (s *MmapKVStore) Close()
Close must be called at the end of the connection with the store, to persist safely the data and to persist metadata on disk. The persistence of the metadata is only done in this method. Usage : defer store.Close()
func (*MmapKVStore) DumpPage ¶
func (s *MmapKVStore) DumpPage(pageId int) string
func (*MmapKVStore) Get ¶
func (s *MmapKVStore) Get(k string) string
func (*MmapKVStore) Meta ¶
func (s *MmapKVStore) Meta() *Directory
func (*MmapKVStore) Open ¶
func (store *MmapKVStore) Open(absolutePath string)
Open create the datafile and the metadata file if they do not exist. Else if they exist, it loads from the disk and mmap the datafile.
func (*MmapKVStore) Put ¶
func (s *MmapKVStore) Put(k, v string) error
Put inserts data into the memory which is mapped on disk, but does not persit the metadata If the store crashes in an inconsistent way (metadata != data), you need to use the recovery tool (RestoreMETA func)
func (*MmapKVStore) RestoreMETA ¶
func (s *MmapKVStore) RestoreMETA()
func (*MmapKVStore) Rm ¶
func (s *MmapKVStore) Rm(absolutePath string)
type Page ¶
type Page []byte
A page is an array of 4096 bytes (the same size as the SSD Hard Drive default configuration on Linux)
from 4092 to 4094, 2 bytes to store local depth (ld) from 4094 to 4096, 2 bytes to store the number of bytes used
func (Page) Get ¶
Get iterates through the page using PageIterator with cursor setted to p.Use(). It compares the key length first, if it matches it compares all bytes and then returns the value. It begins to watch the last record because the page is append only, so the last version of the value for a key is more likely to be near the end
func (Page) Put ¶
Put writes key and value on disk, within the Page boundaries. It checks if the page's available space is more than the record size. If so, it writes record after the last offset given by page.use() If not, it returns an error. There is no lookup in this function to know if the key already exists. It is append only, so the duplicates will be garbage collected during the next split of the page.
type PageIterator ¶
type PageIterator struct {
// contains filtered or unexported fields
}
Implementation of pattern Iterator to scan a Page The scan is made in reverse, from the last byte to the first (right to left).
func (*PageIterator) HasNext ¶
func (it *PageIterator) HasNext() bool
Return false when there is no other record to read. Return true if the cursor has found the beginning of the Page
func (*PageIterator) Next ¶
func (it *PageIterator) Next() ByteRecord
Return the next pointer to the byte array casted in a ByteRecord struct (provides methods). Use an cursor to know the current Record index in the Page. Update the cursor (current) to minus the payload of the Record
type Record ¶
type Record interface {
// contains filtered or unexported methods
}
This interface is for documentation purpose only. A Record is composed of two byte arrays for key and value data, and footers that contain meta info for variable length data. In theory, A key or a value could not excead 16384 bytes length (uint16 is used to store length). But at the moment, there is no logic to handle a record length higher than a Page (4096 bytes)
type RecordWriter ¶
type RecordWriter interface {
Write(key, val string)
}