Skip to content

Commit d063192

Browse files
wojtek-tk8s-publishing-bot
authored andcommitted
Don't sort under lock
Kubernetes-commit: f6072e0d73dcb33edd3f2b1e656bb6d0cf81f9f0
1 parent 422a5da commit d063192

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

pkg/storage/cacher/watch_cache.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -492,21 +492,22 @@ func (s sortableStoreElements) Swap(i, j int) {
492492

493493
// WaitUntilFreshAndList returns list of pointers to `storeElement` objects along
494494
// with their ResourceVersion and the name of the index, if any, that was used.
495-
func (w *watchCache) WaitUntilFreshAndList(ctx context.Context, resourceVersion uint64, matchValues []storage.MatchValue) ([]interface{}, uint64, string, error) {
496-
var err error
495+
func (w *watchCache) WaitUntilFreshAndList(ctx context.Context, resourceVersion uint64, matchValues []storage.MatchValue) (result []interface{}, rv uint64, index string, err error) {
497496
if utilfeature.DefaultFeatureGate.Enabled(features.ConsistentListFromCache) && w.notFresh(resourceVersion) {
498497
w.waitingUntilFresh.Add()
499498
err = w.waitUntilFreshAndBlock(ctx, resourceVersion)
500499
w.waitingUntilFresh.Remove()
501500
} else {
502501
err = w.waitUntilFreshAndBlock(ctx, resourceVersion)
503502
}
503+
504+
defer func() { sort.Sort(sortableStoreElements(result)) }()
504505
defer w.RUnlock()
505506
if err != nil {
506-
return nil, 0, "", err
507+
return result, rv, index, err
507508
}
508509

509-
result, rv, index, err := func() ([]interface{}, uint64, string, error) {
510+
result, rv, index, err = func() ([]interface{}, uint64, string, error) {
510511
// This isn't the place where we do "final filtering" - only some "prefiltering" is happening here. So the only
511512
// requirement here is to NOT miss anything that should be returned. We can return as many non-matching items as we
512513
// want - they will be filtered out later. The fact that we return less things is only further performance improvement.
@@ -519,7 +520,6 @@ func (w *watchCache) WaitUntilFreshAndList(ctx context.Context, resourceVersion
519520
return w.store.List(), w.resourceVersion, "", nil
520521
}()
521522

522-
sort.Sort(sortableStoreElements(result))
523523
return result, rv, index, err
524524
}
525525

0 commit comments

Comments
 (0)