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

Minor logging changes to coordination packages

parent 64203771
No related branches found
No related tags found
No related merge requests found
...@@ -52,6 +52,7 @@ func (s ElectionState) String() string { ...@@ -52,6 +52,7 @@ func (s ElectionState) String() string {
// Election manages (or witnesses) an election protocol on a given // Election manages (or witnesses) an election protocol on a given
// database prefix. // database prefix.
type Election struct { type Election struct {
path string
session *concurrency.Session session *concurrency.Session
election *concurrency.Election election *concurrency.Election
self *pb.Endpoint self *pb.Endpoint
...@@ -63,6 +64,7 @@ type Election struct { ...@@ -63,6 +64,7 @@ type Election struct {
func New(session *concurrency.Session, path string, self *pb.Endpoint) *Election { func New(session *concurrency.Session, path string, self *pb.Endpoint) *Election {
el := concurrency.NewElection(session, path) el := concurrency.NewElection(session, path)
return &Election{ return &Election{
path: path,
session: session, session: session,
election: el, election: el,
self: self, self: self,
...@@ -120,10 +122,12 @@ func (e *Election) runOnce(ctx context.Context, data string, op Op) error { ...@@ -120,10 +122,12 @@ func (e *Election) runOnce(ctx context.Context, data string, op Op) error {
} }
// Invoke the leader operation. // Invoke the leader operation.
log.Printf("we are now the leader for %s", e.path)
err = op(ctx) err = op(ctx)
// Resign, if the session is still valid. Use a standalone // Resign, if the session is still valid. Use a standalone
// Context to resign even on cancellation. // Context to resign even on cancellation.
log.Printf("resigning leadership for %s", e.path)
rctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) rctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
rerr := e.election.Resign(rctx) rerr := e.election.Resign(rctx)
cancel() cancel()
......
...@@ -2,7 +2,6 @@ package watcher ...@@ -2,7 +2,6 @@ package watcher
import ( import (
"context" "context"
"fmt"
"log" "log"
"sync" "sync"
"time" "time"
...@@ -131,7 +130,6 @@ func watchOnce(ctx context.Context, cli *clientv3.Client, prefix string, target ...@@ -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)) rch := cli.Watch(ctx, prefix, clientv3.WithPrefix(), clientv3.WithRev(rev))
for resp := range rch { for resp := range rch {
for _, ev := range resp.Events { 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:] key := string(ev.Kv.Key)[plen:]
switch ev.Type { switch ev.Type {
case clientv3.EventTypePut: case clientv3.EventTypePut:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment