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
Ensure that initial events are sorted for WatchList #120897
Ensure that initial events are sorted for WatchList #120897
Conversation
/assign @p0lyn0mial |
/retest |
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.
/lgtm
for the interval changes.
/hold
for further review.
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: MadhavJivrajani, wojtek-t The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
LGTM label has been added. Git tree hash: 4a09b2510c8147dbb60218c149a06c24fa1eef88
|
/triage accepted |
@@ -140,6 +155,7 @@ func newCacheIntervalFromStore(resourceVersion uint64, store cache.Indexer, getA | |||
} | |||
buffer.endIndex++ | |||
} | |||
sort.Sort(sortableWatchCacheEvents(buffer.buffer)) |
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.
nit: consider using the newer slices.Sort function, which runs faster.
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.
@wojtek-t mind checking if slices.Sort
is faster ?
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 see that it's not used anywhere in the codebase yet - we should do better analysis and migrate more if it appears better.
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.
ok, thanks.
fc83ad1
to
0b48036
Compare
} | ||
|
||
func (s sortableWatchCacheEvents) Less(i, j int) bool { | ||
return s[i].Key < s[j].Key |
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.
is key = namespace/name
?
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's the etcd key [that etcd is using to sort, as well as we're using elsewhere:
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apiserver/pkg/storage/cacher/watch_cache.go#L479-L491
]
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.
OK - I think I found it -
keyFunc := func(obj runtime.Object) (string, error) { |
func (s sortableWatchCacheEvents) Swap(i, j int) { | ||
s[i], s[j] = s[j], s[i] | ||
} | ||
|
||
// newCacheIntervalFromStore is meant to handle the case of rv=0, such that the events |
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.
nit: update the doc saying the output will be sorted.
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.
done
@@ -1264,22 +1264,22 @@ func RunWatchSemantics(ctx context.Context, t *testing.T, store storage.Interfac | |||
// after adding the initial pods which is then used to establish a new watch request | |||
useCurrentRV bool | |||
|
|||
// The test heavily relies on the fact that initialPods in created |
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.
what does it mean ?
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 think that after your change the tests should not rely on that, right ? Should we change the test cases so that we add some variation ?
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.
TBH - I completely can't remember why I added this...
Isn't it your PR that is doing that?
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 think you can remove the comment. Since the initial events are read from the map the result will always be random - unless we sort it which is exactly what this PR does. I updated/improved RunWatchSemanticInitialEventsExtended
.
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.
done
0b48036
to
c52e76b
Compare
c52e76b
to
92bdc7b
Compare
/hold cancel |
/lgtm |
LGTM label has been added. Git tree hash: 37104cba1d7524979cf7b99eebd23f14f754e4bd
|
Ref kubernetes/enhancements#3157
/kind feature
/priority important-longterm
/sig api-machinery