Skip to content

Commit

Permalink
Fix progress notification on watch opened on the current revision tha…
Browse files Browse the repository at this point in the history
…t doesn't match watch range.

When implementing the fix for progress notifications
(etcd-io#15237) we made a incorrect
assumption that that unsynched watches will always get at least one event.

Unsynched watches include not only slow watchers, but also newly created
watches that requested old revision. In case that non of the events
match watch filter, those newly created watches might become synched
without any event going through.

Signed-off-by: Marek Siarkowicz <[email protected]>
  • Loading branch information
serathius committed Mar 8, 2024
1 parent a481256 commit 82dceab
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
20 changes: 1 addition & 19 deletions server/etcdserver/api/v3rpc/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ type serverWatchStream struct {
// records fragmented watch IDs
fragment map[mvcc.WatchID]bool

// indicates whether we have an outstanding global progress
// notification to send
deferredProgress bool

// closec indicates the stream is closed.
closec chan struct{}

Expand Down Expand Up @@ -178,8 +174,6 @@ func (ws *watchServer) Watch(stream pb.Watch_WatchServer) (err error) {
prevKV: make(map[mvcc.WatchID]bool),
fragment: make(map[mvcc.WatchID]bool),

deferredProgress: false,

closec: make(chan struct{}),
}

Expand Down Expand Up @@ -367,14 +361,7 @@ func (sws *serverWatchStream) recvLoop() error {
case *pb.WatchRequest_ProgressRequest:
if uv.ProgressRequest != nil {
sws.mu.Lock()
// Ignore if deferred progress notification is already in progress
if !sws.deferredProgress {
// Request progress for all watchers,
// force generation of a response
if !sws.watchStream.RequestProgressAll() {
sws.deferredProgress = true
}
}
sws.watchStream.RequestProgressAll()
sws.mu.Unlock()
}
default:
Expand Down Expand Up @@ -483,11 +470,6 @@ func (sws *serverWatchStream) sendLoop() {
// elide next progress update if sent a key update
sws.progress[wresp.WatchID] = false
}
if sws.deferredProgress {
if sws.watchStream.RequestProgressAll() {
sws.deferredProgress = false
}
}
sws.mu.Unlock()

case c, ok := <-sws.ctrlStream:
Expand Down
45 changes: 45 additions & 0 deletions tests/integration/v3_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1467,3 +1467,48 @@ func TestV3WatchProgressWaitsForSync(t *testing.T) {
t.Fatal("Wrong revision in progress notification!")
}
}

func TestV3WatchProgressForWatchOnCurrentRevision(t *testing.T) {
if integration.ThroughProxy {
t.Skip("grpc proxy currently does not support requesting progress notifications")
}
integration.BeforeTest(t)

clus := integration.NewCluster(t, &integration.ClusterConfig{Size: 1})
defer clus.Terminate(t)

client := clus.RandClient()
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()

resp, err := client.Put(ctx, "bar", "1")
require.NoError(t, err)

wch := client.Watch(ctx, "foo", clientv3.WithRev(resp.Header.Revision))
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()

err = client.RequestProgress(ctx)
require.NoError(t, err)
gotProgressNotification := false
for {
select {
case <-ticker.C:
err := client.RequestProgress(ctx)
require.NoError(t, err)
case resp := <-wch:
if resp.Err() != nil {
t.Fatal(fmt.Errorf("watch error: %w", resp.Err()))
}
if resp.IsProgressNotify() {
gotProgressNotification = true
}
}
if gotProgressNotification {
break
}
}
if !gotProgressNotification {
t.Fatal("Expected to get progress notification")
}
}

0 comments on commit 82dceab

Please sign in to comment.