YARN-10727. ParentQueue does not validate the queue on removal. Contributed by Andras Gyori

This commit is contained in:
Szilard Nemeth 2021-07-28 14:49:10 +02:00
parent fd13970d94
commit 8d0297c213
2 changed files with 60 additions and 0 deletions

View File

@ -581,6 +581,21 @@ public void removeChildQueue(CSQueue queue)
throws SchedulerDynamicEditException { throws SchedulerDynamicEditException {
writeLock.lock(); writeLock.lock();
try { try {
if (!(queue instanceof AbstractCSQueue) ||
!((AbstractCSQueue) queue).isDynamicQueue()) {
throw new SchedulerDynamicEditException("Queue " + getQueuePath()
+ " can not remove " + queue.getQueuePath() +
" because it is not a dynamic queue");
}
// We need to check if the parent of the child queue is exactly this
// ParentQueue object
if (queue.getParent() != this) {
throw new SchedulerDynamicEditException("Queue " + getQueuePath()
+ " can not remove " + queue.getQueuePath() +
" because it has a different parent queue");
}
// Now we can do remove and update // Now we can do remove and update
this.childQueues.remove(queue); this.childQueues.remove(queue);
this.scheduler.getCapacitySchedulerQueueManager() this.scheduler.getCapacitySchedulerQueueManager()

View File

@ -1162,6 +1162,51 @@ public void testRemoveDanglingAutoCreatedQueuesOnReinit() throws Exception {
"when its dynamic parent is removed", bAutoLeaf); "when its dynamic parent is removed", bAutoLeaf);
} }
@Test
public void testParentQueueDynamicChildRemoval() throws Exception {
startScheduler();
createQueue("root.a.a-auto");
createQueue("root.a.a-auto");
AbstractCSQueue aAuto = (AbstractCSQueue) cs.
getQueue("root.a.a-auto");
Assert.assertTrue(aAuto.isDynamicQueue());
ParentQueue a = (ParentQueue) cs.
getQueue("root.a");
createQueue("root.e.e1-auto");
AbstractCSQueue eAuto = (AbstractCSQueue) cs.
getQueue("root.e.e1-auto");
Assert.assertTrue(eAuto.isDynamicQueue());
ParentQueue e = (ParentQueue) cs.
getQueue("root.e");
// Try to remove a static child queue
try {
a.removeChildQueue(cs.getQueue("root.a.a1"));
Assert.fail("root.a.a1 is a static queue and should not be removed at " +
"runtime");
} catch (SchedulerDynamicEditException ignored) {
}
// Try to remove a dynamic queue with a different parent
try {
a.removeChildQueue(eAuto);
Assert.fail("root.a should not be able to remove root.e.e1-auto");
} catch (SchedulerDynamicEditException ignored) {
}
a.removeChildQueue(aAuto);
e.removeChildQueue(eAuto);
aAuto = (AbstractCSQueue) cs.
getQueue("root.a.a-auto");
eAuto = (AbstractCSQueue) cs.
getQueue("root.e.e1-auto");
Assert.assertNull("root.a.a-auto should have been removed", aAuto);
Assert.assertNull("root.e.e1-auto should have been removed", eAuto);
}
protected LeafQueue createQueue(String queuePath) throws YarnException, protected LeafQueue createQueue(String queuePath) throws YarnException,
IOException { IOException {
return autoQueueHandler.createQueue( return autoQueueHandler.createQueue(