-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.go
80 lines (70 loc) · 1.59 KB
/
db.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package FayKV
import (
"github.com/Kirov7/FayKV/inmemory"
"github.com/Kirov7/FayKV/lsm"
"github.com/Kirov7/FayKV/utils"
"sync"
)
type KvAPI interface {
Set(data *inmemory.Element) error
Get(key []byte) (*utils.Entry, error)
Del(key []byte) error
Info() *Stats
NewIterator(opt *utils.Options) utils.Iterator
Close() error
}
type DB struct {
sync.RWMutex
opt *Options
stats *Stats
lsm *lsm.LSM
}
func Open(opt *Options) *DB {
c := utils.NewCloser()
db := &DB{opt: opt}
// init LSM structure
db.lsm = lsm.NewLSM(&lsm.Options{
WorkDir: opt.WorkDir,
MemTableSize: opt.MemTableSize,
SSTableMaxSize: opt.SSTableMaxSz,
BlockSize: 8 * 1024,
BloomFalsePositive: 0, //0.01,
BaseLevelSize: 10 << 20,
LevelSizeMultiplier: 10,
BaseTableSize: 5 << 20,
TableSizeMultiplier: 2,
NumLevelZeroTables: 15,
MaxLevelNum: 7,
NumCompactors: 1,
})
// Example Initialize statistics
db.stats = newStats(opt)
// Start the merge compression process for the sstable
go db.lsm.StartCompacter()
c.Add(1)
// todo init worker channel
return db
}
func (db *DB) Set(data *inmemory.Element) error {
// todo implement there
panic("todo")
}
func (db *DB) Get(key []byte) (*utils.Entry, error) {
// todo implement there
panic("todo")
}
func (db *DB) Del(key []byte) error {
// todo implement there
panic("todo")
}
func (db *DB) Info() *Stats {
return db.stats
}
func (db *DB) NewIterator(opt *utils.Options) utils.Iterator {
// todo implement there
panic("todo")
}
func (db *DB) Close() error {
// todo implement there
panic("todo")
}