Skip to content
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

Add verification to ensure the watch events are in the expected range #18980

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions server/storage/mvcc/watchable_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
package mvcc

import (
"fmt"
"sync"
"time"

"go.uber.org/zap"

"go.etcd.io/etcd/api/v3/mvccpb"
"go.etcd.io/etcd/client/pkg/v3/verify"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/pkg/v3/traceutil"
"go.etcd.io/etcd/server/v3/lease"
Expand Down Expand Up @@ -372,6 +374,17 @@
// Otherwise we will trigger SIGSEGV during boltdb re-mmap.
tx.RUnlock()

verify.Verify(func() {
Copy link
Member

@serathius serathius Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This just tests the results of range over revisions, this kind of things should be validated in tests, not during e2e tests.
I think the discussion in #17563 (comment) was about curRev decreasing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have a couple of verifications to ensure the revision will never decrease.

This verification is only to ensure the watch events are in the expected range.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We introduce verification for non-trivial properties that are based on state that is changed in so many places that it's impossible to test them in isolated way. In this case you are just validating range that is defined via minBytes and maxBytes variable 10 lines above. Would a unit test be a better match?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example b52ee3b

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge #18981

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It mainly verifies the keys(revisions) read from bbolt are in the expected range. We might should do it in bbolt instead of etcd.

if len(evs) == 0 {
return
}
nCount := len(evs)
if evs[0].Kv.ModRevision < minRev || evs[nCount-1].Kv.ModRevision > curRev {
panic(fmt.Errorf("watch events are out of range, expected: [%d, %d], but got evs[0].Kv.ModRevision: %d, evs[%d].Kv.ModRevision: %d",
minRev, curRev, evs[0].Kv.ModRevision, nCount-1, evs[nCount-1].Kv.ModRevision))

Check warning on line 384 in server/storage/mvcc/watchable_store.go

View check run for this annotation

Codecov / codecov/patch

server/storage/mvcc/watchable_store.go#L383-L384

Added lines #L383 - L384 were not covered by tests
}
})

victims := make(watcherBatch)
wb := newWatcherBatch(wg, evs)
for w := range wg.watchers {
Expand Down