diff --git a/etc/ledis.json b/etc/ledis.json index 92d9f93..dcf2ea5 100644 --- a/etc/ledis.json +++ b/etc/ledis.json @@ -1,8 +1,8 @@ { "addr": "127.0.0.1:6380", + "data_dir": "/tmp/ledis_server", "db": { "data_db" : { - "path": "/tmp/ledisdb", "compression": false, "block_size": 32768, "write_buffer_size": 67108864, diff --git a/ledis/ledis.go b/ledis/ledis.go index 8ba83b2..ad2bc76 100644 --- a/ledis/ledis.go +++ b/ledis/ledis.go @@ -13,11 +13,13 @@ type Config struct { DataDir string `json:"data_dir"` //data_db path is data_dir/data + //if you not set leveldb path, use data_dir/data DataDB leveldb.Config `json:"data_db"` //binlog path is data_dir/binlog //you muse set binlog name to enable binlog - BinLog replication.BinLogConfig `json:"binlog"` + //if you not set bin log path, use data_dir/bin_log + BinLog replication.BinLogConfig `json:"bin_log"` } type DB struct { @@ -61,7 +63,10 @@ func OpenWithConfig(cfg *Config) (*Ledis, error) { return nil, fmt.Errorf("must set correct data_dir") } - cfg.DataDB.Path = path.Join(cfg.DataDir, "data") + if len(cfg.DataDB.Path) == 0 { + cfg.DataDB.Path = path.Join(cfg.DataDir, "data") + } + ldb, err := leveldb.OpenWithConfig(&cfg.DataDB) if err != nil { return nil, err @@ -74,7 +79,9 @@ func OpenWithConfig(cfg *Config) (*Ledis, error) { l.ldb = ldb if len(cfg.BinLog.Name) > 0 { - cfg.BinLog.Path = path.Join(cfg.DataDir, "binlog") + if len(cfg.BinLog.Path) == 0 { + cfg.BinLog.Path = path.Join(cfg.DataDir, "bin_log") + } l.binlog, err = replication.NewBinLogWithConfig(&cfg.BinLog) if err != nil { return nil, err diff --git a/ledis/replication_test.go b/ledis/replication_test.go index f22617e..a3a2d6f 100644 --- a/ledis/replication_test.go +++ b/ledis/replication_test.go @@ -17,7 +17,7 @@ func TestReplication(t *testing.T) { master, err = Open([]byte(` { "data_dir" : "/tmp/test_repl/master", - "binlog": { + "bin_log": { "name" : "ledis" } } diff --git a/server/app.go b/server/app.go index 9e7e029..5e414ee 100644 --- a/server/app.go +++ b/server/app.go @@ -1,6 +1,7 @@ package server import ( + "fmt" "github.com/siddontang/ledisdb/ledis" "net" "strings" @@ -17,6 +18,14 @@ type App struct { } func NewApp(cfg *Config) (*App, error) { + if len(cfg.DataDir) == 0 { + return nil, fmt.Errorf("must set data_dir first") + } + + if len(cfg.DB.DataDir) == 0 { + cfg.DB.DataDir = cfg.DataDir + } + app := new(App) app.closed = false diff --git a/server/app_test.go b/server/app_test.go index efaf08e..3357ddd 100644 --- a/server/app_test.go +++ b/server/app_test.go @@ -38,9 +38,9 @@ func startTestApp() { var d = []byte(` { + "data_dir" : "/tmp/testdb", "addr" : "127.0.0.1:16380", "db" : { - "data_dir" : "/tmp/testdb", "data_db" : { "compression":true, "block_size" : 32768, diff --git a/server/config.go b/server/config.go index 5e98694..592b51d 100644 --- a/server/config.go +++ b/server/config.go @@ -3,13 +3,20 @@ package server import ( "encoding/json" "github.com/siddontang/ledisdb/ledis" + "github.com/siddontang/ledisdb/replication" "io/ioutil" ) type Config struct { Addr string `json:"addr"` + DataDir string `json:"data_dir"` + + //if you not set db path, use data_dir DB ledis.Config `json:"db"` + + //if you not set relay log path, use data_dir/realy_log + RelayLog replication.RelayLogConfig `json:"relay_log"` } func NewConfig(data json.RawMessage) (*Config, error) {