Skip to content
Snippets Groups Projects
Commit a9f5c36a authored by ale's avatar ale
Browse files

Minor logging changes to coordination packages

parent 64203771
Branches
No related tags found
No related merge requests found
......@@ -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()
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment