diff --git a/coordination/election/election.go b/coordination/election/election.go index 6578702aaf45132ddfb36db124736f409b46dc6b..b1e7d255ed7486ed61da1b41f71dc5b000ec54fd 100644 --- a/coordination/election/election.go +++ b/coordination/election/election.go @@ -52,6 +52,7 @@ func (s ElectionState) String() string { // Election manages (or witnesses) an election protocol on a given // database prefix. type Election struct { + path string session *concurrency.Session election *concurrency.Election self *pb.Endpoint @@ -63,6 +64,7 @@ type Election struct { func New(session *concurrency.Session, path string, self *pb.Endpoint) *Election { el := concurrency.NewElection(session, path) return &Election{ + path: path, session: session, election: el, self: self, @@ -120,10 +122,12 @@ func (e *Election) runOnce(ctx context.Context, data string, op Op) error { } // Invoke the leader operation. + log.Printf("we are now the leader for %s", e.path) err = op(ctx) // Resign, if the session is still valid. Use a standalone // Context to resign even on cancellation. + log.Printf("resigning leadership for %s", e.path) rctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) rerr := e.election.Resign(rctx) cancel() diff --git a/coordination/watcher/watcher.go b/coordination/watcher/watcher.go index bb347bbc2eb63c0e3e3aaad133ed611aaf8aeaf9..bc8deb4d4c6779e5f905819d6cf3acce90a986bf 100644 --- a/coordination/watcher/watcher.go +++ b/coordination/watcher/watcher.go @@ -2,7 +2,6 @@ package watcher import ( "context" - "fmt" "log" "sync" "time" @@ -131,7 +130,6 @@ func watchOnce(ctx context.Context, cli *clientv3.Client, prefix string, target rch := cli.Watch(ctx, prefix, clientv3.WithPrefix(), clientv3.WithRev(rev)) for resp := range rch { for _, ev := range resp.Events { - fmt.Printf("%s %q : %q\n", ev.Type, ev.Kv.Key, ev.Kv.Value) key := string(ev.Kv.Key)[plen:] switch ev.Type { case clientv3.EventTypePut: