From c5613f194479e10573a06756557a5591f959c565 Mon Sep 17 00:00:00 2001 From: Thomas Graf Date: Mon, 5 Mar 2018 06:51:35 -0800 Subject: [PATCH] etcd: Respect CompactRevision etcd does not support watching on a compacted revision and will error out. Fortunately etcd tells us the minimum compact revision that we can watch, therefore, recreate the watcher with the provided minimum revision. Fixes: #3010 Signed-off-by: Thomas Graf --- pkg/kvstore/etcd.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/kvstore/etcd.go b/pkg/kvstore/etcd.go index fb5443172cc0c..037c51b71bd92 100644 --- a/pkg/kvstore/etcd.go +++ b/pkg/kvstore/etcd.go @@ -31,6 +31,7 @@ import ( client "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/clientv3/concurrency" clientyaml "github.com/coreos/etcd/clientv3/yaml" + v3rpcErrors "github.com/coreos/etcd/etcdserver/api/v3rpc/rpctypes" "github.com/hashicorp/go-version" "github.com/sirupsen/logrus" ctx "golang.org/x/net/context" @@ -487,11 +488,11 @@ func (e *etcdClient) Watch(w *Watcher) { recreateWatcher: lastRev++ - + recreateWatcherWithRev: log.WithFields(logrus.Fields{ fieldRev: lastRev, fieldWatcher: w, - }).Debugf("Starting to watch %s", w.prefix) + }).Debugf("Starting to watch %s from revision %d", w.prefix, lastRev) etcdWatch := e.client.Watch(ctx.Background(), w.prefix, client.WithPrefix(), client.WithRev(lastRev)) for { @@ -511,7 +512,13 @@ func (e *etcdClient) Watch(w *Watcher) { log.WithFields(logrus.Fields{ fieldRev: lastRev, fieldWatcher: w, - }).WithError(err).Warningf("etcd watcher received error") + }).WithError(err).Warning("etcd watcher received error") + + if err == v3rpcErrors.ErrCompacted { + lastRev = r.CompactRevision + goto recreateWatcherWithRev + } + continue }