2014-07-25 13:58:00 +04:00
|
|
|
package store
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-08-07 12:49:48 +04:00
|
|
|
"github.com/siddontang/ledisdb/config"
|
2014-07-25 13:58:00 +04:00
|
|
|
"github.com/siddontang/ledisdb/store/driver"
|
|
|
|
"os"
|
2014-08-07 12:49:48 +04:00
|
|
|
"path"
|
2014-07-25 13:58:00 +04:00
|
|
|
|
2014-08-30 06:17:04 +04:00
|
|
|
_ "github.com/siddontang/ledisdb/store/boltdb"
|
|
|
|
_ "github.com/siddontang/ledisdb/store/goleveldb"
|
|
|
|
_ "github.com/siddontang/ledisdb/store/hyperleveldb"
|
|
|
|
_ "github.com/siddontang/ledisdb/store/leveldb"
|
|
|
|
_ "github.com/siddontang/ledisdb/store/mdb"
|
|
|
|
_ "github.com/siddontang/ledisdb/store/rocksdb"
|
2014-08-15 20:08:01 +04:00
|
|
|
)
|
2014-08-07 12:49:48 +04:00
|
|
|
|
|
|
|
func getStorePath(cfg *config.Config) string {
|
|
|
|
return path.Join(cfg.DataDir, fmt.Sprintf("%s_data", cfg.DBName))
|
|
|
|
}
|
|
|
|
|
|
|
|
func Open(cfg *config.Config) (*DB, error) {
|
2014-08-15 20:08:01 +04:00
|
|
|
s, err := driver.GetStore(cfg)
|
2014-08-07 12:49:48 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
path := getStorePath(cfg)
|
|
|
|
|
|
|
|
if err := os.MkdirAll(path, os.ModePerm); err != nil {
|
2014-07-25 20:46:03 +04:00
|
|
|
return nil, err
|
2014-07-25 13:58:00 +04:00
|
|
|
}
|
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
idb, err := s.Open(path, cfg)
|
2014-07-25 13:58:00 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
db := &DB{idb}
|
|
|
|
|
|
|
|
return db, nil
|
|
|
|
}
|
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
func Repair(cfg *config.Config) error {
|
2014-08-15 20:08:01 +04:00
|
|
|
s, err := driver.GetStore(cfg)
|
2014-08-07 12:49:48 +04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2014-07-25 13:58:00 +04:00
|
|
|
}
|
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
path := getStorePath(cfg)
|
2014-07-25 13:58:00 +04:00
|
|
|
|
2014-08-07 12:49:48 +04:00
|
|
|
return s.Repair(path, cfg)
|
2014-07-25 13:58:00 +04:00
|
|
|
}
|
2014-08-15 20:08:01 +04:00
|
|
|
|
|
|
|
func init() {
|
|
|
|
}
|