forked from bosun-monitor/bosun
/
store.go
64 lines (50 loc) · 1.25 KB
/
store.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
package store
import (
"fmt"
"os"
"path"
"bosun.org/_third_party/github.com/siddontang/ledisdb/config"
"bosun.org/_third_party/github.com/siddontang/ledisdb/store/driver"
_ "bosun.org/_third_party/github.com/siddontang/ledisdb/store/boltdb"
_ "bosun.org/_third_party/github.com/siddontang/ledisdb/store/goleveldb"
_ "bosun.org/_third_party/github.com/siddontang/ledisdb/store/leveldb"
_ "bosun.org/_third_party/github.com/siddontang/ledisdb/store/mdb"
_ "bosun.org/_third_party/github.com/siddontang/ledisdb/store/rocksdb"
)
func getStorePath(cfg *config.Config) string {
if len(cfg.DBPath) > 0 {
return cfg.DBPath
} else {
return path.Join(cfg.DataDir, fmt.Sprintf("%s_data", cfg.DBName))
}
}
func Open(cfg *config.Config) (*DB, error) {
s, err := driver.GetStore(cfg)
if err != nil {
return nil, err
}
path := getStorePath(cfg)
if err := os.MkdirAll(path, 0755); err != nil {
return nil, err
}
idb, err := s.Open(path, cfg)
if err != nil {
return nil, err
}
db := new(DB)
db.db = idb
db.name = s.String()
db.st = &Stat{}
db.cfg = cfg
return db, nil
}
func Repair(cfg *config.Config) error {
s, err := driver.GetStore(cfg)
if err != nil {
return err
}
path := getStorePath(cfg)
return s.Repair(path, cfg)
}
func init() {
}