From 5d5786a377b3dd24651f7b5621a167a517e652f5 Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 8 Oct 2014 23:23:00 +0800 Subject: [PATCH 1/2] update file store --- rpl/file_store.go | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/rpl/file_store.go b/rpl/file_store.go index df51b03..91ea418 100644 --- a/rpl/file_store.go +++ b/rpl/file_store.go @@ -2,6 +2,8 @@ package rpl import ( "fmt" + "github.com/siddontang/go/hack" + "github.com/siddontang/go/ioutil2" "github.com/siddontang/go/log" "io/ioutil" "os" @@ -121,23 +123,8 @@ func (s *FileStore) Close() error { func (s *FileStore) flushIndex() error { data := strings.Join(s.logNames, "\n") - bakName := fmt.Sprintf("%s.bak", s.indexName) - f, err := os.OpenFile(bakName, os.O_WRONLY|os.O_CREATE, 0644) - if err != nil { - log.Error("create bak index error %s", err.Error()) - return err - } - - if _, err := f.WriteString(data); err != nil { - log.Error("write index error %s", err.Error()) - f.Close() - return err - } - - f.Close() - - if err := os.Rename(bakName, s.indexName); err != nil { - log.Error("rename bak index error %s", err.Error()) + if err := ioutil2.WriteFileAtomic(s.indexName, hack.Slice(data), 0644); err != nil { + log.Error("flush index error %s", err.Error()) return err } From 771d32c87966bda993e104c17a20631d34c20f39 Mon Sep 17 00:00:00 2001 From: siddontang Date: Thu, 9 Oct 2014 10:47:21 +0800 Subject: [PATCH 2/2] bugfix for info command --- server/info.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/server/info.go b/server/info.go index 119c6d3..21c989b 100644 --- a/server/info.go +++ b/server/info.go @@ -161,10 +161,11 @@ func (i *info) dumpReplication(buf *bytes.Buffer) { p = append(p, infoPair{"slave", strings.Join(slaves, ",")}) } - s, _ := i.app.ldb.ReplicationStat() - p = append(p, infoPair{"last_log_id", s.LastID}) - p = append(p, infoPair{"first_log_id", s.FirstID}) - p = append(p, infoPair{"commit_log_id", s.CommitID}) + if s, _ := i.app.ldb.ReplicationStat(); s != nil { + p = append(p, infoPair{"last_log_id", s.LastID}) + p = append(p, infoPair{"first_log_id", s.FirstID}) + p = append(p, infoPair{"commit_log_id", s.CommitID}) + } i.dumpPairs(buf, p...) }