From e3bdb57be219ecb297500ca1f56b600183c6eaf8 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 18 Sep 2014 22:30:33 +0800 Subject: [PATCH] add DBPath and UseBinLog config --- config/config.go | 5 ++++- config/config.toml | 6 ++++++ config/config_test.go | 1 + ledis/ledis.go | 2 +- ledis/replication_test.go | 1 + server/cmd_replication_test.go | 3 +-- store/store.go | 6 +++++- 7 files changed, 19 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index ca93d29..c5736ee 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` diff --git a/config/config.toml b/config/config.toml index 2a3a246..29e5c5d 100644 --- a/config/config.toml +++ b/config/config.toml @@ -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 diff --git a/config/config_test.go b/config/config_test.go index 218ba0f..70b4c9c 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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 diff --git a/ledis/ledis.go b/ledis/ledis.go index 2d52c11..bb46152 100644 --- a/ledis/ledis.go +++ b/ledis/ledis.go @@ -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 { diff --git a/ledis/replication_test.go b/ledis/replication_test.go index 07643c6..8515229 100644 --- a/ledis/replication_test.go +++ b/ledis/replication_test.go @@ -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 diff --git a/server/cmd_replication_test.go b/server/cmd_replication_test.go index 5d20ff5..5b3030c 100644 --- a/server/cmd_replication_test.go +++ b/server/cmd_replication_test.go @@ -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 diff --git a/store/store.go b/store/store.go index aa4b485..2edde30 100644 --- a/store/store.go +++ b/store/store.go @@ -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) {