mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #81148 from wgliang/bugfix/scheduler-heap-race
Fix two race issues in schedule_queue
This commit is contained in:
commit
8c6c94bad2
@ -100,10 +100,10 @@ var highPriorityPod, highPriNominatedPod, medPriorityPod, unschedulablePod = v1.
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func addOrUpdateUnschedulablePod(p *PriorityQueue, pod *v1.Pod) {
|
func addOrUpdateUnschedulablePod(p *PriorityQueue, podInfo *framework.PodInfo) {
|
||||||
p.lock.Lock()
|
p.lock.Lock()
|
||||||
defer p.lock.Unlock()
|
defer p.lock.Unlock()
|
||||||
p.unschedulableQ.addOrUpdate(p.newPodInfo(pod))
|
p.unschedulableQ.addOrUpdate(podInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUnschedulablePod(p *PriorityQueue, pod *v1.Pod) *v1.Pod {
|
func getUnschedulablePod(p *PriorityQueue, pod *v1.Pod) *v1.Pod {
|
||||||
@ -235,7 +235,7 @@ func TestPriorityQueue_AddWithReversePriorityLessFunc(t *testing.T) {
|
|||||||
|
|
||||||
func TestPriorityQueue_AddIfNotPresent(t *testing.T) {
|
func TestPriorityQueue_AddIfNotPresent(t *testing.T) {
|
||||||
q := NewPriorityQueue(nil, nil)
|
q := NewPriorityQueue(nil, nil)
|
||||||
addOrUpdateUnschedulablePod(q, &highPriNominatedPod)
|
addOrUpdateUnschedulablePod(q, q.newPodInfo(&highPriNominatedPod))
|
||||||
q.AddIfNotPresent(&highPriNominatedPod) // Must not add anything.
|
q.AddIfNotPresent(&highPriNominatedPod) // Must not add anything.
|
||||||
q.AddIfNotPresent(&medPriorityPod)
|
q.AddIfNotPresent(&medPriorityPod)
|
||||||
q.AddIfNotPresent(&unschedulablePod)
|
q.AddIfNotPresent(&unschedulablePod)
|
||||||
@ -353,6 +353,7 @@ func TestPriorityQueue_AddUnschedulableIfNotPresent_Backoff(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q.lock.RLock()
|
||||||
// Since there was a move request at the same cycle as "oldCycle", these pods
|
// Since there was a move request at the same cycle as "oldCycle", these pods
|
||||||
// should be in the backoff queue.
|
// should be in the backoff queue.
|
||||||
for i := 1; i < totalNum; i++ {
|
for i := 1; i < totalNum; i++ {
|
||||||
@ -360,6 +361,7 @@ func TestPriorityQueue_AddUnschedulableIfNotPresent_Backoff(t *testing.T) {
|
|||||||
t.Errorf("Expected %v to be added to podBackoffQ.", expectedPods[i].Name)
|
t.Errorf("Expected %v to be added to podBackoffQ.", expectedPods[i].Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
q.lock.RUnlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPriorityQueue_Pop(t *testing.T) {
|
func TestPriorityQueue_Pop(t *testing.T) {
|
||||||
@ -442,8 +444,8 @@ func TestPriorityQueue_Delete(t *testing.T) {
|
|||||||
func TestPriorityQueue_MoveAllToActiveQueue(t *testing.T) {
|
func TestPriorityQueue_MoveAllToActiveQueue(t *testing.T) {
|
||||||
q := NewPriorityQueue(nil, nil)
|
q := NewPriorityQueue(nil, nil)
|
||||||
q.Add(&medPriorityPod)
|
q.Add(&medPriorityPod)
|
||||||
addOrUpdateUnschedulablePod(q, &unschedulablePod)
|
addOrUpdateUnschedulablePod(q, q.newPodInfo(&unschedulablePod))
|
||||||
addOrUpdateUnschedulablePod(q, &highPriorityPod)
|
addOrUpdateUnschedulablePod(q, q.newPodInfo(&highPriorityPod))
|
||||||
q.MoveAllToActiveQueue()
|
q.MoveAllToActiveQueue()
|
||||||
if q.activeQ.Len() != 3 {
|
if q.activeQ.Len() != 3 {
|
||||||
t.Error("Expected all items to be in activeQ.")
|
t.Error("Expected all items to be in activeQ.")
|
||||||
@ -489,8 +491,8 @@ func TestPriorityQueue_AssignedPodAdded(t *testing.T) {
|
|||||||
q := NewPriorityQueue(nil, nil)
|
q := NewPriorityQueue(nil, nil)
|
||||||
q.Add(&medPriorityPod)
|
q.Add(&medPriorityPod)
|
||||||
// Add a couple of pods to the unschedulableQ.
|
// Add a couple of pods to the unschedulableQ.
|
||||||
addOrUpdateUnschedulablePod(q, &unschedulablePod)
|
addOrUpdateUnschedulablePod(q, q.newPodInfo(&unschedulablePod))
|
||||||
addOrUpdateUnschedulablePod(q, affinityPod)
|
addOrUpdateUnschedulablePod(q, q.newPodInfo(affinityPod))
|
||||||
// Simulate addition of an assigned pod. The pod has matching labels for
|
// Simulate addition of an assigned pod. The pod has matching labels for
|
||||||
// affinityPod. So, affinityPod should go to activeQ.
|
// affinityPod. So, affinityPod should go to activeQ.
|
||||||
q.AssignedPodAdded(&labelPod)
|
q.AssignedPodAdded(&labelPod)
|
||||||
@ -534,8 +536,8 @@ func TestPriorityQueue_PendingPods(t *testing.T) {
|
|||||||
|
|
||||||
q := NewPriorityQueue(nil, nil)
|
q := NewPriorityQueue(nil, nil)
|
||||||
q.Add(&medPriorityPod)
|
q.Add(&medPriorityPod)
|
||||||
addOrUpdateUnschedulablePod(q, &unschedulablePod)
|
addOrUpdateUnschedulablePod(q, q.newPodInfo(&unschedulablePod))
|
||||||
addOrUpdateUnschedulablePod(q, &highPriorityPod)
|
addOrUpdateUnschedulablePod(q, q.newPodInfo(&highPriorityPod))
|
||||||
expectedSet := makeSet([]*v1.Pod{&medPriorityPod, &unschedulablePod, &highPriorityPod})
|
expectedSet := makeSet([]*v1.Pod{&medPriorityPod, &unschedulablePod, &highPriorityPod})
|
||||||
if !reflect.DeepEqual(expectedSet, makeSet(q.PendingPods())) {
|
if !reflect.DeepEqual(expectedSet, makeSet(q.PendingPods())) {
|
||||||
t.Error("Unexpected list of pending Pods.")
|
t.Error("Unexpected list of pending Pods.")
|
||||||
@ -1055,10 +1057,12 @@ func TestHighPriorityFlushUnschedulableQLeftover(t *testing.T) {
|
|||||||
Message: "fake scheduling failure",
|
Message: "fake scheduling failure",
|
||||||
})
|
})
|
||||||
|
|
||||||
addOrUpdateUnschedulablePod(q, &highPod)
|
highPodInfo := q.newPodInfo(&highPod)
|
||||||
addOrUpdateUnschedulablePod(q, &midPod)
|
highPodInfo.Timestamp = time.Now().Add(-1 * unschedulableQTimeInterval)
|
||||||
q.unschedulableQ.podInfoMap[util.GetPodFullName(&highPod)].Timestamp = time.Now().Add(-1 * unschedulableQTimeInterval)
|
midPodInfo := q.newPodInfo(&midPod)
|
||||||
q.unschedulableQ.podInfoMap[util.GetPodFullName(&midPod)].Timestamp = time.Now().Add(-1 * unschedulableQTimeInterval)
|
midPodInfo.Timestamp = time.Now().Add(-1 * unschedulableQTimeInterval)
|
||||||
|
addOrUpdateUnschedulablePod(q, highPodInfo)
|
||||||
|
addOrUpdateUnschedulablePod(q, midPodInfo)
|
||||||
|
|
||||||
if p, err := q.Pop(); err != nil || p != &highPod {
|
if p, err := q.Pop(); err != nil || p != &highPod {
|
||||||
t.Errorf("Expected: %v after Pop, but got: %v", highPriorityPod.Name, p.Name)
|
t.Errorf("Expected: %v after Pop, but got: %v", highPriorityPod.Name, p.Name)
|
||||||
|
Loading…
Reference in New Issue
Block a user