mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-18 04:54:54 +00:00
Refactor delta addition/clearing
This commit is contained in:
@@ -282,6 +282,11 @@ func (f *RealFIFO) PopBatch(process ProcessBatchFunc) error {
|
||||
isInInitialList := !f.hasSynced_locked()
|
||||
unique := sets.NewString()
|
||||
deltas := make([]Delta, 0, min(len(f.items), f.batchSize))
|
||||
moveDeltaToProcessList := func(i int) {
|
||||
deltas = append(deltas, f.items[i])
|
||||
// The underlying array still exists and references this object, so the object will not be garbage collected unless we zero the reference.
|
||||
f.items[i] = Delta{}
|
||||
}
|
||||
// only bundle unique items into a batch
|
||||
for i := 0; i < f.batchSize && i < len(f.items); i++ {
|
||||
if f.initialPopulationCount > 0 && i >= f.initialPopulationCount {
|
||||
@@ -295,18 +300,14 @@ func (f *RealFIFO) PopBatch(process ProcessBatchFunc) error {
|
||||
// still pop the broken item out of queue to be compatible with the non-batch behavior it should be safe
|
||||
// when 1st element is broken, however for Nth broken element, there's possible risk that broken item
|
||||
// still can be processed and broke the uniqueness of the batch unexpectedly.
|
||||
deltas = append(deltas, item)
|
||||
// The underlying array still exists and references this object, so the object will not be garbage collected unless we zero the reference.
|
||||
f.items[i] = Delta{}
|
||||
moveDeltaToProcessList(i)
|
||||
break
|
||||
}
|
||||
if unique.Has(id) {
|
||||
break
|
||||
}
|
||||
unique.Insert(id)
|
||||
deltas = append(deltas, item)
|
||||
// The underlying array still exists and references this object, so the object will not be garbage collected unless we zero the reference.
|
||||
f.items[i] = Delta{}
|
||||
moveDeltaToProcessList(i)
|
||||
}
|
||||
if f.initialPopulationCount > 0 {
|
||||
f.initialPopulationCount -= len(deltas)
|
||||
|
||||
Reference in New Issue
Block a user