Merge pull request #6849 from heyitsanthony/proxy-fix-watch-create
grpcproxy: don't send extra watch create eventsrelease-3.1
commit
d073512def
|
@ -54,13 +54,20 @@ func newWatchBroadcast(wp *watchProxy, w *watcher, update func(*watchBroadcast))
|
||||||
defer close(wb.donec)
|
defer close(wb.donec)
|
||||||
// loop because leader loss will close channel
|
// loop because leader loss will close channel
|
||||||
for cctx.Err() == nil {
|
for cctx.Err() == nil {
|
||||||
wch := wp.cw.Watch(cctx, w.wr.key,
|
opts := []clientv3.OpOption{
|
||||||
clientv3.WithRange(w.wr.end),
|
clientv3.WithRange(w.wr.end),
|
||||||
clientv3.WithProgressNotify(),
|
clientv3.WithProgressNotify(),
|
||||||
clientv3.WithCreatedNotify(),
|
|
||||||
clientv3.WithRev(wb.nextrev),
|
clientv3.WithRev(wb.nextrev),
|
||||||
clientv3.WithPrevKV(),
|
clientv3.WithPrevKV(),
|
||||||
)
|
}
|
||||||
|
// The create notification should be the first response;
|
||||||
|
// if the watch is recreated following leader loss, it
|
||||||
|
// shouldn't post a second create response to the client.
|
||||||
|
if wb.responses == 0 {
|
||||||
|
opts = append(opts, clientv3.WithCreatedNotify())
|
||||||
|
}
|
||||||
|
wch := wp.cw.Watch(cctx, w.wr.key, opts...)
|
||||||
|
|
||||||
for wr := range wch {
|
for wr := range wch {
|
||||||
wb.bcast(wr)
|
wb.bcast(wr)
|
||||||
update(wb)
|
update(wb)
|
||||||
|
|
|
@ -60,8 +60,10 @@ func (wbs *watchBroadcasts) coalesce(wb *watchBroadcast) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
wbswb.mu.Lock()
|
wbswb.mu.Lock()
|
||||||
// NB: victim lock already held
|
// 1. check if wbswb is behind wb so it won't skip any events in wb
|
||||||
if wb.nextrev >= wbswb.nextrev && wbswb.nextrev != 0 {
|
// 2. ensure wbswb started; nextrev == 0 may mean wbswb is waiting
|
||||||
|
// for a current watcher and expects a create event from the server.
|
||||||
|
if wb.nextrev >= wbswb.nextrev && wbswb.responses > 0 {
|
||||||
for w := range wb.receivers {
|
for w := range wb.receivers {
|
||||||
wbswb.receivers[w] = struct{}{}
|
wbswb.receivers[w] = struct{}{}
|
||||||
wbs.watchers[w] = wbswb
|
wbs.watchers[w] = wbswb
|
||||||
|
|
Loading…
Reference in New Issue