Skip to content

Commit

Permalink
etcd: Respect CompactRevision
Browse files Browse the repository at this point in the history
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 <thomas@cilium.io>
  • Loading branch information
tgraf committed Mar 5, 2018
1 parent d76e7f4 commit c5613f1
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/kvstore/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit c5613f1

Please sign in to comment.