grpcproxy: handle create event

This commit is contained in:
Xiang Li 2016-08-02 20:51:30 -07:00
parent c30a436829
commit 57c68ab1db
4 changed files with 10 additions and 15 deletions

View File

@ -92,7 +92,7 @@ func (wr *WatchResponse) Err() error {
// IsProgressNotify returns true if the WatchResponse is progress notification. // IsProgressNotify returns true if the WatchResponse is progress notification.
func (wr *WatchResponse) IsProgressNotify() bool { func (wr *WatchResponse) IsProgressNotify() bool {
return len(wr.Events) == 0 && !wr.Canceled return len(wr.Events) == 0 && !wr.Canceled && !wr.Created
} }
// watcher implements the Watcher interface // watcher implements the Watcher interface

View File

@ -123,19 +123,7 @@ func (sws *serverWatchStream) recvLoop() error {
} else { } else {
sws.addCoalescedWatcher(watcher) sws.addCoalescedWatcher(watcher)
} }
wresp := &pb.WatchResponse{
Header: &pb.ResponseHeader{}, // TODO: fill in header
WatchId: sws.nextWatcherID,
Created: true,
}
sws.nextWatcherID++ sws.nextWatcherID++
select {
case sws.ctrlCh <- wresp:
default:
panic("handle this")
}
case *pb.WatchRequest_CancelRequest: case *pb.WatchRequest_CancelRequest:
sws.removeWatcher(uv.CancelRequest.WatchId) sws.removeWatcher(uv.CancelRequest.WatchId)
@ -185,6 +173,7 @@ func (sws *serverWatchStream) addDedicatedWatcher(w watcher, rev int64) {
w.wr.key, clientv3.WithRange(w.wr.end), w.wr.key, clientv3.WithRange(w.wr.end),
clientv3.WithRev(rev), clientv3.WithRev(rev),
clientv3.WithProgressNotify(), clientv3.WithProgressNotify(),
clientv3.WithCreatedNotify(),
) )
ws := newWatcherSingle(wch, cancel, w, sws) ws := newWatcherSingle(wch, cancel, w, sws)

View File

@ -66,12 +66,13 @@ func (w *watcher) send(wr clientv3.WatchResponse) {
} }
// all events are filtered out? // all events are filtered out?
if !wr.IsProgressNotify() && len(events) == 0 { if !wr.IsProgressNotify() && !wr.Created && len(events) == 0 {
return return
} }
pbwr := &pb.WatchResponse{ pbwr := &pb.WatchResponse{
Header: &wr.Header, Header: &wr.Header,
Created: wr.Created,
WatchId: w.id, WatchId: w.id,
Events: events, Events: events,
} }

View File

@ -42,7 +42,12 @@ func (wgs *watchergroups) addWatcher(rid receiverID, w watcher) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
wch := wgs.cw.Watch(ctx, w.wr.key, clientv3.WithRange(w.wr.end), clientv3.WithProgressNotify()) wch := wgs.cw.Watch(ctx, w.wr.key,
clientv3.WithRange(w.wr.end),
clientv3.WithProgressNotify(),
clientv3.WithCreatedNotify(),
)
watchg := newWatchergroup(wch, cancel) watchg := newWatchergroup(wch, cancel)
watchg.add(rid, w) watchg.add(rid, w)
go watchg.run() go watchg.run()