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,11 +51,14 @@ type Config struct {
DBName string `toml:"db_name"`
DBPath string `toml:"db_path"`
LevelDB LevelDBConfig `toml:"leveldb"`
LMDB LMDBConfig `toml:"lmdb"`
BinLog BinLogConfig `toml:"binlog"`
UseBinLog bool `toml:"use_binlog"`
BinLog BinLogConfig `toml:"binlog"`
SlaveOf string `toml:"slaveof"`

View File

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

View File

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

View File

@ -41,7 +41,7 @@ func Open(cfg *config.Config) (*Ledis, error) {
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!!!")
l.binlog, err = NewBinLog(cfg)
if err != nil {

View File

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

View File

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

View File

@ -16,7 +16,11 @@ import (
)
func getStorePath(cfg *config.Config) string {
return path.Join(cfg.DataDir, fmt.Sprintf("%s_data", cfg.DBName))
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) {