forked from mirror/ledisdb
adjust config
This commit is contained in:
parent
e3c2102080
commit
4a1c74cb44
|
@ -20,6 +20,7 @@ var usePprof = flag.Bool("pprof", false, "enable pprof")
|
|||
var pprofPort = flag.Int("pprof_port", 6060, "pprof http port")
|
||||
var slaveof = flag.String("slaveof", "", "make the server a slave of another instance")
|
||||
var readonly = flag.Bool("readonly", false, "set readonly mode, salve server is always readonly")
|
||||
var rpl = flag.Bool("rpl", false, "enable replication or not, slave server is always enabled")
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||
|
@ -48,8 +49,10 @@ func main() {
|
|||
if len(*slaveof) > 0 {
|
||||
cfg.SlaveOf = *slaveof
|
||||
cfg.Readonly = true
|
||||
cfg.UseReplication = true
|
||||
} else {
|
||||
cfg.Readonly = *readonly
|
||||
cfg.UseReplication = *rpl
|
||||
}
|
||||
|
||||
var app *server.App
|
||||
|
|
|
@ -15,7 +15,6 @@ var (
|
|||
|
||||
const (
|
||||
DefaultAddr string = "127.0.0.1:6380"
|
||||
DefaultHttpAddr string = "127.0.0.1:11181"
|
||||
|
||||
DefaultDBName string = "goleveldb"
|
||||
|
||||
|
@ -101,6 +100,8 @@ func NewConfigWithData(data []byte) (*Config, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
cfg.adjust()
|
||||
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
|
@ -108,7 +109,7 @@ func NewConfigDefault() *Config {
|
|||
cfg := new(Config)
|
||||
|
||||
cfg.Addr = DefaultAddr
|
||||
cfg.HttpAddr = DefaultHttpAddr
|
||||
cfg.HttpAddr = ""
|
||||
|
||||
cfg.DataDir = DefaultDataDir
|
||||
|
||||
|
@ -123,28 +124,36 @@ func NewConfigDefault() *Config {
|
|||
cfg.LMDB.MapSize = 20 * 1024 * 1024
|
||||
cfg.LMDB.NoSync = true
|
||||
|
||||
cfg.Replication.WaitSyncTime = 1
|
||||
cfg.UseReplication = false
|
||||
cfg.Replication.WaitSyncTime = 500
|
||||
cfg.Replication.Compression = true
|
||||
cfg.Replication.WaitMaxSlaveAcks = 2
|
||||
cfg.Replication.SyncLog = 0
|
||||
|
||||
cfg.adjust()
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (cfg *LevelDBConfig) Adjust() {
|
||||
if cfg.CacheSize <= 0 {
|
||||
cfg.CacheSize = 4 * 1024 * 1024
|
||||
func (cfg *Config) adjust() {
|
||||
if cfg.LevelDB.CacheSize <= 0 {
|
||||
cfg.LevelDB.CacheSize = 4 * 1024 * 1024
|
||||
}
|
||||
|
||||
if cfg.BlockSize <= 0 {
|
||||
cfg.BlockSize = 4 * 1024
|
||||
if cfg.LevelDB.BlockSize <= 0 {
|
||||
cfg.LevelDB.BlockSize = 4 * 1024
|
||||
}
|
||||
|
||||
if cfg.WriteBufferSize <= 0 {
|
||||
cfg.WriteBufferSize = 4 * 1024 * 1024
|
||||
if cfg.LevelDB.WriteBufferSize <= 0 {
|
||||
cfg.LevelDB.WriteBufferSize = 4 * 1024 * 1024
|
||||
}
|
||||
|
||||
if cfg.MaxOpenFiles < 1024 {
|
||||
cfg.MaxOpenFiles = 1024
|
||||
if cfg.LevelDB.MaxOpenFiles < 1024 {
|
||||
cfg.LevelDB.MaxOpenFiles = 1024
|
||||
}
|
||||
|
||||
if cfg.Replication.ExpiredLogDays <= 0 {
|
||||
cfg.Replication.ExpiredLogDays = 7
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@ path = ""
|
|||
# It will reduce performance but have better high availability.
|
||||
sync = true
|
||||
|
||||
# If sync is true, wait at last wait_sync_time seconds for slave syncing this log
|
||||
wait_sync_time = 1
|
||||
# If sync is true, wait at last wait_sync_time milliseconds for slave syncing this log
|
||||
wait_sync_time = 500
|
||||
|
||||
# If sync is true, wait at most min(wait_max_slave_acks, (n + 1) / 2) to promise syncing ok.
|
||||
# n is slave number
|
||||
|
|
|
@ -58,8 +58,8 @@ path = ""
|
|||
# It will reduce performance but have better high availability.
|
||||
sync = true
|
||||
|
||||
# If sync is true, wait at last wait_sync_time seconds for slave syncing this log
|
||||
wait_sync_time = 1
|
||||
# If sync is true, wait at last wait_sync_time milliseconds for slave syncing this log
|
||||
wait_sync_time = 500
|
||||
|
||||
# If sync is true, wait at most min(wait_max_slave_acks, (n + 1) / 2) to promise syncing ok.
|
||||
# n is slave number
|
||||
|
@ -81,6 +81,7 @@ compression = true
|
|||
[snapshot]
|
||||
# Path to store snapshot dump file
|
||||
# if not set, use data_dir/snapshot
|
||||
# snapshot file name format is snap-2006-01-02T15:04:05.999999999.dmp
|
||||
path = ""
|
||||
|
||||
# Reserve newest max_num snapshot dump files
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func TestDump(t *testing.T) {
|
||||
cfgM := new(config.Config)
|
||||
cfgM := config.NewConfigDefault()
|
||||
cfgM.DataDir = "/tmp/test_ledis_master"
|
||||
|
||||
os.RemoveAll(cfgM.DataDir)
|
||||
|
@ -19,7 +19,7 @@ func TestDump(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfgS := new(config.Config)
|
||||
cfgS := config.NewConfigDefault()
|
||||
cfgS.DataDir = "/tmp/test_ledis_slave"
|
||||
os.RemoveAll(cfgM.DataDir)
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ var testLedisOnce sync.Once
|
|||
|
||||
func getTestDB() *DB {
|
||||
f := func() {
|
||||
cfg := new(config.Config)
|
||||
cfg := config.NewConfigDefault()
|
||||
cfg.DataDir = "/tmp/test_ledis"
|
||||
|
||||
os.RemoveAll(cfg.DataDir)
|
||||
|
|
|
@ -30,7 +30,7 @@ func TestReplication(t *testing.T) {
|
|||
var slave *Ledis
|
||||
var err error
|
||||
|
||||
cfgM := new(config.Config)
|
||||
cfgM := config.NewConfigDefault()
|
||||
cfgM.DataDir = "/tmp/test_repl/master"
|
||||
|
||||
cfgM.UseReplication = true
|
||||
|
@ -43,7 +43,7 @@ func TestReplication(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
cfgS := new(config.Config)
|
||||
cfgS := config.NewConfigDefault()
|
||||
cfgS.DataDir = "/tmp/test_repl/slave"
|
||||
cfgS.UseReplication = true
|
||||
cfgS.Readonly = true
|
||||
|
|
|
@ -190,7 +190,7 @@ func testTxSelect(t *testing.T, db *DB) {
|
|||
}
|
||||
|
||||
func testTx(t *testing.T, name string) {
|
||||
cfg := new(config.Config)
|
||||
cfg := config.NewConfigDefault()
|
||||
cfg.DataDir = "/tmp/ledis_test_tx"
|
||||
|
||||
cfg.DBName = name
|
||||
|
|
|
@ -269,12 +269,12 @@ func (s *GoLevelDBStore) open() error {
|
|||
}
|
||||
|
||||
func NewGoLevelDBStore(base string) (*GoLevelDBStore, error) {
|
||||
cfg := new(config.Config)
|
||||
cfg := config.NewConfigDefault()
|
||||
cfg.DBName = "goleveldb"
|
||||
cfg.DBPath = base
|
||||
cfg.LevelDB.BlockSize = 4 * 1024 * 1024
|
||||
cfg.LevelDB.CacheSize = 16 * 1024 * 1024
|
||||
cfg.LevelDB.WriteBufferSize = 4 * 1024 * 1024
|
||||
cfg.LevelDB.BlockSize = 16 * 1024 * 1024
|
||||
cfg.LevelDB.CacheSize = 64 * 1024 * 1024
|
||||
cfg.LevelDB.WriteBufferSize = 64 * 1024 * 1024
|
||||
cfg.LevelDB.Compression = false
|
||||
|
||||
s := new(GoLevelDBStore)
|
||||
|
|
|
@ -14,7 +14,7 @@ func TestReplication(t *testing.T) {
|
|||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
c := new(config.Config)
|
||||
c := config.NewConfigDefault()
|
||||
c.Replication.Path = dir
|
||||
|
||||
r, err := NewReplication(c)
|
||||
|
|
|
@ -29,7 +29,7 @@ func startTestApp() {
|
|||
f := func() {
|
||||
newTestLedisClient()
|
||||
|
||||
cfg := new(config.Config)
|
||||
cfg := config.NewConfigDefault()
|
||||
cfg.DataDir = "/tmp/testdb"
|
||||
os.RemoveAll(cfg.DataDir)
|
||||
|
||||
|
|
|
@ -37,12 +37,12 @@ func TestReplication(t *testing.T) {
|
|||
data_dir := "/tmp/test_replication"
|
||||
os.RemoveAll(data_dir)
|
||||
|
||||
masterCfg := new(config.Config)
|
||||
masterCfg := config.NewConfigDefault()
|
||||
masterCfg.DataDir = fmt.Sprintf("%s/master", data_dir)
|
||||
masterCfg.Addr = "127.0.0.1:11182"
|
||||
masterCfg.UseReplication = true
|
||||
masterCfg.Replication.Sync = true
|
||||
masterCfg.Replication.WaitSyncTime = 5
|
||||
masterCfg.Replication.WaitSyncTime = 5000
|
||||
|
||||
var master *App
|
||||
var slave *App
|
||||
|
@ -53,7 +53,7 @@ func TestReplication(t *testing.T) {
|
|||
}
|
||||
defer master.Close()
|
||||
|
||||
slaveCfg := new(config.Config)
|
||||
slaveCfg := config.NewConfigDefault()
|
||||
slaveCfg.DataDir = fmt.Sprintf("%s/slave", data_dir)
|
||||
slaveCfg.Addr = "127.0.0.1:11183"
|
||||
slaveCfg.SlaveOf = masterCfg.Addr
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
//
|
||||
// Start a ledis server is very simple:
|
||||
//
|
||||
// cfg := new(config.Config)
|
||||
// cfg := config.NewConfigDefault()
|
||||
// cfg.Addr = "127.0.0.1:6380"
|
||||
// cfg.DataDir = "/tmp/ledis"
|
||||
// app := server.NewApp(cfg)
|
||||
|
|
|
@ -366,7 +366,7 @@ func (app *App) publishNewLog(l *rpl.Log) {
|
|||
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(time.Duration(app.cfg.Replication.WaitSyncTime) * time.Second):
|
||||
case <-time.After(time.Duration(app.cfg.Replication.WaitSyncTime) * time.Millisecond):
|
||||
log.Info("replication wait timeout")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
func TestScan(t *testing.T) {
|
||||
cfg := new(config.Config)
|
||||
cfg := config.NewConfigDefault()
|
||||
cfg.DataDir = "/tmp/test_scan"
|
||||
cfg.Addr = "127.0.0.1:11185"
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ var testScript4 = `
|
|||
`
|
||||
|
||||
func TestLuaCall(t *testing.T) {
|
||||
cfg := new(config.Config)
|
||||
cfg := config.NewConfigDefault()
|
||||
cfg.Addr = ":11188"
|
||||
cfg.DataDir = "/tmp/testscript"
|
||||
cfg.DBName = "memory"
|
||||
|
|
|
@ -18,7 +18,7 @@ func (d *testSnapshotDumper) Dump(w io.Writer) error {
|
|||
}
|
||||
|
||||
func TestSnapshot(t *testing.T) {
|
||||
cfg := new(config.Config)
|
||||
cfg := config.NewConfigDefault()
|
||||
cfg.Snapshot.MaxNum = 2
|
||||
cfg.Snapshot.Path = path.Join(os.TempDir(), "snapshot")
|
||||
defer os.RemoveAll(cfg.Snapshot.Path)
|
||||
|
|
|
@ -113,8 +113,6 @@ func newOptions(cfg *config.LevelDBConfig) *opt.Options {
|
|||
opts := &opt.Options{}
|
||||
opts.ErrorIfMissing = false
|
||||
|
||||
cfg.Adjust()
|
||||
|
||||
opts.BlockCache = cache.NewLRUCache(cfg.CacheSize)
|
||||
|
||||
//we must use bloomfilter
|
||||
|
|
|
@ -108,8 +108,6 @@ func (db *DB) initOptions(cfg *config.LevelDBConfig) {
|
|||
|
||||
opts.SetCreateIfMissing(true)
|
||||
|
||||
cfg.Adjust()
|
||||
|
||||
db.cache = NewLRUCache(cfg.CacheSize)
|
||||
opts.SetCache(db.cache)
|
||||
|
||||
|
|
|
@ -108,8 +108,6 @@ func (db *DB) initOptions(cfg *config.LevelDBConfig) {
|
|||
|
||||
opts.SetCreateIfMissing(true)
|
||||
|
||||
cfg.Adjust()
|
||||
|
||||
db.cache = NewLRUCache(cfg.CacheSize)
|
||||
opts.SetCache(db.cache)
|
||||
|
||||
|
|
|
@ -113,8 +113,6 @@ func (db *DB) initOptions(cfg *config.LevelDBConfig) {
|
|||
|
||||
opts.SetCreateIfMissing(true)
|
||||
|
||||
cfg.Adjust()
|
||||
|
||||
db.env = NewDefaultEnv()
|
||||
db.env.SetBackgroundThreads(runtime.NumCPU() * 2)
|
||||
db.env.SetHighPriorityBackgroundThreads(1)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func TestStore(t *testing.T) {
|
||||
cfg := new(config.Config)
|
||||
cfg := config.NewConfigDefault()
|
||||
cfg.DataDir = "/tmp/testdb"
|
||||
cfg.LMDB.MapSize = 10 * 1024 * 1024
|
||||
|
||||
|
|
Loading…
Reference in New Issue