add DBPath and UseBinLog config

This commit is contained in:
siddontang 2014-09-18 22:30:33 +08:00
parent 2972f57436
commit e3bdb57be2
7 changed files with 19 additions and 5 deletions

View File

@ -51,10 +51,13 @@ type Config struct {
DBName string `toml:"db_name"` DBName string `toml:"db_name"`
DBPath string `toml:"db_path"`
LevelDB LevelDBConfig `toml:"leveldb"` LevelDB LevelDBConfig `toml:"leveldb"`
LMDB LMDBConfig `toml:"lmdb"` LMDB LMDBConfig `toml:"lmdb"`
UseBinLog bool `toml:"use_binlog"`
BinLog BinLogConfig `toml:"binlog"` BinLog BinLogConfig `toml:"binlog"`
SlaveOf string `toml:"slaveof"` SlaveOf string `toml:"slaveof"`

View File

@ -27,6 +27,12 @@ slaveof = ""
# #
db_name = "leveldb" db_name = "leveldb"
# If not set, use data_dir/"db_name"_data
db_path = ""
# enable binlog or not
use_binlog = true
[leveldb] [leveldb]
compression = false compression = false
block_size = 32768 block_size = 32768

View File

@ -11,6 +11,7 @@ func TestConfig(t *testing.T) {
dstCfg.HttpAddr = "127.0.0.1:11181" dstCfg.HttpAddr = "127.0.0.1:11181"
dstCfg.DataDir = "/tmp/ledis_server" dstCfg.DataDir = "/tmp/ledis_server"
dstCfg.DBName = "leveldb" dstCfg.DBName = "leveldb"
dstCfg.UseBinLog = true
dstCfg.LevelDB.Compression = false dstCfg.LevelDB.Compression = false
dstCfg.LevelDB.BlockSize = 32768 dstCfg.LevelDB.BlockSize = 32768

View File

@ -41,7 +41,7 @@ func Open(cfg *config.Config) (*Ledis, error) {
l.ldb = ldb l.ldb = ldb
if cfg.BinLog.MaxFileNum > 0 && cfg.BinLog.MaxFileSize > 0 { if cfg.UseBinLog {
println("binlog will be refactored later, use your own risk!!!") println("binlog will be refactored later, use your own risk!!!")
l.binlog, err = NewBinLog(cfg) l.binlog, err = NewBinLog(cfg)
if err != nil { if err != nil {

View File

@ -34,6 +34,7 @@ func TestReplication(t *testing.T) {
cfgM := new(config.Config) cfgM := new(config.Config)
cfgM.DataDir = "/tmp/test_repl/master" cfgM.DataDir = "/tmp/test_repl/master"
cfgM.UseBinLog = true
cfgM.BinLog.MaxFileNum = 10 cfgM.BinLog.MaxFileNum = 10
cfgM.BinLog.MaxFileSize = 50 cfgM.BinLog.MaxFileSize = 50

View File

@ -40,8 +40,7 @@ func TestReplication(t *testing.T) {
masterCfg := new(config.Config) masterCfg := new(config.Config)
masterCfg.DataDir = fmt.Sprintf("%s/master", data_dir) masterCfg.DataDir = fmt.Sprintf("%s/master", data_dir)
masterCfg.Addr = "127.0.0.1:11182" masterCfg.Addr = "127.0.0.1:11182"
masterCfg.BinLog.MaxFileSize = 1 * 1024 * 1024 masterCfg.UseBinLog = true
masterCfg.BinLog.MaxFileNum = 10
var master *App var master *App
var slave *App var slave *App

View File

@ -16,8 +16,12 @@ import (
) )
func getStorePath(cfg *config.Config) string { 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)) return path.Join(cfg.DataDir, fmt.Sprintf("%s_data", cfg.DBName))
} }
}
func Open(cfg *config.Config) (*DB, error) { func Open(cfg *config.Config) (*DB, error) {
s, err := driver.GetStore(cfg) s, err := driver.GetStore(cfg)