From cb062bded453f533378c075d85ee036f544268e8 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Fri, 4 Aug 2017 05:28:35 -0700 Subject: [PATCH] allow reads on disconnected followers (#121) --- controller/controller.go | 3 ++- controller/follow.go | 2 ++ controller/stats.go | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/controller/controller.go b/controller/controller.go index 254f2b94..fabba113 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -84,6 +84,7 @@ type Controller struct { lives map[*liveBuffer]bool lcond *sync.Cond fcup bool // follow caught up + fcuponce bool // follow caught up once shrinking bool // aof shrinking flag shrinklog [][]string // aof shrinking log hooks map[string]*Hook // hook name @@ -492,7 +493,7 @@ func (c *Controller) handleInputCommand(conn *server.Conn, msg *server.Message, // read operations c.mu.RLock() defer c.mu.RUnlock() - if c.config.FollowHost != "" && !c.fcup { + if c.config.FollowHost != "" && !c.fcuponce { return writeErr(errors.New("catching up to leader")) } case "follow", "readonly", "config": diff --git a/controller/follow.go b/controller/follow.go index 85629cfc..c31978e4 100644 --- a/controller/follow.go +++ b/controller/follow.go @@ -218,6 +218,7 @@ func (c *Controller) followStep(host string, port int, followc uint64) error { if caughtUp { c.mu.Lock() c.fcup = true + c.fcuponce = true c.mu.Unlock() log.Info("caught up") } @@ -241,6 +242,7 @@ func (c *Controller) followStep(host string, port int, followc uint64) error { caughtUp = true c.mu.Lock() c.fcup = true + c.fcuponce = true c.mu.Unlock() log.Info("caught up") } diff --git a/controller/stats.go b/controller/stats.go index 9a0864ce..ffc0b460 100644 --- a/controller/stats.go +++ b/controller/stats.go @@ -80,6 +80,7 @@ func (c *Controller) cmdServer(msg *server.Message) (res string, err error) { if c.config.FollowHost != "" { m["following"] = fmt.Sprintf("%s:%d", c.config.FollowHost, c.config.FollowPort) m["caught_up"] = c.fcup + m["caught_up_once"] = c.fcuponce } m["http_transport"] = c.http m["pid"] = os.Getpid()