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/29 06:51:50 UTC

(yunikorn-core) branch master updated: [YUNIKORN-3530] Clear allocatingAcceptedApps on parent queues when an application is removed (#1201)

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 8a0f7536 [YUNIKORN-3530] Clear allocatingAcceptedApps on parent queues when an application is removed (#1201)
8a0f7536 is described below

commit 8a0f753695c2b1051dba33cf5d818da275990d61
Author: Eason Chen <18...@users.noreply.github.com>
AuthorDate: Thu Oct 29 12:18:53 2026 +0530

    [YUNIKORN-3530] Clear allocatingAcceptedApps on parent queues when an application is removed (#1201)
    
    Closes: #1201
    
    Signed-off-by: mani <ma...@gmail.com>
---
 pkg/scheduler/objects/queue.go      | 17 ++++++++++-
 pkg/scheduler/objects/queue_test.go | 60 +++++++++++++++++++++++++++++++++++++
 pkg/scheduler/partition_test.go     | 52 ++++++++++++++++++++++++++++++++
 3 files changed, 128 insertions(+), 1 deletion(-)

diff --git a/pkg/scheduler/objects/queue.go b/pkg/scheduler/objects/queue.go
index 7ebb0bc2..4a5fdc37 100644
--- a/pkg/scheduler/objects/queue.go
+++ b/pkg/scheduler/objects/queue.go
@@ -1088,9 +1088,9 @@ func (sq *Queue) RemoveApplication(app *Application) {
 	sq.Lock()
 	delete(sq.applications, appID)
 	delete(sq.appPriorities, appID)
-	delete(sq.allocatingAcceptedApps, appID)
 	priority := sq.recalculatePriority()
 	sq.Unlock()
+	sq.removeAllocatingAccepted(appID)
 	app.appEvents.SendRemoveApplicationEvent(appID)
 
 	sq.parent.UpdateQueuePriority(sq.Name, priority)
@@ -2092,6 +2092,21 @@ func (sq *Queue) setAllocatingAccepted(appID string) {
 	sq.allocatingAcceptedApps[appID] = true
 }
 
+// removeAllocatingAccepted stops tracking the application in accepted state that has placeholders allocated.
+// Used when the application is removed before it reached the running state, the tracking is otherwise
+// cleaned up by incRunningApps. For this queue (recursively).
+func (sq *Queue) removeAllocatingAccepted(appID string) {
+	if sq == nil {
+		return
+	}
+	if sq.parent != nil {
+		sq.parent.removeAllocatingAccepted(appID)
+	}
+	sq.Lock()
+	defer sq.Unlock()
+	delete(sq.allocatingAcceptedApps, appID)
+}
+
 func (sq *Queue) GetPreemptionPolicy() policies.PreemptionPolicy {
 	sq.RLock()
 	defer sq.RUnlock()
diff --git a/pkg/scheduler/objects/queue_test.go b/pkg/scheduler/objects/queue_test.go
index d9623ae6..87d4e2b9 100644
--- a/pkg/scheduler/objects/queue_test.go
+++ b/pkg/scheduler/objects/queue_test.go
@@ -671,6 +671,30 @@ func TestRemoveApplication(t *testing.T) {
 	assert.Assert(t, resources.IsZero(root.allocatedResource), "root queue allocated resource not updated correctly")
 }
 
+func TestRemoveApplicationAllocatingAccepted(t *testing.T) {
+	// create the root
+	root, err := createRootQueue(nil)
+	assert.NilError(t, err, "queue create failed")
+	var parent, leaf *Queue
+	parent, err = createManagedQueueMaxApps(root, "parent", true, nil, 1)
+	assert.NilError(t, err, "failed to create parent queue")
+	leaf, err = createManagedQueue(parent, "leaf", false, nil)
+	assert.NilError(t, err, "failed to create leaf queue")
+
+	// app in accepted state with placeholders allocated takes the only slot on the parent
+	app := newApplication("app-1", "default", "root.parent.leaf")
+	leaf.AddApplication(app)
+	leaf.setAllocatingAccepted(app.ApplicationID)
+	assert.Assert(t, !leaf.canRunApp("app-2"), "parent max running apps reached, should be denied")
+
+	// removing the app before it runs must release the slot on all queues in the hierarchy
+	leaf.RemoveApplication(app)
+	assert.Equal(t, len(leaf.allocatingAcceptedApps), 0, "app not removed from leaf list")
+	assert.Equal(t, len(parent.allocatingAcceptedApps), 0, "app not removed from parent list")
+	assert.Equal(t, len(root.allocatingAcceptedApps), 0, "app not removed from root list")
+	assert.Assert(t, leaf.canRunApp("app-2"), "parent slot should be released after removal")
+}
+
 func TestQueueStates(t *testing.T) {
 	// create the root
 	root, err := createRootQueue(nil)
@@ -3287,6 +3311,42 @@ func TestQueue_setAllocatingAccepted(t *testing.T) {
 	q.setAllocatingAccepted("")
 }
 
+func TestQueue_removeAllocatingAccepted(t *testing.T) {
+	// create the root
+	root, err := createRootQueue(nil)
+	assert.NilError(t, err, "queue create failed")
+	var leaf, leaf2 *Queue
+	leaf, err = createManagedQueue(root, "leaf", false, nil)
+	assert.NilError(t, err, "failed to create leaf queue")
+	leaf2, err = createManagedQueue(root, "leaf2", false, nil)
+	assert.NilError(t, err, "failed to create leaf2 queue")
+
+	leaf.setAllocatingAccepted("test-1")
+	leaf.setAllocatingAccepted("test-2")
+	leaf2.setAllocatingAccepted("test-3")
+	assert.Equal(t, len(root.allocatingAcceptedApps), 3, "expected 3 apps in root list")
+
+	leaf.removeAllocatingAccepted("test-1")
+	assert.Equal(t, len(leaf.allocatingAcceptedApps), 1, "expected 1 app in leaf list")
+	assert.Equal(t, len(root.allocatingAcceptedApps), 2, "expected 2 apps in root list")
+	assert.Assert(t, !root.allocatingAcceptedApps["test-1"], "app should be removed from root list")
+	leaf.removeAllocatingAccepted("test-1")
+	assert.Equal(t, len(root.allocatingAcceptedApps), 2, "expected no change after removing same app again")
+
+	leaf2.removeAllocatingAccepted("test-3")
+	assert.Equal(t, len(leaf2.allocatingAcceptedApps), 0, "expected 0 apps in leaf2 list")
+	assert.Equal(t, len(leaf.allocatingAcceptedApps), 1, "expected no change in leaf list")
+	assert.Equal(t, len(root.allocatingAcceptedApps), 1, "expected 1 app in root list")
+
+	defer func() {
+		if r := recover(); r != nil {
+			t.Fatal("panic on nil queue removeAllocatingAccepted")
+		}
+	}()
+	var q *Queue
+	q.removeAllocatingAccepted("")
+}
+
 func TestQueueEvents(t *testing.T) {
 	events.Init()
 	eventSystem := events.GetEventSystem().(*events.EventSystemImpl) //nolint:errcheck
diff --git a/pkg/scheduler/partition_test.go b/pkg/scheduler/partition_test.go
index f16af187..96eee99d 100644
--- a/pkg/scheduler/partition_test.go
+++ b/pkg/scheduler/partition_test.go
@@ -4522,6 +4522,58 @@ func TestTryAllocateMaxRunning(t *testing.T) {
 	assert.Equal(t, result.Request.GetAllocationKey(), allocKey, "expected ask alloc-1 to be allocated")
 }
 
+func TestTryAllocateMaxRunningRemoveAccepted(t *testing.T) {
+	const resType = "vcore"
+	partition := createQueuesNodes(t)
+	assert.Assert(t, partition != nil, "partition create failed")
+	defer partition.userGroupCache.Stop()
+
+	// set max running apps on the parent only
+	parent := partition.getQueueInternal("root.parent")
+	parent.SetMaxRunningApps(1)
+
+	// add first app to the partition
+	appRes, err := resources.NewResourceFromConf(map[string]string{resType: "2"})
+	assert.NilError(t, err, "app resource creation failed")
+	app := newApplicationTG(appID1, "default", "root.parent.sub-leaf", appRes)
+	err = partition.AddApplication(app)
+	assert.NilError(t, err, "failed to add app-1 to partition")
+	var res *resources.Resource
+	res, err = resources.NewResourceFromConf(map[string]string{resType: "1"})
+	assert.NilError(t, err, "failed to create resource")
+	err = app.AddAllocationAsk(newAllocationAskTG(allocKey, appID1, "ph1", res, true))
+	assert.NilError(t, err, "failed to add ask alloc-1 to app-1")
+
+	// allocate should work: app stays in accepted state (placeholder!)
+	result := partition.tryAllocate()
+	if result == nil || result.Request == nil {
+		t.Fatal("allocation did not return any allocation")
+	}
+	assert.Equal(t, app.CurrentState(), objects.Accepted.String(), "application should have stayed in accepted state")
+
+	// add second app to the partition
+	app2 := newApplication(appID2, "default", "root.parent.sub-leaf")
+	err = partition.AddApplication(app2)
+	assert.NilError(t, err, "failed to add app-2 to partition")
+	err = app2.AddAllocationAsk(newAllocationAsk(allocKey, appID2, res))
+	assert.NilError(t, err, "failed to add ask alloc-1 to app-2")
+
+	// allocation should fail max running app is reached on parent via accepted allocating
+	result = partition.tryAllocate()
+	if result != nil {
+		t.Fatal("allocation should not have returned as parent limit is reached")
+	}
+
+	// remove the first app before it reached the running state: the parent limit is released
+	partition.removeApplication(appID1)
+	result = partition.tryAllocate()
+	if result == nil || result.Request == nil {
+		t.Fatal("allocation did not return any allocation")
+	}
+	assert.Equal(t, result.Request.GetApplicationID(), appID2, "expected application app-2 to be allocated")
+	assert.Equal(t, result.Request.GetAllocationKey(), allocKey, "expected ask alloc-1 to be allocated")
+}
+
 func TestNewQueueEvents(t *testing.T) {
 	events.Init()
 	eventSystem := events.GetEventSystem().(*events.EventSystemImpl) //nolint:errcheck


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