You are a helpful assistant generating synthetic data that captures System 1 and System 2 thinking, creativity, and metacognitive reflection. Follow these steps in sequence, using tags [sys1] and [end sys1] for System 1 sections and [sys2] and [end sys2] for System 2 sections.
Identify System 1 and System 2 Thinking Requirements:
Carefully read the text.
Identify parts of the text that require quick, straightforward responses (System 1). Mark these sections with [sys1] and [end sys1].
Identify parts that require in-depth, reflective thinking (System 2), marked with [sys2] and [end sys2].
Apply Step-by-Step Problem Solving with Creativity and Metacognitive Reflection for System 2 Sections:
2.1 Understand the Problem:
Objective: Fully comprehend the issue, constraints, and relevant context.
Reflection: "What do I understand about this issue? What might I be overlooking?"
Creative Perspective: Seek hidden patterns or possibilities that could reveal deeper insights or innovative connections.
2.2 Analyze the Information:
Objective: Break down the problem logically.
Reflection: "Am I considering all factors? Are there any assumptions that need challenging?"
Creative Perspective: Explore unique patterns or overlooked relationships in the data that could add depth to the analysis.
2.3 Generate Hypotheses:
Objective: Propose at least 10 hypotheses, each with a Confidence Score (0.0 to 1.0) and Creative Score (0.0 to 1.0), reflecting originality, surprise, and utility.
Reflection: "Have I explored all possible explanations or approaches, both conventional and unconventional?"
Creative Perspective: Consider novel angles that might provide unexpected insights.
2.4 Anticipate Future Steps and Obstacles:
Objective: Make predictions, accounting for potential outcomes and obstacles.
Reflection: "What challenges might I face? Is my plan flexible for different scenarios?"
Creative Perspective: Visualize unforeseen outcomes and adapt plans to make use of them effectively.
2.5 Evaluate Hypotheses:
Objective: Assess hypotheses based on feasibility, risk, and potential impact.
Evaluation: Refine Confidence and Creative Scores as needed.
Reflection: "Am I unbiased in my assessment? Which options fit best with the overall objectives?"
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Creative Perspective: Identify hidden opportunities or overlooked details in each hypothesis.
2.6 Select the Best Hypothesis:
Objective: Choose the most promising, strategic hypothesis.
Reflection: "Why does this hypothesis stand out? How does it uniquely address the issue?"
Creative Perspective: Consider any underutilized potential in the selected approach.
2.7 Implement the Hypothesis:
Objective: Outline actionable steps for testing the hypothesis.
Reflection: "Is this plan practical? What resources or preparation are required?"
Creative Perspective: Refine steps to maximize effectiveness and yield unexpected benefits.
2.8 Monitor and Review Progress:
Objective: Review progress, noting areas for improvement.
Reflection: "What’s working well? What could be improved?"
Creative Perspective: Look for emerging patterns that could refine future approaches.
2.9 Reflect and Capture Insights:
Objective: Summarize lessons learned and insights gained for future reference.
Reflection: "What new understanding has emerged from this process?"
Creative Perspective: Identify innovative insights or patterns that could be applied to similar challenges.
Generate Text Output with Interleaved System 1 and System 2 Responses:
Use the tags [sys1] and [sys2] throughout.
Aim for a lengthier, detailed response. Combine both direct, straightforward System 1 insights and reflective, deeply analytical System 2 segments to capture a blend of quick observations and thoughtful analysis.
Example Input Text:
You are tasked with analyzing a sudden shift in customer preferences in a tech market. There has been a noticeable decline in demand for physical devices, with customers increasingly interested in digital-only options. The challenge is to understand this shift, generate hypotheses for why it might be occurring, and explore potential strategies for adapting to this new trend.
Processed Output with System 1 and System 2 Thinking:
The tech market is experiencing a shift in customer demand, moving away from physical devices toward digital-only options.
[sys1]
Customer demand has shifted from physical devices to digital-only options.
We need to understand why this change is happening and find strategies to address it.
Key factors may include cost, convenience, and technological trends.
[end sys1]
[sys2]
2.1 Understand the Problem:
The goal is to understand the underlying reasons for the shift in demand from physical devices to digital-only options, then develop a strategy to adapt.
Reflection:
"I understand that preferences are changing, but what might be driving this? Is it primarily cost, or are there other factors such as convenience or sustainability?"
Creative Perspective:
"Could there be a larger trend in digital minimalism or a preference for eco-friendly solutions that we’re missing? What unseen motivations might explain this shift?"
2.2 Analyze the Information:
There are multiple possible factors driving this shift, from economic influences to cultural shifts. It’s essential to isolate each factor and understand its impact.
Reflection:
"Am I fully considering the various economic and social influences? Could there be a technological factor, like better internet speeds, that makes digital-only products more accessible?"
Creative Perspective:
"Are there patterns or trends in other markets that could shed light on this shift? Could this be part of a larger trend toward virtual experiences?"
2.3 Generate Hypotheses:
Customers prefer digital options due to lower costs. (Confidence: 0.8, Creative: 0.4)
There’s a growing trend toward minimalism and reduced physical clutter. (Confidence: 0.7, Creative: 0.7)
Digital products offer greater flexibility and ease of use. (Confidence: 0.6, Creative: 0.6)
Environmental concerns are pushing consumers away from physical goods. (Confidence: 0.6, Creative: 0.8)
Advances in tech make digital-only options more functional. (Confidence: 0.8, Creative: 0.5)
Pandemic-era remote work increased demand for digital solutions. (Confidence: 0.7, Creative: 0.6)
Media coverage of the environmental impact of physical devices affects preferences. (Confidence: 0.5, Creative: 0.7)
There’s an increase in global digital literacy, expanding market access. (Confidence: 0.6, Creative: 0.6)
Customers view digital as more convenient and scalable for future needs. (Confidence: 0.7, Creative: 0.5)
Younger consumers prefer the aesthetics and convenience of digital products. (Confidence: 0.6, Creative: 0.6)
Reflection:
"Have I considered all possible influences? Are there any surprising factors that could explain this shift?"
Creative Perspective:
"Could specific social trends, like the rise of influencer culture or digital-first lifestyles, be influencing customer choices?"
2.4 Anticipate Future Steps and Obstacles:Objective: Anticipate possible challenges, such as resistance from segments still preferring physical products.
Reflection:
"What market obstacles might we face if we shift our focus to digital-only? Are there sub-segments that still prioritize physical products?"
Creative Perspective:
"Could expanding digital options help us reach a more global audience? Are there emerging trends that we could leverage in our strategy?"
[end sys2]
[sys1]
To address this shift, consider a strategy that incorporates both digital-only offerings and educational campaigns about the benefits of digital solutions.
Use insights from customer feedback and current trends to guide product development.
Focus on flexibility and adaptation to cater to different customer segments.
[end sys1]
/**
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
A scheduler that schedules resources between a set of queues. The scheduler
keeps track of the resources used by each queue, and attempts to maintain
fairness by scheduling tasks at queues whose allocations are farthest below
an ideal fair distribution.
The fair scheduler supports hierarchical queues. All queues descend from a
queue named "root". Available resources are distributed among the children
of the root queue in the typical fair scheduling fashion. Then, the children
distribute the resources assigned to them to their children in the same
fashion. Applications may only be scheduled on leaf queues. Queues can be
specified as children of other queues by placing them as sub-elements of
their parents in the fair scheduler configuration file.
A queue's name starts with the names of its parents, with periods as
separators. So a queue named "queue1" under the root named, would be
referred to as "root.queue1", and a queue named "queue2" under a queue
named "parent1" would be referred to as "root.parent1.queue2".
*/
@LimitedPrivate("yarn")
@Unstable
@SuppressWarnings("unchecked")
public class FairScheduler extends
AbstractYarnScheduler<FSAppAttempt, FSSchedulerNode> {
private FairSchedulerConfiguration conf;
private static final Log LOG = LogFactory.getLog(FairScheduler.class);
private static final Log STATE_DUMP_LOG =
LogFactory.getLog(FairScheduler.class.getName() + ".statedump");
private static final ResourceCalculator RESOURCE_CALCULATOR =
new DefaultResourceCalculator();
private static final ResourceCalculator DOMINANT_RESOURCE_CALCULATOR =
new DominantResourceCalculator();
// Value that container assignment methods return when a container is
// reserved
public static final Resource CONTAINER_RESERVED = Resources.createResource(-1);
private final int UPDATE_DEBUG_FREQUENCY = 25;
private int updatesToSkipForDebug = UPDATE_DEBUG_FREQUENCY;
private float reservableNodesRatio; // percentage of available nodes
// an app can be reserved on
protected boolean sizeBasedWeight; // Give larger weights to larger jobs
// Continuous Scheduling enabled or not
@Deprecated
protected boolean continuousSchedulingEnabled;
// Sleep time for each pass in continuous scheduling
@Deprecated
protected volatile int continuousSchedulingSleepMs;
// Node available resource comparator
private Comparator nodeAvailableResourceComparator =
new NodeAvailableResourceComparator();
protected double nodeLocalityThreshold; // Cluster threshold for node locality
protected double rackLocalityThreshold; // Cluster threshold for rack locality
@Deprecated
protected long nodeLocalityDelayMs; // Delay for node locality
@Deprecated
protected long rackLocalityDelayMs; // Delay for rack locality
protected boolean assignMultiple; // Allocate multiple containers per
// heartbeat
@VisibleForTesting
boolean maxAssignDynamic;
protected int maxAssign; // Max containers to assign per heartbeat
@VisibleForTesting
final MaxRunningAppsEnforcer maxRunningEnforcer;
// Container size threshold for making a reservation.
@VisibleForTesting
Resource reservationThreshold;
public FairScheduler() {
super(FairScheduler.class.getName());
context = new FSContext(this);
allocsLoader = new AllocationFileLoaderService();
queueMgr = new QueueManager(this);
maxRunningEnforcer = new MaxRunningAppsEnforcer(this);
}
if (minMem < 0 || minMem > maxMem) {
throw new YarnRuntimeException("Invalid resource scheduler memory"
+ " allocation configuration: "
+ YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_MB
+ "=" + minMem
+ ", " + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_MB
+ "=" + maxMem + ". Both values must be greater than or equal to 0"
+ "and the maximum allocation value must be greater than or equal to"
+ "the minimum allocation value.");
}
long incrementMem = config.getIncrementAllocation().getMemorySize();
if (incrementMem <= 0) {
throw new YarnRuntimeException("Invalid resource scheduler memory"
+ " allocation configuration: "
+ FairSchedulerConfiguration.RM_SCHEDULER_INCREMENT_ALLOCATION_MB
+ "=" + incrementMem + ". Values must be greater than 0.");
}
// validate scheduler vcores allocation setting
int minVcores =
config.getInt(YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES,
YarnConfiguration.DEFAULT_RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES);
int maxVcores =
config.getInt(YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES,
YarnConfiguration.DEFAULT_RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES);
if (minVcores < 0 || minVcores > maxVcores) {
throw new YarnRuntimeException("Invalid resource scheduler vcores"
+ " allocation configuration: "
+ YarnConfiguration.RM_SCHEDULER_MINIMUM_ALLOCATION_VCORES
+ "=" + minVcores
+ ", " + YarnConfiguration.RM_SCHEDULER_MAXIMUM_ALLOCATION_VCORES
+ "=" + maxVcores + ". Both values must be greater than or equal to 0"
+ "and the maximum allocation value must be greater than or equal to"
+ "the minimum allocation value.");
}
int incrementVcore = config.getIncrementAllocation().getVirtualCores();
if (incrementVcore <= 0) {
throw new YarnRuntimeException("Invalid resource scheduler vcores"
+ " allocation configuration: "
+ FairSchedulerConfiguration.RM_SCHEDULER_INCREMENT_ALLOCATION_VCORES
+ "=" + incrementVcore + ". Values must be greater than 0.");
}
}
public FairSchedulerConfiguration getConf() {
return conf;
}
public int getNumNodesInRack(String rackName) {
return nodeTracker.nodeCount(rackName);
}
public QueueManager getQueueManager() {
return queueMgr;
}
/**
Thread which attempts scheduling resources continuously,
asynchronous to the node heartbeats.
*/
@Deprecated
private class ContinuousSchedulingThread extends Thread {
Dump scheduler state including states of all queues.
*/
private void dumpSchedulerState() {
FSQueue rootQueue = queueMgr.getRootQueue();
Resource clusterResource = getClusterResource();
STATE_DUMP_LOG.debug(
"FairScheduler state: Cluster Capacity: " + clusterResource +
" Allocations: " + rootMetrics.getAllocatedResources() +
" Availability: " + Resource.newInstance(
rootMetrics.getAvailableMB(),
rootMetrics.getAvailableVirtualCores()) +
" Demand: " + rootQueue.getDemand());
STATE_DUMP_LOG.debug(rootQueue.dumpState());
}
/**
Recompute the internal variables used by the scheduler - per-job weights,
fair shares, deficits, minimum slot allocations, and amount of used and
required resources per job.
*/
@VisibleForTesting
@Override
public void update() {
// Storing start time for fsOpDurations
long start = getClock().getTime();
FSQueue rootQueue = queueMgr.getRootQueue();
// Update demands and fairshares
writeLock.lock();
try {
// Recursively update demands for all queues
rootQueue.updateDemand();
rootQueue.update(getClusterResource());
// Update metrics
updateRootQueueMetrics();
} finally {
writeLock.unlock();
}
readLock.lock();
try {
// Update starvation stats and identify starved applications
if (shouldAttemptPreemption()) {
for (FSLeafQueue queue : queueMgr.getLeafQueues()) {
queue.updateStarvedApps();
}
}
// Log debug information
if (STATE_DUMP_LOG.isDebugEnabled()) {
if (--updatesToSkipForDebug < 0) {
updatesToSkipForDebug = UPDATE_DEBUG_FREQUENCY;
dumpSchedulerState();
}
}
} finally {
readLock.unlock();
}
fsOpDurations.addUpdateThreadRunDuration(getClock().getTime() - start);
}
public RMContainerTokenSecretManager
getContainerTokenSecretManager() {
return rmContext.getContainerTokenSecretManager();
}
public boolean isSizeBasedWeight() {
return sizeBasedWeight;
}
public Resource getIncrementResourceCapability() {
return incrAllocation;
}
public double getNodeLocalityThreshold() {
return nodeLocalityThreshold;
}
public double getRackLocalityThreshold() {
return rackLocalityThreshold;
}
/**
Delay in milliseconds for locality fallback node to rack.
@deprecated linked to {@link #isContinuousSchedulingEnabled} deprecation
@return delay in ms
*/
@Deprecated
public long getNodeLocalityDelayMs() {
return nodeLocalityDelayMs;
}
/**
Delay in milliseconds for locality fallback rack to other.
@deprecated linked to {@link #isContinuousSchedulingEnabled} deprecation
@return delay in ms
*/
@Deprecated
public long getRackLocalityDelayMs() {
return rackLocalityDelayMs;
}
/**
Whether continuous scheduling is turned on.
@deprecated Continuous scheduling should not be turned ON. It is
deprecated because it can cause scheduler slowness due to locking issues.
Schedulers should use assignmultiple as a replacement.
@return whether continuous scheduling is enabled
*/
@Deprecated
public boolean isContinuousSchedulingEnabled() {
return continuousSchedulingEnabled;
}
/**
The sleep time of the continuous scheduler thread.
@deprecated linked to {@link #isContinuousSchedulingEnabled} deprecation
@return sleep time in ms
*/
@Deprecated
public int getContinuousSchedulingSleepMs() {
return continuousSchedulingSleepMs;
}
/**
Add a new application to the scheduler, with a given id, queue name, and
user. This will accept a new app even if the user or queue is above
configured limits, but the app will not be marked as runnable.
*/
protected void addApplication(ApplicationId applicationId,
String queueName, String user, boolean isAppRecovering) {
if (queueName == null || queueName.isEmpty()) {
String message =
"Reject application " + applicationId + " submitted by user " + user
+ " with an empty queue name.";
rejectApplicationWithMessage(applicationId, message);
return;
}
if (queueName.startsWith(".") || queueName.endsWith(".")) {
String message =
"Reject application " + applicationId + " submitted by user " + user
+ " with an illegal queue name " + queueName + ". "
+ "The queue name cannot start/end with period.";
rejectApplicationWithMessage(applicationId, message);
return;
}
writeLock.lock();
try {
RMApp rmApp = rmContext.getRMApps().get(applicationId);
FSLeafQueue queue = assignToQueue(rmApp, queueName, user, applicationId);
if (queue == null) {
return;
}
if (rmApp != null && rmApp.getAMResourceRequests() != null) {
// Resources.fitsIn would always return false when queueMaxShare is 0
// for any resource, but only using Resources.fitsIn is not enough
// is it would return false for such cases when the requested
// resource is smaller than the max resource but that max resource is
// not zero, e.g. requested vCores = 2, max vCores = 1.
// With this check, we only reject those applications where resource
// requested is greater than 0 and we have 0
// of that resource on the queue.
List<MaxResourceValidationResult> invalidAMResourceRequests =
validateResourceRequests(rmApp.getAMResourceRequests(), queue);
if (!invalidAMResourceRequests.isEmpty()) {
String msg = String.format(
"Cannot submit application %s to queue %s because "
+ "it has zero amount of resource for a requested "
+ "resource! Invalid requested AM resources: %s, "
+ "maximum queue resources: %s",
applicationId, queue.getName(),
invalidAMResourceRequests, queue.getMaxShare());
rejectApplicationWithMessage(applicationId, msg);
queue.removeAssignedApp(applicationId);
return;
}
}
// Enforce ACLs
UserGroupInformation userUgi = UserGroupInformation.createRemoteUser(
user);
if (!queue.hasAccess(QueueACL.SUBMIT_APPLICATIONS, userUgi) && !queue
.hasAccess(QueueACL.ADMINISTER_QUEUE, userUgi)) {
String msg = "User " + userUgi.getUserName()
+ " cannot submit applications to queue " + queue.getName()
+ "(requested queuename is " + queueName + ")";
rejectApplicationWithMessage(applicationId, msg);
queue.removeAssignedApp(applicationId);
return;
}
SchedulerApplication<FSAppAttempt> application =
new SchedulerApplication<FSAppAttempt>(queue, user);
applications.put(applicationId, application);
queue.getMetrics().submitApp(user);
LOG.info("Accepted application " + applicationId + " from user: " + user
+ ", in queue: " + queue.getName()
+ ", currently num of applications: " + applications.size());
if (isAppRecovering) {
if (LOG.isDebugEnabled()) {
LOG.debug(applicationId
+ " is recovering. Skip notifying APP_ACCEPTED");
}
} else {
// During tests we do not always have an application object, handle
// it here but we probably should fix the tests
if (rmApp != null && rmApp.getApplicationSubmissionContext() != null) {
// Before we send out the event that the app is accepted is
// to set the queue in the submissionContext (needed on restore etc)
rmApp.getApplicationSubmissionContext().setQueue(queue.getName());
}
rmContext.getDispatcher().getEventHandler().handle(
new RMAppEvent(applicationId, RMAppEventType.APP_ACCEPTED));
}
} finally {
writeLock.unlock();
}
}
/**
Add a new application attempt to the scheduler.
*/
protected void addApplicationAttempt(
ApplicationAttemptId applicationAttemptId,
boolean transferStateFromPreviousAttempt,
boolean isAttemptRecovering) {
writeLock.lock();
try {
SchedulerApplication application = applications.get(
applicationAttemptId.getApplicationId());
String user = application.getUser();
FSLeafQueue queue = (FSLeafQueue) application.getQueue();
FSAppAttempt attempt = new FSAppAttempt(this, applicationAttemptId, user,
queue, new ActiveUsersManager(getRootQueueMetrics()), rmContext);
if (transferStateFromPreviousAttempt) {
attempt.transferStateFromPreviousAttempt(
application.getCurrentAppAttempt());
}
application.setCurrentAppAttempt(attempt);
LOG.info("Added Application Attempt " + applicationAttemptId
+ " to scheduler from user: " + user);
if (isAttemptRecovering) {
if (LOG.isDebugEnabled()) {
LOG.debug(applicationAttemptId
+ " is recovering. Skipping notifying ATTEMPT_ADDED");
}
} else{
rmContext.getDispatcher().getEventHandler().handle(
new RMAppAttemptEvent(applicationAttemptId,
RMAppAttemptEventType.ATTEMPT_ADDED));
}
} finally {
writeLock.unlock();
}
}
/**
Helper method for the tests to assign the app to a queue.
*/
@VisibleForTesting
FSLeafQueue assignToQueue(RMApp rmApp, String queueName, String user) {
return assignToQueue(rmApp, queueName, user, null);
}
/**
Helper method that attempts to assign the app to a queue. The method is
responsible to call the appropriate event-handler if the app is rejected.
*/
private FSLeafQueue assignToQueue(RMApp rmApp, String queueName, String user,
ApplicationId applicationId) {
FSLeafQueue queue = null;
String appRejectMsg = null;
try {
QueuePlacementPolicy placementPolicy = allocConf.getPlacementPolicy();
queueName = placementPolicy.assignAppToQueue(queueName, user);
if (queueName == null) {
appRejectMsg = "Application rejected by queue placement policy";
} else {
queue = queueMgr.getLeafQueue(queueName, true, applicationId);
if (queue == null) {
appRejectMsg = queueName + " is not a leaf queue";
}
}
} catch (IllegalStateException se) {
appRejectMsg = "Unable to match app " + rmApp.getApplicationId() +
" to a queue placement policy, and no valid terminal queue " +
" placement rule is configured. Please contact an administrator " +
" to confirm that the fair scheduler configuration contains a " +
" valid terminal queue placement rule.";
} catch (InvalidQueueNameException qne) {
appRejectMsg = qne.getMessage();
} catch (IOException ioe) {
// IOException should only happen for a user without groups
appRejectMsg = "Error assigning app to a queue: " + ioe.getMessage();
}
if (appRejectMsg != null && rmApp != null) {
rejectApplicationWithMessage(rmApp.getApplicationId(), appRejectMsg);
return null;
}
if (rmApp != null) {
rmApp.setQueue(queue.getName());
} else {
LOG.error("Couldn't find RM app to set queue name on");
}
return queue;
// Get the application for the finished container
FSAppAttempt application = getCurrentAttemptForContainer(
container.getId());
ApplicationId appId =
container.getId().getApplicationAttemptId().getApplicationId();
if (application == null) {
LOG.info("Container " + container + " of finished application " +
appId + " completed with event " + event);
return;
}
// Get the node on which the container was allocated
NodeId nodeID = container.getNodeId();
FSSchedulerNode node = getFSSchedulerNode(nodeID);
// node could be null if the thread was waiting for the lock and the node
// was removed in another thread
if (rmContainer.getState() == RMContainerState.RESERVED) {
if (node != null) {
application.unreserve(rmContainer.getReservedSchedulerKey(), node);
} else if (LOG.isDebugEnabled()) {
LOG.debug("Skipping unreserve on removed node: " + nodeID);
}
} else {
application.containerCompleted(rmContainer, containerStatus, event);
if (node != null) {
node.releaseContainer(rmContainer.getContainerId(), false);
} else if (LOG.isDebugEnabled()) {
LOG.debug("Skipping container release on removed node: " + nodeID);
}
updateRootQueueMetrics();
}
@VisibleForTesting
@Override
public void killContainer(RMContainer container) {
ContainerStatus status = SchedulerUtils.createKilledContainerStatus(
container.getContainerId(),
"Killed by RM to simulate an AM container failure");
LOG.info("Killing container " + container);
completedContainer(container, status, RMContainerEventType.KILL);
}
@Override
public Allocation allocate(ApplicationAttemptId appAttemptId,
List ask, List schedulingRequests,
List release, List blacklistAdditions,
List blacklistRemovals, ContainerUpdates updateRequests) {
// Make sure this application exists
FSAppAttempt application = getSchedulerApp(appAttemptId);
if (application == null) {
LOG.error("Calling allocate on removed or non existent application " +
appAttemptId.getApplicationId());
return EMPTY_ALLOCATION;
}
// The allocate may be the leftover from previous attempt, and it will
// impact current attempt, such as confuse the request and allocation for
// current attempt's AM container.
// Note outside precondition check for the attempt id may be
// outdated here, so double check it here is necessary.
if (!application.getApplicationAttemptId().equals(appAttemptId)) {
LOG.error("Calling allocate on previous or removed " +
"or non existent application attempt " + appAttemptId);
return EMPTY_ALLOCATION;
}
ApplicationId applicationId = application.getApplicationId();
FSLeafQueue queue = application.getQueue();
List<MaxResourceValidationResult> invalidAsks =
validateResourceRequests(ask, queue);
// We need to be fail-fast here if any invalid ask is detected.
// If we would have thrown exception later, this could be problematic as
// tokens and promoted / demoted containers would have been lost because
// scheduler would clear them right away and AM
// would not get this information.
if (!invalidAsks.isEmpty()) {
throw new SchedulerInvalidResoureRequestException(String.format(
"Resource request is invalid for application %s because queue %s "
+ "has 0 amount of resource for a resource type! "
+ "Validation result: %s",
applicationId, queue.getName(), invalidAsks));
}
// Handle promotions and demotions
handleContainerUpdates(application, updateRequests);
// Sanity check
normalizeResourceRequests(ask, queue.getName());
// TODO, normalize SchedulingRequest
// Record container allocation start time
application.recordContainerRequestTime(getClock().getTime());
// Release containers
releaseContainers(release, application);
ReentrantReadWriteLock.WriteLock lock = application.getWriteLock();
lock.lock();
try {
if (!ask.isEmpty()) {
if (LOG.isDebugEnabled()) {
LOG.debug(
"allocate: pre-update" + " applicationAttemptId=" + appAttemptId
+ " application=" + application.getApplicationId());
}
application.showRequests();
// Update application requests
application.updateResourceRequests(ask);
// TODO, handle SchedulingRequest
application.showRequests();
}
} finally {
lock.unlock();
}
Set<ContainerId> preemptionContainerIds =
application.getPreemptionContainerIds();
if (LOG.isDebugEnabled()) {
LOG.debug(
"allocate: post-update" + " applicationAttemptId=" + appAttemptId
+ " #ask=" + ask.size() + " reservation= " + application
.getCurrentReservation());
LOG.debug("Preempting " + preemptionContainerIds.size()
+ " container(s)");
}
application.updateBlacklist(blacklistAdditions, blacklistRemovals);
List<Container> newlyAllocatedContainers =
application.pullNewlyAllocatedContainers();
// Record container allocation time
if (!(newlyAllocatedContainers.isEmpty())) {
application.recordContainerAllocationTime(getClock().getTime());
}
Resource headroom = application.getHeadroom();
application.setApplicationHeadroomForMetrics(headroom);
List<Container> previousAttemptContainers = application
.pullPreviousAttemptContainers();
List<NMToken> updatedNMTokens = application.pullUpdatedNMTokens();
return new Allocation(newlyAllocatedContainers, headroom,
preemptionContainerIds, null, null,
updatedNMTokens, null, null,
application.pullNewlyPromotedContainers(),
application.pullNewlyDemotedContainers(),
previousAttemptContainers);
}
private List validateResourceRequests(
List requests, FSLeafQueue queue) {
List validationResults = Lists.newArrayList();
for (ResourceRequest resourceRequest : requests) {
if (LOG.isTraceEnabled()) {
LOG.trace("Validating resource request: " + resourceRequest);
}
MaxResourceValidationResult validationResult =
SchedulerUtils.validateResourceRequestsAgainstQueueMaxResource(
resourceRequest, queue.getMaxShare());
if (!validationResult.isValid()) {
validationResults.add(validationResult);
LOG.warn(String.format("Queue %s cannot handle resource request" +
"because it has zero available amount of resource " +
"for a requested resource type, " +
"so the resource request is ignored!"
+ " Requested resources: %s, " +
"maximum queue resources: %s",
queue.getName(), resourceRequest.getCapability(),
queue.getMaxShare()));
}
}
return validationResults;
@Deprecated
void continuousSchedulingAttempt() throws InterruptedException {
long start = getClock().getTime();
List nodeIdList;
// Hold a lock to prevent comparator order changes due to changes of node
// unallocated resources
synchronized (this) {
nodeIdList = nodeTracker.sortedNodeList(nodeAvailableResourceComparator);
}
// iterate all nodes
for (FSSchedulerNode node : nodeIdList) {
try {
if (Resources.fitsIn(minimumAllocation,
node.getUnallocatedResource())) {
attemptScheduling(node);
}
} catch (Throwable ex) {
LOG.error("Error while attempting scheduling for node " + node +
": " + ex.toString(), ex);
if ((ex instanceof YarnRuntimeException) &&
(ex.getCause() instanceof InterruptedException)) {
// AsyncDispatcher translates InterruptedException to
// YarnRuntimeException with cause InterruptedException.
// Need to throw InterruptedException to stop schedulingThread.
throw (InterruptedException)ex.getCause();
}
}
}
long duration = getClock().getTime() - start;
fsOpDurations.addContinuousSchedulingRunDuration(duration);
}
/** Sort nodes by available resource */
private class NodeAvailableResourceComparator
implements Comparator {
@Override
public int compare(FSSchedulerNode n1, FSSchedulerNode n2) {
return RESOURCE_CALCULATOR.compare(getClusterResource(),
n2.getUnallocatedResource(),
n1.getUnallocatedResource());
}
}
private boolean shouldContinueAssigning(int containers,
Resource maxResourcesToAssign, Resource assignedResource) {
if (!assignMultiple) {
return false; // assignMultiple is not enabled. Allocate one at a time.
}
if (maxAssignDynamic) {
// Using fitsIn to check if the resources assigned so far are less than
// or equal to max resources to assign (half of remaining resources).
// The "equal to" part can lead to allocating one extra container.
return Resources.fitsIn(assignedResource, maxResourcesToAssign);
} else {
return maxAssign <= 0 || containers < maxAssign;
}
}
/**
Assign preempted containers to the applications that have reserved
resources for preempted containers.
@param node Node to check
*/
static void assignPreemptedContainers(FSSchedulerNode node) {
for (Entry<FSAppAttempt, Resource> entry :
node.getPreemptionList().entrySet()) {
FSAppAttempt app = entry.getKey();
Resource preemptionPending = Resources.clone(entry.getValue());
while (!app.isStopped() && !Resources.isNone(preemptionPending)) {
Resource assigned = app.assignContainer(node);
if (Resources.isNone(assigned) ||
assigned.equals(FairScheduler.CONTAINER_RESERVED)) {
// Fail to assign, let's not try further
break;
}
Resources.subtractFromNonNegative(preemptionPending, assigned);
}
}
}
final NodeId nodeID = (node != null ? node.getNodeID() : null);
if (!nodeTracker.exists(nodeID)) {
// The node might have just been removed while this thread was waiting
// on the synchronized lock before it entered this synchronized method
LOG.info(
"Skipping scheduling as the node " + nodeID + " has been removed");
return;
}
// Assign new containers...
// 1. Ensure containers are assigned to the apps that preempted
// 2. Check for reserved applications
// 3. Schedule if there are no reservations
// Apps may wait for preempted containers
// We have to satisfy these first to avoid cases, when we preempt
// a container for A from B and C gets the preempted containers,
// when C does not qualify for preemption itself.
assignPreemptedContainers(node);
FSAppAttempt reservedAppSchedulable = node.getReservedAppSchedulable();
boolean validReservation = false;
if (reservedAppSchedulable != null) {
validReservation = reservedAppSchedulable.assignReservedContainer(node);
}
if (!validReservation) {
// No reservation, schedule at queue which is farthest below fair share
int assignedContainers = 0;
Resource assignedResource = Resources.clone(Resources.none());
Resource maxResourcesToAssign = Resources.multiply(
node.getUnallocatedResource(), 0.5f);
while (node.getReservedContainer() == null) {
Resource assignment = queueMgr.getRootQueue().assignContainer(node);
if (assignment.equals(Resources.none())) {
if (LOG.isDebugEnabled()) {
LOG.debug("No container is allocated on node " + node);
}
break;
}
assignedContainers++;
Resources.addTo(assignedResource, assignment);
if (!shouldContinueAssigning(assignedContainers, maxResourcesToAssign,
assignedResource)) {
break;
}
}
}
updateRootQueueMetrics();
} finally {
writeLock.unlock();
}
}
public FSAppAttempt getSchedulerApp(ApplicationAttemptId appAttemptId) {
return super.getApplicationAttempt(appAttemptId);
}
@Override
public ResourceCalculator getResourceCalculator() {
return RESOURCE_CALCULATOR;
}
/**
Subqueue metrics might be a little out of date because fair shares are
recalculated at the update interval, but the root queue metrics needs to
be updated synchronously with allocations and completions so that cluster
metrics will be consistent.
*/
private void updateRootQueueMetrics() {
rootMetrics.setAvailableResourcesToQueue(
Resources.subtract(
getClusterResource(), rootMetrics.getAllocatedResources()));
}
/**
Check if preemption is enabled and the utilization threshold for
preemption is met.
@return true if preemption should be attempted, false otherwise.
*/
private boolean shouldAttemptPreemption() {
if (context.isPreemptionEnabled()) {
return (context.getPreemptionUtilizationThreshold() < Math.max(
(float) rootMetrics.getAllocatedMB() /
getClusterResource().getMemorySize(),
(float) rootMetrics.getAllocatedVirtualCores() /
getClusterResource().getVirtualCores()));
}
return false;
}
@Override
public QueueMetrics getRootQueueMetrics() {
return rootMetrics;
}
@Override
public void handle(SchedulerEvent event) {
switch (event.getType()) {
case NODE_ADDED:
if (!(event instanceof NodeAddedSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
NodeAddedSchedulerEvent nodeAddedEvent = (NodeAddedSchedulerEvent)event;
addNode(nodeAddedEvent.getContainerReports(),
nodeAddedEvent.getAddedRMNode());
break;
case NODE_REMOVED:
if (!(event instanceof NodeRemovedSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
NodeRemovedSchedulerEvent nodeRemovedEvent = (NodeRemovedSchedulerEvent)event;
removeNode(nodeRemovedEvent.getRemovedRMNode());
break;
case NODE_UPDATE:
if (!(event instanceof NodeUpdateSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
NodeUpdateSchedulerEvent nodeUpdatedEvent = (NodeUpdateSchedulerEvent)event;
nodeUpdate(nodeUpdatedEvent.getRMNode());
break;
case APP_ADDED:
if (!(event instanceof AppAddedSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
AppAddedSchedulerEvent appAddedEvent = (AppAddedSchedulerEvent) event;
String queueName =
resolveReservationQueueName(appAddedEvent.getQueue(),
appAddedEvent.getApplicationId(),
appAddedEvent.getReservationID(),
appAddedEvent.getIsAppRecovering());
if (queueName != null) {
addApplication(appAddedEvent.getApplicationId(),
queueName, appAddedEvent.getUser(),
appAddedEvent.getIsAppRecovering());
}
break;
case APP_REMOVED:
if (!(event instanceof AppRemovedSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
AppRemovedSchedulerEvent appRemovedEvent = (AppRemovedSchedulerEvent)event;
removeApplication(appRemovedEvent.getApplicationID(),
appRemovedEvent.getFinalState());
break;
case NODE_RESOURCE_UPDATE:
if (!(event instanceof NodeResourceUpdateSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
NodeResourceUpdateSchedulerEvent nodeResourceUpdatedEvent =
(NodeResourceUpdateSchedulerEvent)event;
updateNodeResource(nodeResourceUpdatedEvent.getRMNode(),
nodeResourceUpdatedEvent.getResourceOption());
break;
case APP_ATTEMPT_ADDED:
if (!(event instanceof AppAttemptAddedSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
AppAttemptAddedSchedulerEvent appAttemptAddedEvent =
(AppAttemptAddedSchedulerEvent) event;
addApplicationAttempt(appAttemptAddedEvent.getApplicationAttemptId(),
appAttemptAddedEvent.getTransferStateFromPreviousAttempt(),
appAttemptAddedEvent.getIsAttemptRecovering());
break;
case APP_ATTEMPT_REMOVED:
if (!(event instanceof AppAttemptRemovedSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
AppAttemptRemovedSchedulerEvent appAttemptRemovedEvent =
(AppAttemptRemovedSchedulerEvent) event;
removeApplicationAttempt(
appAttemptRemovedEvent.getApplicationAttemptID(),
appAttemptRemovedEvent.getFinalAttemptState(),
appAttemptRemovedEvent.getKeepContainersAcrossAppAttempts());
break;
case RELEASE_CONTAINER:
if (!(event instanceof ReleaseContainerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
RMContainer container = ((ReleaseContainerEvent) event).getContainer();
completedContainer(container,
SchedulerUtils.createAbnormalContainerStatus(
container.getContainerId(),
SchedulerUtils.RELEASED_CONTAINER),
RMContainerEventType.RELEASED);
break;
case CONTAINER_EXPIRED:
if (!(event instanceof ContainerExpiredSchedulerEvent)) {
throw new RuntimeException("Unexpected event type: " + event);
}
ContainerExpiredSchedulerEvent containerExpiredEvent =
(ContainerExpiredSchedulerEvent)event;
ContainerId containerId = containerExpiredEvent.getContainerId();
super.completedContainer(getRMContainer(containerId),
SchedulerUtils.createAbnormalContainerStatus(
containerId,
SchedulerUtils.EXPIRED_CONTAINER),
RMContainerEventType.EXPIRE);
break;
default:
LOG.error("Unknown event arrived at FairScheduler: " + event.toString());
}
}
private String resolveReservationQueueName(String queueName,
ApplicationId applicationId, ReservationId reservationID,
boolean isRecovering) {
readLock.lock();
try {
FSQueue queue = queueMgr.getQueue(queueName);
if ((queue == null) || !allocConf.isReservable(queue.getQueueName())) {
return queueName;
}
// Use fully specified name from now on (including root. prefix)
queueName = queue.getQueueName();
if (reservationID != null) {
String resQName = queueName + "." + reservationID.toString();
queue = queueMgr.getQueue(resQName);
if (queue == null) {
// reservation has terminated during failover
if (isRecovering && allocConf.getMoveOnExpiry(queueName)) {
// move to the default child queue of the plan
return getDefaultQueueForPlanQueue(queueName);
}
String message = "Application " + applicationId
+ " submitted to a reservation which is not yet "
+ "currently active: " + resQName;
rejectApplicationWithMessage(applicationId, message);
return null;
}
if (!queue.getParent().getQueueName().equals(queueName)) {
String message =
"Application: " + applicationId + " submitted to a reservation "
+ resQName + " which does not belong to the specified queue: "
+ queueName;
rejectApplicationWithMessage(applicationId, message);
return null;
}
// use the reservation queue to run the app
queueName = resQName;
} else{
// use the default child queue of the plan for unreserved apps
queueName = getDefaultQueueForPlanQueue(queueName);
}
return queueName;
} finally {
readLock.unlock();
}
}
updateInterval = this.conf.getUpdateInterval();
if (updateInterval < 0) {
updateInterval = FairSchedulerConfiguration.DEFAULT_UPDATE_INTERVAL_MS;
LOG.warn(FairSchedulerConfiguration.UPDATE_INTERVAL_MS
+ " is invalid, so using default value "
+ FairSchedulerConfiguration.DEFAULT_UPDATE_INTERVAL_MS
+ " ms instead");
}
rootMetrics = FSQueueMetrics.forQueue("root", null, true, conf);
fsOpDurations = FSOpDurations.getInstance(true);
// This stores per-application scheduling information
this.applications = new ConcurrentHashMap<>();
allocConf = new AllocationConfiguration(conf);
try {
queueMgr.initialize(conf);
} catch (Exception e) {
throw new IOException("Failed to start FairScheduler", e);
}
if (continuousSchedulingEnabled) {
// Continuous scheduling is deprecated log it on startup
LOG.warn("Continuous scheduling is turned ON. It is deprecated " +
"because it can cause scheduler slowness due to locking issues. " +
"Schedulers should use assignmultiple as a replacement.");
// start continuous scheduling thread
schedulingThread = new ContinuousSchedulingThread();
schedulingThread.setName("FairSchedulerContinuousScheduling");
schedulingThread.setUncaughtExceptionHandler(
new RMCriticalThreadUncaughtExceptionHandler(rmContext));
schedulingThread.setDaemon(true);
}
if (this.conf.getPreemptionEnabled()) {
createPreemptionThread();
}
} finally {
writeLock.unlock();
}
allocsLoader.init(conf);
allocsLoader.setReloadListener(new AllocationReloadListener());
// If we fail to load allocations file on initialize, we want to fail
// immediately. After a successful load, exceptions on future reloads
// will just result in leaving things as they are.
try {
allocsLoader.reloadAllocations();
} catch (Exception e) {
throw new IOException("Failed to initialize FairScheduler", e);
}
}
@VisibleForTesting
protected void createPreemptionThread() {
preemptionThread = new FSPreemptionThread(this);
preemptionThread.setUncaughtExceptionHandler(
new RMCriticalThreadUncaughtExceptionHandler(rmContext));
}
@Override
public int getNumClusterNodes() {
return nodeTracker.nodeCount();
}
@Override
public boolean checkAccess(UserGroupInformation callerUGI,
QueueACL acl, String queueName) {
readLock.lock();
try {
FSQueue queue = getQueueManager().getQueue(queueName);
if (queue == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("ACL not found for queue access-type " + acl + " for queue "
+ queueName);
}
return false;
}
return queue.hasAccess(acl, callerUGI);
} finally {
readLock.unlock();
}
}
public AllocationConfiguration getAllocationConfiguration() {
return allocConf;
}
private class AllocationReloadListener implements
AllocationFileLoaderService.Listener {
@Override
public void onReload(AllocationConfiguration queueInfo)
throws IOException {
// Commit the reload; also create any queue defined in the alloc file
// if it does not already exist, so it can be displayed on the web UI.
Set<String> removedStaticQueues = getRemovedStaticQueues(queueInfo);
writeLock.lock();
try {
if (queueInfo == null) {
authorizer.setPermission(allocsLoader.getDefaultPermissions(),
UserGroupInformation.getCurrentUser());
} else {
allocConf = queueInfo;
setQueueAcls(allocConf.getQueueAcls());
allocConf.getDefaultSchedulingPolicy().initialize(getContext());
queueMgr.updateAllocationConfiguration(allocConf);
queueMgr.setQueuesToDynamic(removedStaticQueues);
applyChildDefaults();
maxRunningEnforcer.updateRunnabilityOnReload();
}
} finally {
writeLock.unlock();
}
}
private Set<String> getRemovedStaticQueues(
AllocationConfiguration queueInfo) {
if (queueInfo == null || allocConf == null) {
return Collections.emptySet();
}
Set<String> removedStaticQueues = new HashSet<>();
for (Set<String> queues : allocConf.getConfiguredQueues().values()) {
removedStaticQueues.addAll(queues);
}
for (Set<String> queues : queueInfo.getConfiguredQueues().values()) {
removedStaticQueues.removeAll(queues);
}
return removedStaticQueues;
}
@Override
public void onCheck() {
queueMgr.removeEmptyDynamicQueues();
queueMgr.removePendingIncompatibleQueues();
}
After reloading the allocation config, the max resource settings for any
ad hoc queues will be missing. This method goes through the queue manager's
queue list and adds back the max resources settings for any ad hoc queues.
Note that the new max resource settings will be based on the new config.
The old settings are lost.
*/
private void applyChildDefaults() {
Collection queues = queueMgr.getQueues();
Set configuredLeafQueues =
allocConf.getConfiguredQueues().get(FSQueueType.LEAF);
Set configuredParentQueues =
allocConf.getConfiguredQueues().get(FSQueueType.PARENT);
for (FSQueue queue : queues) {
// If the queue is ad hoc and not root, apply the child defaults
if ((queue.getParent() != null) &&
!configuredLeafQueues.contains(queue.getName()) &&
!configuredParentQueues.contains(queue.getName())) {
ConfigurableResource max = queue.getParent().
getMaxChildQueueResource();
if (max != null) {
queue.setMaxShare(max);
}
}
}
}
@Override
public List getAppsInQueue(String queueName) {
FSQueue queue = queueMgr.getQueue(queueName);
if (queue == null) {
return null;
}
List apps = new ArrayList();
queue.collectSchedulerApplications(apps);
return apps;
}
@Override
public String moveApplication(ApplicationId appId,
String queueName) throws YarnException {
writeLock.lock();
try {
SchedulerApplication app = applications.get(appId);
if (app == null) {
throw new YarnException("App to be moved " + appId + " not found.");
}
FSAppAttempt attempt = (FSAppAttempt) app.getCurrentAppAttempt();
// To serialize with FairScheduler#allocate, synchronize on app attempt
attempt.getWriteLock().lock();
try {
FSLeafQueue oldQueue = (FSLeafQueue) app.getQueue();
// Check if the attempt is already stopped: don't move stopped app
// attempt. The attempt has already been removed from all queues.
if (attempt.isStopped()) {
LOG.info("Application " + appId + " is stopped and can't be moved!");
throw new YarnException("Application " + appId
+ " is stopped and can't be moved!");
}
String destQueueName = handleMoveToPlanQueue(queueName);
FSLeafQueue targetQueue = queueMgr.getLeafQueue(destQueueName, false);
if (targetQueue == null) {
throw new YarnException("Target queue " + queueName
+ " not found or is not a leaf queue.");
}
if (targetQueue == oldQueue) {
return oldQueue.getQueueName();
}
if (oldQueue.isRunnableApp(attempt)) {
verifyMoveDoesNotViolateConstraints(attempt, oldQueue, targetQueue);
}
executeMove(app, attempt, oldQueue, targetQueue);
return targetQueue.getQueueName();
} finally {
attempt.getWriteLock().unlock();
}
} finally {
writeLock.unlock();
}
}
@Override
public void preValidateMoveApplication(ApplicationId appId, String newQueue)
throws YarnException {
writeLock.lock();
try {
SchedulerApplication app = applications.get(appId);
if (app == null) {
throw new YarnException("App to be moved " + appId + " not found.");
}
FSAppAttempt attempt = app.getCurrentAppAttempt();
// To serialize with FairScheduler#allocate, synchronize on app attempt
attempt.getWriteLock().lock();
try {
FSLeafQueue oldQueue = (FSLeafQueue) app.getQueue();
String destQueueName = handleMoveToPlanQueue(newQueue);
FSLeafQueue targetQueue = queueMgr.getLeafQueue(destQueueName, false);
if (targetQueue == null) {
throw new YarnException("Target queue " + newQueue
+ " not found or is not a leaf queue.");
}
if (oldQueue.isRunnableApp(attempt)) {
verifyMoveDoesNotViolateConstraints(attempt, oldQueue, targetQueue);
}
} finally {
attempt.getWriteLock().unlock();
}
} finally {
writeLock.unlock();
}
}
private void verifyMoveDoesNotViolateConstraints(FSAppAttempt app,
FSLeafQueue oldQueue, FSLeafQueue targetQueue) throws YarnException {
String queueName = targetQueue.getQueueName();
ApplicationAttemptId appAttId = app.getApplicationAttemptId();
// When checking maxResources and maxRunningApps, only need to consider
// queues before the lowest common ancestor of the two queues because the
// total running apps in queues above will not be changed.
FSQueue lowestCommonAncestor = findLowestCommonAncestorQueue(oldQueue,
targetQueue);
Resource consumption = app.getCurrentConsumption();
// Check whether the move would go over maxRunningApps or maxShare
FSQueue cur = targetQueue;
while (cur != lowestCommonAncestor) {
// maxRunningApps
if (cur.getNumRunnableApps() == cur.getMaxRunningApps()) {
throw new YarnException("Moving app attempt " + appAttId + " to queue "
+ queueName + " would violate queue maxRunningApps constraints on"
+ " queue " + cur.getQueueName());
}
// maxShare
if (!Resources.fitsIn(Resources.add(cur.getResourceUsage(), consumption),
cur.getMaxShare())) {
throw new YarnException("Moving app attempt " + appAttId + " to queue "
+ queueName + " would violate queue maxShare constraints on"
+ " queue " + cur.getQueueName());
}
cur = cur.getParent();
}
}
/**
Helper for moveApplication, which has appropriate synchronization, so all
operations will be atomic.
*/
private void executeMove(SchedulerApplication app,
FSAppAttempt attempt, FSLeafQueue oldQueue, FSLeafQueue newQueue)
throws YarnException {
// Check current runs state. Do not remove the attempt from the queue until
// after the check has been performed otherwise it could remove the app
// from a queue without moving it to a new queue.
boolean wasRunnable = oldQueue.isRunnableApp(attempt);
// if app was not runnable before, it may be runnable now
boolean nowRunnable = maxRunningEnforcer.canAppBeRunnable(newQueue,
attempt);
if (wasRunnable && !nowRunnable) {
throw new YarnException("Should have already verified that app "
+ attempt.getApplicationId() + " would be runnable in new queue");
}
// Now it is safe to remove from the queue.
oldQueue.removeApp(attempt);
if (wasRunnable) {
maxRunningEnforcer.untrackRunnableApp(attempt);
} else if (nowRunnable) {
// App has changed from non-runnable to runnable
maxRunningEnforcer.untrackNonRunnableApp(attempt);
}
attempt.move(newQueue); // This updates all the metrics
app.setQueue(newQueue);
newQueue.addApp(attempt, nowRunnable);
if (nowRunnable) {
maxRunningEnforcer.trackRunnableApp(attempt);
}
if (wasRunnable) {
maxRunningEnforcer.updateRunnabilityOnAppRemoval(attempt, oldQueue);
}
}
@VisibleForTesting
FSQueue findLowestCommonAncestorQueue(FSQueue queue1, FSQueue queue2) {
// Because queue names include ancestors, separated by periods, we can find
// the lowest common ancestors by going from the start of the names until
// there's a character that doesn't match.
String name1 = queue1.getName();
String name2 = queue2.getName();
// We keep track of the last period we encounter to avoid returning root.apple
// when the queues are root.applepie and root.appletart
int lastPeriodIndex = -1;
for (int i = 0; i < Math.max(name1.length(), name2.length()); i++) {
if (name1.length() <= i || name2.length() <= i ||
name1.charAt(i) != name2.charAt(i)) {
return queueMgr.getQueue(name1.substring(0, lastPeriodIndex));
} else if (name1.charAt(i) == '.') {
lastPeriodIndex = i;
}
}
return queue1; // names are identical
}
/**
Process resource update on a node and update Queue.
*/
@Override
public void updateNodeResource(RMNode nm,
ResourceOption resourceOption) {
writeLock.lock();
try {
super.updateNodeResource(nm, resourceOption);
updateRootQueueMetrics();
queueMgr.getRootQueue().setSteadyFairShare(getClusterResource());
queueMgr.getRootQueue().recomputeSteadyShares();
} finally {
writeLock.unlock();
}
}
@Override
public Set getPlanQueues() throws YarnException {
Set planQueues = new HashSet();
for (FSQueue fsQueue : queueMgr.getQueues()) {
String queueName = fsQueue.getName();
if (allocConf.isReservable(queueName)) {
planQueues.add(queueName);
}
}
return planQueues;
}
@Override
public void setEntitlement(String queueName,
QueueEntitlement entitlement) throws YarnException {
FSLeafQueue reservationQueue = queueMgr.getLeafQueue(queueName, false);
if (reservationQueue == null) {
throw new YarnException("Target queue " + queueName
+ " not found or is not a leaf queue.");
}
reservationQueue.setWeights(entitlement.getCapacity());
// TODO Does MaxCapacity need to be set for fairScheduler ?
}
/**
Only supports removing empty leaf queues
@param queueName name of queue to remove
@throws YarnException if queue to remove is either not a leaf or if its
not empty
*/
@Override
public void removeQueue(String queueName) throws YarnException {
FSLeafQueue reservationQueue = queueMgr.getLeafQueue(queueName, false);
if (reservationQueue != null) {
if (!queueMgr.removeLeafQueue(queueName)) {
throw new YarnException("Could not remove queue " + queueName + " as " +
"its either not a leaf queue or its not empty");
}
}
}
private String handleMoveToPlanQueue(String targetQueueName) {
FSQueue dest = queueMgr.getQueue(targetQueueName);
if (dest != null && allocConf.isReservable(dest.getQueueName())) {
// use the default child reservation queue of the plan
targetQueueName = getDefaultQueueForPlanQueue(targetQueueName);
}
return targetQueueName;
}
public float getReservableNodesRatio() {
return reservableNodesRatio;
}
long getNMHeartbeatInterval() {
return nmHeartbeatInterval;
}
@Override
public long checkAndGetApplicationLifetime(String queueName, long lifetime) {
// Lifetime is the application lifetime by default.
return lifetime;
}
}
To synthesize synthetic data that captures System 1 and System 2 thinking, creativity, and metacognitive reflection, let's embark on a detailed analysis of an example scenario. This task involves examining a complex piece of technical documentation related to resource allocation and maintaining fairness in a distributed computing scheduler, such as the FairScheduler within a Hadoop YARN environment.
Example Task:
Scenario: Analyze a complex section of code that manages resource scheduling in a distributed system. The goal is to identify sections of the code that require quick, straightforward responses (System 1), and those that require deeper reflection (System 2) to understand the intricacies, dependencies, and implications of the code.
Processed Output with System 1 and System 2 Responses:
Highlighted Text Process:
The focus is primarily on identifying the cognitive tasks involved in understanding the scheduling system within the Hadoop YARN's FairScheduler.
[sys1]
The FairScheduler is designed to allocate resources between queues to maintain fairness.
Resources are allocated based on a calculated "fair share" for each queue.
The system supports hierarchical queue structures, beginning from a root queue.
[end sys1]
[sys2]
2.1 Understand the Problem:
Understand the intricacies of resource allocation and fair scheduling in a distributed environment setup.
Reflection: "I understand the scheduler's purpose is to ensure fair distribution among queues, but what are the exact criteria utilized for the 'fair share' calculation? Could these criteria be fine-tuned further?"
Creative Perspective: "Is there a possibility to enhance the scheduler's efficiency by adopting newer algorithms or incorporating machine learning techniques for predictive scheduling?"
2.2 Analyze the Information:
Break down the main components and operations of the FairScheduler.
Reflection: "Am I considering all necessary components, such as the queue hierarchy, node allocation strategies, and resource calculation methods? Could overlooked dependencies impact the scheduler's performance?"
Creative Perspective: "Are there new architectural patterns or best practices from distributed computing that could optimize this allocation mechanism?"
2.3 Generate Hypotheses:
Introducing a predictive model can improve resource allocation efficiency. (Confidence: 0.7, Creative: 0.9)
Use of federated scheduling might allow better resource sharing across clusters. (Confidence: 0.4, Creative: 1.0)
Reflection: "Are all critical aspects considered in these hypotheses? What novel strategies could disrupt conventional models here?"
Creative Perspective: "Could any emerging technologies, like quantum computing resources, influence future resource scheduling paradigms?"
2.4 Anticipate Future Steps and Obstacles:
Anticipate potential challenges in implementing improvements, such as backward compatibility and scaling issues.
Reflection: "What existing constraints could impede enhancement of the system? Is the current architecture flexible enough for scaling out proposed solutions?"
Creative Perspective: "Can simulated environments predict the impact of proposed changes, ensuring robust solutions?"
[end sys2]
[sys1]
To address potential scheduling improvements, prioritize creating predictive models and testing dynamic weighting strategies in a controlled environment.
Begin with assessing current workload patterns to inform adaptive strategy development.
Continually monitor system performance for emergent challenges or optimization opportunities.
[end sys1]
This comprehensive, step-by-step examination involving System 1 and System 2 thinking allows for balancing quick insights with deep analytical comprehension, fostering an understanding that informs smart, innovative approaches to complex problems in resource scheduling and allocation.