Skip to content

Commit

Permalink
fix #1: using PreKv replace Kv when recieve delete event
Browse files Browse the repository at this point in the history
  • Loading branch information
WSL committed Sep 5, 2018
1 parent 42e9c1d commit 863b1d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func main() {
panic(err)
}

ticker := time.NewTicker(100 * time.Millisecond)
ticker := time.NewTicker(1000 * time.Millisecond)
for t := range ticker.C {
client := pb.NewGreeterClient(conn)
resp, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "world " + strconv.Itoa(t.Second())})
Expand Down
4 changes: 2 additions & 2 deletions etcdv3/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ func (w *watcher) Next() ([]*naming.Update, error) {

// generate etcd Watcher
ctx, cancel := context.WithCancel(context.Background())
rch := w.client.Watch(ctx, prefix, etcd3.WithPrefix())
rch := w.client.Watch(ctx, prefix, etcd3.WithPrefix(), etcd3.WithPrevKV())
defer cancel()
for wresp := range rch {
for _, ev := range wresp.Events {
switch ev.Type {
case mvccpb.PUT:
return []*naming.Update{{Op: naming.Add, Addr: string(ev.Kv.Value)}}, nil
case mvccpb.DELETE:
return []*naming.Update{{Op: naming.Delete, Addr: string(ev.Kv.Value)}}, nil
return []*naming.Update{{Op: naming.Delete, Addr: string(ev.PrevKv.Value)}}, nil
}
}
}
Expand Down

0 comments on commit 863b1d1

Please sign in to comment.