-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix watch event loss #17555
Merged
Merged
Fix watch event loss #17555
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,20 +17,25 @@ package integration | |
import ( | ||
"bytes" | ||
"context" | ||
"errors" | ||
"fmt" | ||
"reflect" | ||
"sort" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
pb "go.etcd.io/etcd/api/v3/etcdserverpb" | ||
"go.etcd.io/etcd/api/v3/mvccpb" | ||
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
"go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc" | ||
"go.etcd.io/etcd/server/v3/storage/mvcc" | ||
"go.etcd.io/etcd/tests/v3/framework/integration" | ||
gofail "go.etcd.io/gofail/runtime" | ||
) | ||
|
||
// TestV3WatchFromCurrentRevision tests Watch APIs from current revision. | ||
|
@@ -1512,3 +1517,56 @@ func TestV3WatchProgressWaitsForSyncNoEvents(t *testing.T) { | |
} | ||
require.True(t, gotProgressNotification, "Expected to get progress notification") | ||
} | ||
|
||
// TestV3NoEventsLostOnCompact verifies that slow watchers exit with compacted watch response | ||
// if its next revision of events are compacted and no lost events sent to client. | ||
func TestV3NoEventsLostOnCompact(t *testing.T) { | ||
if integration.ThroughProxy { | ||
t.Skip("grpc proxy currently does not support requesting progress notifications") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't think this comment is relevant. |
||
} | ||
integration.BeforeTest(t) | ||
if len(gofail.List()) == 0 { | ||
t.Skip("please run 'make gofail-enable' before running the test") | ||
} | ||
clus := integration.NewCluster(t, &integration.ClusterConfig{Size: 1}) | ||
defer clus.Terminate(t) | ||
|
||
client := clus.RandClient() | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
||
// sendLoop throughput is rate-limited to 1 event per second | ||
require.NoError(t, gofail.Enable("beforeSendWatchResponse", `sleep("1s")`)) | ||
wch := client.Watch(ctx, "foo") | ||
|
||
var rev int64 | ||
writeCount := mvcc.ChanBufLen() * 11 / 10 | ||
for i := 0; i < writeCount; i++ { | ||
resp, err := client.Put(ctx, "foo", "bar") | ||
require.NoError(t, err) | ||
rev = resp.Header.Revision | ||
} | ||
_, err := client.Compact(ctx, rev) | ||
require.NoError(t, err) | ||
|
||
time.Sleep(time.Second) | ||
require.NoError(t, gofail.Disable("beforeSendWatchResponse")) | ||
|
||
eventCount := 0 | ||
compacted := false | ||
for resp := range wch { | ||
err = resp.Err() | ||
if err != nil { | ||
if !errors.Is(err, rpctypes.ErrCompacted) { | ||
t.Fatalf("want watch response err %v but got %v", rpctypes.ErrCompacted, err) | ||
} | ||
compacted = true | ||
break | ||
} | ||
eventCount += len(resp.Events) | ||
if eventCount == writeCount { | ||
break | ||
} | ||
} | ||
assert.Truef(t, compacted, "Expected stream to get compacted, instead we got %d events out of %d events", eventCount, writeCount) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how relevant is maxWatchersPerSync to the issue and this test as
len(watchers) < 4
.What about the case where
len(watchers) > maxWatchersPerSync
as pointed out in #17555 (comment) ? I haven't verified it, but I expect that unremoved watcher froms.unsynced
will causesyncWatchers
to return != 0, causing function to be called earlier.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be true. Confirmed that it always runs into the if branch (see below), and confirmed that it has no any impact on the test case.
But it isn't a big deal, and also from another prospective it should be OK to explicitly set a value to ensure
len(wg.watchers) < maxWatchers
although it's alreadytrue
by default.etcd/server/storage/mvcc/watcher_group.go
Lines 225 to 227 in 63e394d
Suggest to discuss & fix it separately. We may want to do minor local code refactor. @chaochn47 are you able to continue to work on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean that the even I don't change
maxWatchersPerSync
in the test case , the test case could also reproduce the issue without the fix and the issue disappeared after applying the patch in this PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good