From fafd0c7e807580f9de0437c1f42656b304b2a994 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 18 Sep 2014 10:25:15 +0800 Subject: [PATCH 1/3] add flag for pprof --- cmd/ledis-server/main.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/ledis-server/main.go b/cmd/ledis-server/main.go index c0e1204..448120c 100644 --- a/cmd/ledis-server/main.go +++ b/cmd/ledis-server/main.go @@ -2,6 +2,7 @@ package main import ( "flag" + "fmt" "github.com/siddontang/ledisdb/config" "github.com/siddontang/ledisdb/server" "log" @@ -15,6 +16,8 @@ import ( var configFile = flag.String("config", "", "ledisdb config file") var dbName = flag.String("db_name", "", "select a db to use, it will overwrite the config's db name") +var usePprof = flag.Bool("pprof", false, "enable pprof") +var pprofPort = flag.Int("pprof_port", 6060, "pprof http port") func main() { runtime.GOMAXPROCS(runtime.NumCPU()) @@ -60,9 +63,11 @@ func main() { app.Close() }() - go func() { - log.Println(http.ListenAndServe("localhost:6060", nil)) - }() + if *usePprof { + go func() { + log.Println(http.ListenAndServe(fmt.Sprintf(":%d", *pprofPort), nil)) + }() + } app.Run() } From 0a72481eb0a7a7f09c2a89e698f8788c47923ec8 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 18 Sep 2014 21:27:43 +0800 Subject: [PATCH 2/3] mode use 0644 for file, 0755 for dir --- cmd/ledis-dump/main.go | 2 +- ledis/binlog.go | 6 +++--- server/replication.go | 4 ++-- store/boltdb/db.go | 2 +- store/goleveldb/db.go | 2 +- store/hyperleveldb/db.go | 2 +- store/leveldb/db.go | 2 +- store/rocksdb/db.go | 2 +- store/store.go | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cmd/ledis-dump/main.go b/cmd/ledis-dump/main.go index bf02ad7..b6a798d 100644 --- a/cmd/ledis-dump/main.go +++ b/cmd/ledis-dump/main.go @@ -23,7 +23,7 @@ func main() { var err error var f *os.File - if f, err = os.OpenFile(*dumpFile, os.O_CREATE|os.O_WRONLY, os.ModePerm); err != nil { + if f, err = os.OpenFile(*dumpFile, os.O_CREATE|os.O_WRONLY, 0644); err != nil { println(err.Error()) return } diff --git a/ledis/binlog.go b/ledis/binlog.go index 077398a..0d9c251 100644 --- a/ledis/binlog.go +++ b/ledis/binlog.go @@ -117,7 +117,7 @@ func NewBinLog(cfg *config.Config) (*BinLog, error) { l.path = path.Join(cfg.DataDir, "binlog") - if err := os.MkdirAll(l.path, os.ModePerm); err != nil { + if err := os.MkdirAll(l.path, 0755); err != nil { return nil, err } @@ -136,7 +136,7 @@ func (l *BinLog) flushIndex() error { data := strings.Join(l.logNames, "\n") bakName := fmt.Sprintf("%s.bak", l.indexName) - f, err := os.OpenFile(bakName, os.O_WRONLY|os.O_CREATE, 0666) + f, err := os.OpenFile(bakName, os.O_WRONLY|os.O_CREATE, 0644) if err != nil { log.Error("create binlog bak index error %s", err.Error()) return err @@ -217,7 +217,7 @@ func (l *BinLog) openNewLogFile() error { lastName := l.getLogFile() logPath := path.Join(l.path, lastName) - if l.logFile, err = os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY, 0666); err != nil { + if l.logFile, err = os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY, 0644); err != nil { log.Error("open new logfile error %s", err.Error()) return err } diff --git a/server/replication.go b/server/replication.go index 267a29b..445a813 100644 --- a/server/replication.go +++ b/server/replication.go @@ -38,7 +38,7 @@ func (m *MasterInfo) Save(filePath string) error { filePathBak := fmt.Sprintf("%s.bak", filePath) var fd *os.File - fd, err = os.OpenFile(filePathBak, os.O_CREATE|os.O_WRONLY, os.ModePerm) + fd, err = os.OpenFile(filePathBak, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return err } @@ -250,7 +250,7 @@ func (m *master) fullSync() error { } dumpPath := path.Join(m.app.cfg.DataDir, "master.dump") - f, err := os.OpenFile(dumpPath, os.O_CREATE|os.O_WRONLY, os.ModePerm) + f, err := os.OpenFile(dumpPath, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { return err } diff --git a/store/boltdb/db.go b/store/boltdb/db.go index f2cb1f3..15a0570 100644 --- a/store/boltdb/db.go +++ b/store/boltdb/db.go @@ -18,7 +18,7 @@ func (s Store) String() string { } func (s Store) Open(dbPath string, cfg *config.Config) (driver.IDB, error) { - os.MkdirAll(dbPath, os.ModePerm) + os.MkdirAll(dbPath, 0755) name := path.Join(dbPath, "ledis_bolt.db") db := new(DB) var err error diff --git a/store/goleveldb/db.go b/store/goleveldb/db.go index 2a13f50..dad6a90 100644 --- a/store/goleveldb/db.go +++ b/store/goleveldb/db.go @@ -47,7 +47,7 @@ type DB struct { } func (s Store) Open(path string, cfg *config.Config) (driver.IDB, error) { - if err := os.MkdirAll(path, os.ModePerm); err != nil { + if err := os.MkdirAll(path, 0755); err != nil { return nil, err } diff --git a/store/hyperleveldb/db.go b/store/hyperleveldb/db.go index d6d7aeb..071dd38 100644 --- a/store/hyperleveldb/db.go +++ b/store/hyperleveldb/db.go @@ -28,7 +28,7 @@ func (s Store) String() string { } func (s Store) Open(path string, cfg *config.Config) (driver.IDB, error) { - if err := os.MkdirAll(path, os.ModePerm); err != nil { + if err := os.MkdirAll(path, 0755); err != nil { return nil, err } diff --git a/store/leveldb/db.go b/store/leveldb/db.go index 92a2419..ab29928 100644 --- a/store/leveldb/db.go +++ b/store/leveldb/db.go @@ -28,7 +28,7 @@ func (s Store) String() string { } func (s Store) Open(path string, cfg *config.Config) (driver.IDB, error) { - if err := os.MkdirAll(path, os.ModePerm); err != nil { + if err := os.MkdirAll(path, 0755); err != nil { return nil, err } diff --git a/store/rocksdb/db.go b/store/rocksdb/db.go index 1c79229..f3fb406 100644 --- a/store/rocksdb/db.go +++ b/store/rocksdb/db.go @@ -29,7 +29,7 @@ func (s Store) String() string { } func (s Store) Open(path string, cfg *config.Config) (driver.IDB, error) { - if err := os.MkdirAll(path, os.ModePerm); err != nil { + if err := os.MkdirAll(path, 0755); err != nil { return nil, err } diff --git a/store/store.go b/store/store.go index d620c03..aa4b485 100644 --- a/store/store.go +++ b/store/store.go @@ -27,7 +27,7 @@ func Open(cfg *config.Config) (*DB, error) { path := getStorePath(cfg) - if err := os.MkdirAll(path, os.ModePerm); err != nil { + if err := os.MkdirAll(path, 0755); err != nil { return nil, err } From ee59af00628c04166db9c794ac5024f29562f43f Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 18 Sep 2014 21:54:33 +0800 Subject: [PATCH 3/3] add warning for bin log --- ledis/ledis.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ledis/ledis.go b/ledis/ledis.go index f3c1c8c..30e6ac7 100644 --- a/ledis/ledis.go +++ b/ledis/ledis.go @@ -42,6 +42,7 @@ func Open(cfg *config.Config) (*Ledis, error) { l.ldb = ldb if cfg.BinLog.MaxFileNum > 0 && cfg.BinLog.MaxFileSize > 0 { + println("binlog will be refactored later, use your own risk!!!") l.binlog, err = NewBinLog(cfg) if err != nil { return nil, err