From 53f29dc721f9eca58cc796519698392cd0c56b18 Mon Sep 17 00:00:00 2001 From: Mike Spreitzer Date: Wed, 8 Jul 2020 01:15:51 -0400 Subject: [PATCH] Replaced repair with returning error, in delta_fifo.go When dedupDeltas does the impossible and the key is already queued, return an error rather than maintain the data structure invariants. Kubernetes-commit: a39481a4f6cf33f9bf4555adcffa28077863e7a9 --- tools/cache/delta_fifo.go | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/tools/cache/delta_fifo.go b/tools/cache/delta_fifo.go index 37e17717..148b478d 100644 --- a/tools/cache/delta_fifo.go +++ b/tools/cache/delta_fifo.go @@ -395,9 +395,9 @@ func (f *DeltaFIFO) queueActionLocked(actionType DeltaType, obj interface{}) err klog.Errorf("Impossible dedupDeltas for id=%q: oldDeltas=%#+v, obj=%#+v; ignoring", id, oldDeltas, obj) return nil } - klog.Errorf("Impossible dedupDeltas for id=%q: oldDeltas=%#+v, obj=%#+v; removing from queue", id, oldDeltas, obj) + klog.Errorf("Impossible dedupDeltas for id=%q: oldDeltas=%#+v, obj=%#+v; breaking invariant by storing empty Deltas", id, oldDeltas, obj) f.items[id] = newDeltas - f.filterQueueLocked() + return fmt.Errorf("Impossible dedupDeltas for id=%q: oldDeltas=%#+v, obj=%#+v; broke DeltaFIFO invariant by storing empty Deltas", id, oldDeltas, obj) } return nil } @@ -656,35 +656,6 @@ func (f *DeltaFIFO) syncKeyLocked(key string) error { return nil } -// A partial repair function. Removes keys from f.queue that -// correspond to nothing in f.items. Removes keys from both when the -// entry in f.items has zero length. Ensures each key appears at most -// once in queue. Must be called with the lock held. -func (f *DeltaFIFO) filterQueueLocked() { - newQueue := make([]string, 0, len(f.queue)) - newItems := make(map[string]Deltas, len(f.items)) - for _, key := range f.queue { - if _, exists := newItems[key]; exists { - klog.Errorf("Removing duplicate key %q", key) - continue - } - deltas, exists := f.items[key] - if !exists { - klog.Errorf("Removing key %q because it has no Deltas", key) - continue - } - if len(deltas) == 0 { - klog.Errorf("Removing key %q because it has zero-length Deltas", key) - continue - } - newQueue = append(newQueue, key) - newItems[key] = deltas - } - klog.Info("Finished repair of queue") - f.queue = newQueue - f.items = newItems -} - // A KeyListerGetter is anything that knows how to list its keys and look up by key. type KeyListerGetter interface { KeyLister