Replace will delete the contents of 'f', using instead the given map. 'f' takes ownership of the map, you should not reference the map again after calling this function. f's queue is reset, too; upon return, it will contain the items in the map, in no particular order.
(list []interface{}, resourceVersion string)
| 449 | // after calling this function. f's queue is reset, too; upon return, it |
| 450 | // will contain the items in the map, in no particular order. |
| 451 | func (f *DeltaFIFO) Replace(list []interface{}, resourceVersion string) error { |
| 452 | f.lock.Lock() |
| 453 | defer f.lock.Unlock() |
| 454 | keys := make(sets.String, len(list)) |
| 455 | |
| 456 | for _, item := range list { |
| 457 | key, err := f.KeyOf(item) |
| 458 | if err != nil { |
| 459 | return KeyError{item, err} |
| 460 | } |
| 461 | keys.Insert(key) |
| 462 | if err := f.queueActionLocked(Sync, item); err != nil { |
| 463 | return fmt.Errorf("couldn't enqueue object: %v", err) |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | if f.knownObjects == nil { |
| 468 | // Do deletion detection against our own list. |
| 469 | queuedDeletions := 0 |
| 470 | for k, oldItem := range f.items { |
| 471 | if keys.Has(k) { |
| 472 | continue |
| 473 | } |
| 474 | var deletedObj interface{} |
| 475 | if n := oldItem.Newest(); n != nil { |
| 476 | deletedObj = n.Object |
| 477 | } |
| 478 | queuedDeletions++ |
| 479 | if err := f.queueActionLocked(Deleted, DeletedFinalStateUnknown{k, deletedObj}); err != nil { |
| 480 | return err |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | if !f.populated { |
| 485 | f.populated = true |
| 486 | // While there shouldn't be any queued deletions in the initial |
| 487 | // population of the queue, it's better to be on the safe side. |
| 488 | f.initialPopulationCount = len(list) + queuedDeletions |
| 489 | } |
| 490 | |
| 491 | return nil |
| 492 | } |
| 493 | |
| 494 | // Detect deletions not already in the queue. |
| 495 | knownKeys := f.knownObjects.ListKeys() |
| 496 | queuedDeletions := 0 |
| 497 | for _, k := range knownKeys { |
| 498 | if keys.Has(k) { |
| 499 | continue |
| 500 | } |
| 501 | |
| 502 | deletedObj, exists, err := f.knownObjects.GetByKey(k) |
| 503 | if err != nil { |
| 504 | deletedObj = nil |
| 505 | klog.Errorf("Unexpected error %v during lookup of key %v, placing DeleteFinalStateUnknown marker without object", err, k) |
| 506 | } else if !exists { |
| 507 | deletedObj = nil |
| 508 | klog.Infof("Key %v does not exist in known objects store, placing DeleteFinalStateUnknown marker without object", k) |