From 5e5c092653f56d268e25cbe2a4dfc24d0dca514f Mon Sep 17 00:00:00 2001 From: ShuNing Date: Sat, 29 Dec 2018 15:24:56 +0800 Subject: [PATCH] server/leader: use the compact revision to watch leader (#1396) * server/leader: use the compact revision to watch leader Signed-off-by: nolouch --- server/leader.go | 9 ++++++--- tests/server/leader_watch_test.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/leader.go b/server/leader.go index a4cb81d77c3..81fb2e875e4 100644 --- a/server/leader.go +++ b/server/leader.go @@ -310,14 +310,17 @@ func (s *Server) watchLeader(leader *pdpb.Member, revision int64) { defer s.cluster.regionSyncer.StopSyncWithLeader() } + // The revision is the revision of last modification on this key. + // If the revision is compacted, will meet required revision has been compacted error. + // In this case, use the compact revision to re-watch the key. for { // gofail: var delayWatcher struct{} rch := watcher.Watch(ctx, s.getLeaderPath(), clientv3.WithRev(revision)) for wresp := range rch { - // meet compacted error, use current revision. + // meet compacted error, use the compact revision. if wresp.CompactRevision != 0 { - log.Warnf("required revision %d has been compacted, use current revision", revision) - revision = 0 + log.Warnf("required revision %d has been compacted, use the compact revision %d", revision, wresp.CompactRevision) + revision = wresp.CompactRevision break } if wresp.Canceled { diff --git a/tests/server/leader_watch_test.go b/tests/server/leader_watch_test.go index d98e06f377b..8dece401b0e 100644 --- a/tests/server/leader_watch_test.go +++ b/tests/server/leader_watch_test.go @@ -26,7 +26,7 @@ import ( func (s *serverTestSuite) TestWatcher(c *C) { c.Parallel() - cluster, err := tests.NewTestCluster(1) + cluster, err := tests.NewTestCluster(1, func(conf *server.Config) { conf.AutoCompactionRetention = "1s" }) c.Assert(err, IsNil) defer cluster.Destroy()