|
|
|
@ -404,6 +404,7 @@ func isDeletionDup(a, b *Delta) *Delta {
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将新元素加入队列的方法,并且调用前要加锁。附带作用,填充了items
|
|
|
|
|
// queueActionLocked appends to the delta list for the object.
|
|
|
|
|
// Caller must lock first.
|
|
|
|
|
func (f *DeltaFIFO) queueActionLocked(actionType DeltaType, obj interface{}) error {
|
|
|
|
@ -573,10 +574,14 @@ func (f *DeltaFIFO) Pop(process PopProcessFunc) (interface{}, error) {
|
|
|
|
|
// are those listed by `f.knownObjects` and the current object of K is
|
|
|
|
|
// what `f.knownObjects.GetByKey(K)` returns.
|
|
|
|
|
func (f *DeltaFIFO) Replace(list []interface{}, _ string) error {
|
|
|
|
|
// 调用这个函数的时候时线程安全的
|
|
|
|
|
f.lock.Lock()
|
|
|
|
|
defer f.lock.Unlock()
|
|
|
|
|
|
|
|
|
|
// 注意keys的类型是一个集合
|
|
|
|
|
keys := make(sets.String, len(list))
|
|
|
|
|
|
|
|
|
|
// 是为了兼容考虑,并没有更多的意义
|
|
|
|
|
// keep backwards compat for old clients
|
|
|
|
|
action := Sync
|
|
|
|
|
if f.emitDeltaTypeReplaced {
|
|
|
|
@ -589,12 +594,16 @@ func (f *DeltaFIFO) Replace(list []interface{}, _ string) error {
|
|
|
|
|
if err != nil {
|
|
|
|
|
return KeyError{item, err}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
keys.Insert(key)
|
|
|
|
|
|
|
|
|
|
if err := f.queueActionLocked(action, item); err != nil {
|
|
|
|
|
return fmt.Errorf("couldn't enqueue object: %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 处理没有提供已知对象的方法集的情况
|
|
|
|
|
if f.knownObjects == nil {
|
|
|
|
|
// Do deletion detection against our own list.
|
|
|
|
|
queuedDeletions := 0
|
|
|
|
|