Merge branch 'develop'

This commit is contained in:
siddontang 2014-10-09 10:47:38 +08:00
commit d0c09f4c50
2 changed files with 9 additions and 21 deletions

View File

@ -2,6 +2,8 @@ package rpl
import ( import (
"fmt" "fmt"
"github.com/siddontang/go/hack"
"github.com/siddontang/go/ioutil2"
"github.com/siddontang/go/log" "github.com/siddontang/go/log"
"io/ioutil" "io/ioutil"
"os" "os"
@ -121,23 +123,8 @@ func (s *FileStore) Close() error {
func (s *FileStore) flushIndex() error { func (s *FileStore) flushIndex() error {
data := strings.Join(s.logNames, "\n") data := strings.Join(s.logNames, "\n")
bakName := fmt.Sprintf("%s.bak", s.indexName) if err := ioutil2.WriteFileAtomic(s.indexName, hack.Slice(data), 0644); err != nil {
f, err := os.OpenFile(bakName, os.O_WRONLY|os.O_CREATE, 0644) log.Error("flush index error %s", err.Error())
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())
return err return err
} }

View File

@ -161,10 +161,11 @@ func (i *info) dumpReplication(buf *bytes.Buffer) {
p = append(p, infoPair{"slave", strings.Join(slaves, ",")}) p = append(p, infoPair{"slave", strings.Join(slaves, ",")})
} }
s, _ := i.app.ldb.ReplicationStat() if s, _ := i.app.ldb.ReplicationStat(); s != nil {
p = append(p, infoPair{"last_log_id", s.LastID}) p = append(p, infoPair{"last_log_id", s.LastID})
p = append(p, infoPair{"first_log_id", s.FirstID}) p = append(p, infoPair{"first_log_id", s.FirstID})
p = append(p, infoPair{"commit_log_id", s.CommitID}) p = append(p, infoPair{"commit_log_id", s.CommitID})
}
i.dumpPairs(buf, p...) i.dumpPairs(buf, p...)
} }