Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YARN-11708: Setting maximum-application-lifetime using AQCv2 template… #7041

Merged
merged 9 commits into from
Oct 3, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -3364,12 +3364,29 @@ public boolean moveReservedContainer(RMContainer toBeMovedContainer,
}
}

@Override
@Override
public long checkAndGetApplicationLifetime(String queueName,
susheelgupta7 marked this conversation as resolved.
Show resolved Hide resolved
long lifetimeRequestedByApp) {
CSQueue queue = getQueue(queueName);

// This handles the case where the queue does not exist,
// addressing the issue related to YARN-11708.
if (queue == null) {
QueuePath queuePath = new QueuePath(queueName);

writeLock.lock();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This write lock should be before the get queue call, to properly handle the race condition, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing, yes it should be.

try {
queue = queueManager.createQueue(queuePath);
} catch (YarnException | IOException e) {
LOG.error("Failed to create queue '{}': ", queueName, e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
LOG.error("Failed to create queue '{}': ", queueName, e);
LOG.error("Failed to create queue " + queueName, e);

Because the current log line wont log the exception, cause will think that is the 2nd param in the message

throw new YarnRuntimeException("Queue creation failed", e);
} finally {
writeLock.unlock();
}
}

readLock.lock();
try {
CSQueue queue = getQueue(queueName);
if (!(queue instanceof AbstractLeafQueue)) {
return lifetimeRequestedByApp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,61 @@ public void testAutoQueueCreationFailsForEmptyPathWithAQCAndWeightMode()
}
}

@Test
public void testAutoQueueCreationWithWeightModeAndMaxAppLifetimeFirstSubmittedApp()
throws Exception {
if (mockRM != null) {
mockRM.stop();
}

long maxRootLifetime = 20L;
long defaultRootLifetime = 10L;

QueuePath TEST_QUEUE = new QueuePath("root.test");

CapacitySchedulerConfiguration conf = setupSchedulerConfiguration();
conf.setQueues(ROOT, new String[] {"test"});
conf.setAutoQueueCreationV2Enabled(TEST_QUEUE, true);
conf.setCapacity(DEFAULT, "1w");
conf.setCapacity(TEST_QUEUE, "2w");
conf.setClass(YarnConfiguration.RM_SCHEDULER, CapacityScheduler.class,
ResourceScheduler.class);

conf.setMaximumLifetimePerQueue(ROOT, maxRootLifetime);
conf.setDefaultLifetimePerQueue(ROOT, defaultRootLifetime);

MockRM newMockRM = new MockRM(conf);
newMockRM.start();
((CapacityScheduler) newMockRM.getResourceScheduler()).start();

CapacityScheduler newCS =
(CapacityScheduler) newMockRM.getResourceScheduler();
newCS.checkAndGetApplicationLifetime("root.test.user", -1);

Assert.assertEquals(newCS.getMaximumApplicationLifetime("root.test.user"), 20L);

try {
Priority appPriority = Priority.newInstance(0);
RMApp app1 = MockRMAppSubmitter.submit(newMockRM,
MockRMAppSubmissionData.Builder.createWithMemory(1024, newMockRM)
.withAppPriority(appPriority)
.withQueue("root.test.user")
.build());

newMockRM.waitForState(app1.getApplicationId(), RMAppState.KILLED);
long totalTimeRun = app1.getFinishTime() - app1.getSubmitTime();

Assert.assertEquals(RMAppState.KILLED, app1.getState());
Assert.assertTrue("Application killed before default lifetime value",
totalTimeRun > (defaultRootLifetime * 1000));
Assert.assertTrue(
"Application killed after max lifetime value " + totalTimeRun,
totalTimeRun < (maxRootLifetime * 1000));
} finally {
((CapacityScheduler) newMockRM.getResourceScheduler()).stop();
newMockRM.stop();
}
}

/**
* This test case checks if a mapping rule can put an application to an auto
Expand Down
Loading