diff --git a/ledis/replication.go b/ledis/replication.go index 4937952..ee219a6 100644 --- a/ledis/replication.go +++ b/ledis/replication.go @@ -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() +} diff --git a/server/client.go b/server/client.go index 5bceaef..4474086 100644 --- a/server/client.go +++ b/server/client.go @@ -49,7 +49,7 @@ type client struct { syncBuf bytes.Buffer compressBuf []byte - lastSyncLogID uint64 + lastLogID uint64 ack *syncAck diff --git a/server/cmd_replication.go b/server/cmd_replication.go index 8447941..36ee248 100644 --- a/server/cmd_replication.go +++ b/server/cmd_replication.go @@ -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 { diff --git a/server/info.go b/server/info.go index cae6a3f..0680c20 100644 --- a/server/info.go +++ b/server/info.go @@ -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)) diff --git a/server/replication.go b/server/replication.go index f05c676..6ccbced 100644 --- a/server/replication.go +++ b/server/replication.go @@ -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