You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@yunikorn.apache.org by ma...@apache.org on 2026/10/28 12:41:58 UTC

(yunikorn-core) branch master updated: [YUNIKORN-3515] Fix multi-application victim overwrite and ghost notifications in quota preemption (#1193)

This is an automated email from the ASF dual-hosted git repository.

manirajv06 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/yunikorn-core.git


The following commit(s) were added to refs/heads/master by this push:
     new d60b3417 [YUNIKORN-3515] Fix multi-application victim overwrite and ghost notifications in quota preemption (#1193)
d60b3417 is described below

commit d60b3417e2747cf89497d5b7e47c3007a4e3f8bd
Author: hedger9487 <he...@gmail.com>
AuthorDate: Wed Oct 28 18:10:22 2026 +0530

    [YUNIKORN-3515] Fix multi-application victim overwrite and ghost notifications in quota preemption (#1193)
    
    Closes: #1193
    
    Signed-off-by: mani <ma...@gmail.com>
---
 pkg/scheduler/objects/quota_preemptor.go      | 14 +++--
 pkg/scheduler/objects/quota_preemptor_test.go | 80 ++++++++++++++++++++++++++-
 2 files changed, 88 insertions(+), 6 deletions(-)

diff --git a/pkg/scheduler/objects/quota_preemptor.go b/pkg/scheduler/objects/quota_preemptor.go
index 37a66bc4..897da693 100644
--- a/pkg/scheduler/objects/quota_preemptor.go
+++ b/pkg/scheduler/objects/quota_preemptor.go
@@ -341,12 +341,11 @@ func (qpc *QuotaPreemptionContext) preemptVictims() {
 
 	for app, victims := range apps {
 		if len(victims) > 0 {
-			qpc.results.claimedResource = victimsTotalResource
-			qpc.results.preemptedVictims = victims
+			var releasedVictims []*Allocation
 			for _, victim := range victims {
 				err := victim.MarkPreempted()
 				if err != nil {
-					log.Log(log.SchedRequiredNodePreemption).Warn("allocation is already released, ignoring in quota preemption process",
+					log.Log(log.SchedQuotaChangePreemption).Warn("allocation is already released, ignoring in quota preemption process",
 						zap.String("applicationID", victim.GetApplicationID()),
 						zap.String("allocationKey", victim.GetAllocationKey()))
 					continue
@@ -359,9 +358,14 @@ func (qpc *QuotaPreemptionContext) preemptVictims() {
 					zap.String("nodeID", victim.GetNodeID()))
 				qpc.queue.IncPreemptingResource(victim.GetAllocatedResource())
 				victim.SendPreemptedByQuotaChangeEvent(qpc.queue.GetQueuePath())
+				releasedVictims = append(releasedVictims, victim)
+				qpc.results.claimedResource = resources.Add(qpc.results.claimedResource, victim.GetAllocatedResource())
+			}
+			if len(releasedVictims) > 0 {
+				qpc.results.preemptedVictims = append(qpc.results.preemptedVictims, releasedVictims...)
+				app.notifyRMAllocationReleased(releasedVictims, si.TerminationType_PREEMPTED_BY_SCHEDULER,
+					"preempting allocations to enforce new max quota for queue : "+qpc.queue.GetQueuePath())
 			}
-			app.notifyRMAllocationReleased(victims, si.TerminationType_PREEMPTED_BY_SCHEDULER,
-				"preempting allocations to enforce new max quota for queue : "+qpc.queue.GetQueuePath())
 		}
 	}
 }
diff --git a/pkg/scheduler/objects/quota_preemptor_test.go b/pkg/scheduler/objects/quota_preemptor_test.go
index d4b3bba1..643757b6 100644
--- a/pkg/scheduler/objects/quota_preemptor_test.go
+++ b/pkg/scheduler/objects/quota_preemptor_test.go
@@ -790,9 +790,87 @@ func createQueueSetups(t *testing.T, parent *Queue, leafResG configs.Resources,
 }
 
 func createVictim(t *testing.T, allocKey string, node *Node, adjustment int, allocRes *resources.Resource) *Allocation {
+	return createVictimForApp(t, allocKey, "app1", node, adjustment, allocRes)
+}
+
+func createVictimForApp(t *testing.T, allocKey string, appID string, node *Node, adjustment int, allocRes *resources.Resource) *Allocation {
 	baseTime := time.Now().Truncate(time.Hour).Add(30 * time.Minute)
-	allocation := createAllocation(allocKey, "app1", node.NodeID, true, false, 10, false, allocRes)
+	allocation := createAllocation(allocKey, appID, node.NodeID, true, false, 10, false, allocRes)
 	allocation.createTime = baseTime.Add(-time.Minute * time.Duration(adjustment))
 	assert.Assert(t, node.TryAddAllocation(allocation))
 	return allocation
 }
+
+func TestQuotaChangeTryPreemption_MultipleApplications(t *testing.T) {
+	events.Init()
+	eventSystem := events.GetEventSystem().(*events.EventSystemImpl) //nolint:errcheck
+	eventSystem.StartServiceWithPublisher(false)
+
+	testCases := []struct {
+		name                    string
+		releaseVictimKey        string
+		expectedPreemptedKeys   []string
+		expectedClaimedResource *resources.Resource
+	}{
+		{
+			name:                    "all valid victims across multiple apps",
+			releaseVictimKey:        "",
+			expectedPreemptedKeys:   []string{"alloc-app1-1", "alloc-app1-2", "alloc-app2-1"},
+			expectedClaimedResource: resources.NewResourceFromMap(map[string]resources.Quantity{"first": 30}),
+		},
+		{
+			name:                    "ignore already released victim in multi app preemption",
+			releaseVictimKey:        "alloc-app1-2",
+			expectedPreemptedKeys:   []string{"alloc-app1-1", "alloc-app2-1"},
+			expectedClaimedResource: resources.NewResourceFromMap(map[string]resources.Quantity{"first": 20}),
+		},
+	}
+
+	for _, tc := range testCases {
+		t.Run(tc.name, func(t *testing.T) {
+			node := NewNode(&si.NodeInfo{
+				NodeID: "node",
+				SchedulableResource: &si.Resource{
+					Resources: map[string]*si.Quantity{"first": {Value: 100}},
+				},
+			})
+			parent, err := NewConfiguredQueue(configs.QueueConfig{Name: "parent", Parent: true}, nil, false, nil)
+			assert.NilError(t, err)
+			leaf, err := NewConfiguredQueue(configs.QueueConfig{Name: "leaf"}, parent, false, nil)
+			assert.NilError(t, err)
+
+			allocRes := resources.NewResourceFromMap(map[string]resources.Quantity{"first": 10})
+			v1 := createVictimForApp(t, "alloc-app1-1", "app1", node, 5, allocRes)
+			v2 := createVictimForApp(t, "alloc-app1-2", "app1", node, 4, allocRes)
+			v3 := createVictimForApp(t, "alloc-app2-1", "app2", node, 3, allocRes)
+
+			leaf.maxResource = resources.NewResourceFromMap(map[string]resources.Quantity{"first": 50})
+			assignAllocationsToQueue(t, []*Allocation{v1, v2, v3}, leaf)
+
+			leaf.maxResource = resources.NewResourceFromMap(map[string]resources.Quantity{"first": 0})
+			leaf.guaranteedResource = resources.NewResourceFromMap(map[string]resources.Quantity{"first": 0})
+
+			preemptor := NewQuotaPreemptor(leaf)
+			preemptor.setPreemptableResources()
+			preemptor.allocations = []*Allocation{v1, v2, v3}
+
+			if tc.releaseVictimKey != "" {
+				for _, victim := range preemptor.allocations {
+					if victim.GetAllocationKey() == tc.releaseVictimKey {
+						assert.NilError(t, victim.SetReleased(true))
+					}
+				}
+			}
+
+			preemptor.preemptVictims()
+
+			assert.Equal(t, len(preemptor.results.preemptedVictims), len(tc.expectedPreemptedKeys))
+			assertPreemptedAllocationKeys(t, preemptor.results.preemptedVictims, tc.expectedPreemptedKeys)
+			assert.Assert(t, resources.Equals(preemptor.results.claimedResource, tc.expectedClaimedResource))
+
+			removeAllocationAsks(node, []*Allocation{v1, v2, v3})
+			resetQueue(parent)
+			_ = eventSystem.Store.CollectEvents()
+		})
+	}
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@yunikorn.apache.org
For additional commands, e-mail: issues-help@yunikorn.apache.org