simplekv

package module
v0.0.0-...-2162086 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: MIT Imports: 14 Imported by: 0

README

simplekv

A simple KV database implementation

TODO

  • asm murmur3 perf
  • clean code
  • unit, benchmark test

structure

structure

key features

  1. LSM 日志结构存储引擎,核心点在于顺序写日志,这样就能保证超快的写速度;
  2. 内存索引,KV红黑树实现,内存索引有大小限制;
  3. 超过内存限制(threshold)后,会将内存数据刷新到磁盘段文件中(segment file);
  4. 在内存中保存了索引、数据方便快速查询,如果仍查不到则去搜索段文件;
  5. 如果一个 key 被写了多次,那么就会有很多重复的行,因此需要合并他们(compact);
  6. 当需要刷内存索引至磁盘时,会先将磁盘中的段文件进行合并(compact);
  7. 引入布隆过滤器来加快文件数据查询,不存在的 key 直接返回,避免读文件;
  8. sparse index(稀疏索引) 保存了部分 segment-file-offset 信息,方便在文件中搜索;
  9. 稀疏索引查询的时候找到比 key 小(对于二叉树的左孩子节点)的文件和索引,然后遍历文件,就能提升效率;
  10. WAL 日志用来恢复 memtable;

references

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Murmur332

func Murmur332(key []byte, seed uint32) uint32

Murmur332 murmur hash for uint32

Types

type AppendLog

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

AppendLog 追加日志

func NewAppendLog

func NewAppendLog(filename string) (*AppendLog, error)

NewAppendLog 新建追加日志

func (*AppendLog) Clear

func (l *AppendLog) Clear() error

func (*AppendLog) Sync

func (l *AppendLog) Sync() error

func (*AppendLog) Write

func (l *AppendLog) Write(val []byte) error

func (*AppendLog) WriteString

func (l *AppendLog) WriteString(val string) error

type BitArray

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

BitArray refer https://developpaper.com/implementation-of-bit-array-in-golang/

func NewBitArray

func NewBitArray(len int) *BitArray

NewBitArray init @param len, length of bits

func (*BitArray) Add

func (a *BitArray) Add(x int)

Add set x

func (*BitArray) AddAll

func (a *BitArray) AddAll(arr ...int)

AddAll add many

func (*BitArray) Clear

func (a *BitArray) Clear()

func (*BitArray) Has

func (a *BitArray) Has(x int) bool

Has check x is set

func (*BitArray) Len

func (a *BitArray) Len() int

Len return length of bits

func (*BitArray) Remove

func (a *BitArray) Remove(x int)

func (*BitArray) String

func (a *BitArray) String() string

String returns the set as a string of the form "{1 2 3}".

func (*BitArray) UnionWith

func (a *BitArray) UnionWith(other *BitArray)

UnionWith merge with other

type BloomFilter

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

BloomFilter 布隆过滤器

func NewBloomFilter

func NewBloomFilter(numItems int, falsePositivePob float64) *BloomFilter

NewBloomFilter 新建布隆过滤器

func (*BloomFilter) Add

func (f *BloomFilter) Add(item string)

func (*BloomFilter) Check

func (f *BloomFilter) Check(item string) bool

func (*BloomFilter) Pack

func (f *BloomFilter) Pack() string

func (*BloomFilter) UnPack

func (f *BloomFilter) UnPack(data string) error

type LineReader

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

func NewLineReader

func NewLineReader(path string, offset int64) (*LineReader, error)

func (*LineReader) Close

func (r *LineReader) Close() error

func (*LineReader) ReadLine

func (r *LineReader) ReadLine() (string, error)

func (*LineReader) ReadLineKV

func (r *LineReader) ReadLineKV() (string, string, error)

type SizedMap

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

SizedMap map with size

func NewSizedMap

func NewSizedMap() *SizedMap

NewSizedMap new sized map

func (*SizedMap) Contains

func (m *SizedMap) Contains(key string) bool

Contains k

func (*SizedMap) Get

func (m *SizedMap) Get(key string) interface{}

Get k

func (*SizedMap) GetTotalSize

func (m *SizedMap) GetTotalSize() int

GetTotalSize total size of kvs

func (*SizedMap) Set

func (m *SizedMap) Set(key string, v interface{})

Set k->v

type Tree

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

Tree LSM tree(og structure tree)

func NewTree

func NewTree(segmentBasename, segmentsDirectory,
	walBasename string) (*Tree, error)

NewTree Initialize a new LSM tree - A first segment called segment_basename - A segments directory called segments_directory - A memtable write ahead log (WAL) called wal_basename

func (*Tree) Get

func (t *Tree) Get(key string) (string, error)

func (*Tree) Set

func (t *Tree) Set(key, value string) error

Jump to

Keyboard shortcuts

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