update info

This commit is contained in:
siddontang 2014-09-23 17:53:52 +08:00
parent 1a1250d949
commit 4bb886adff
5 changed files with 26 additions and 4 deletions

View File

@ -216,3 +216,11 @@ func (l *Ledis) AddNewLogEventHandler(h NewLogEventHandler) error {
return nil
}
func (l *Ledis) ReplicationStat() (*rpl.Stat, error) {
if !l.ReplicationUsed() {
return nil, ErrRplNotSupport
}
return l.r.Stat()
}

View File

@ -49,7 +49,7 @@ type client struct {
syncBuf bytes.Buffer
compressBuf []byte
lastSyncLogID uint64
lastLogID uint64
ack *syncAck

View File

@ -78,7 +78,7 @@ func syncCommand(c *client) error {
return ErrCmdParams
}
c.lastSyncLogID = logId - 1
c.lastLogID = logId - 1
if c.ack != nil && logId > c.ack.id {
select {

View File

@ -81,6 +81,8 @@ func (i *info) Dump(section string) []byte {
i.dumpPersistence(buf)
case "goroutine":
i.dumpGoroutine(buf)
case "replication":
i.dumpReplication(buf)
default:
buf.WriteString(fmt.Sprintf("# %s\r\n", section))
}
@ -103,6 +105,8 @@ func (i *info) dumpAll(buf *bytes.Buffer) {
i.dumpMem(buf)
buf.Write(Delims)
i.dumpGoroutine(buf)
buf.Write(Delims)
i.dumpReplication(buf)
}
func (i *info) dumpServer(buf *bytes.Buffer) {
@ -142,6 +146,16 @@ func (i *info) dumpPersistence(buf *bytes.Buffer) {
i.dumpPairs(buf, infoPair{"db_name", i.Persistence.DBName})
}
func (i *info) dumpReplication(buf *bytes.Buffer) {
buf.WriteString("# Replication\r\n")
p := []infoPair{}
for s, _ := range i.app.slaves {
p = append(p, infoPair{"slave", s.remoteAddr})
}
i.dumpPairs(buf, p...)
}
func (i *info) dumpPairs(buf *bytes.Buffer, pairs ...infoPair) {
for _, v := range pairs {
buf.WriteString(fmt.Sprintf("%s:%v\r\n", v.Key, v.Value))

View File

@ -261,7 +261,7 @@ func (app *App) removeSlave(c *client) {
if c.ack != nil {
select {
case c.ack.ch <- c.lastSyncLogID:
case c.ack.ch <- c.lastLogID:
default:
}
}
@ -278,7 +278,7 @@ func (app *App) publishNewLog(l *rpl.Log) {
logId := l.ID
for s, _ := range app.slaves {
if s.lastSyncLogID >= logId {
if s.lastLogID >= logId {
//slave has already this log
ss = []*client{}
break