Class AppPlacementAllocator<N extends SchedulerNode>
java.lang.Object
org.apache.hadoop.yarn.server.resourcemanager.scheduler.placement.AppPlacementAllocator<N>
- Direct Known Subclasses:
LocalityAppPlacementAllocator,SingleConstraintAppPlacementAllocator
This class has the following functionality:
1) Keeps track of pending resource requests when following events happen:
- New ResourceRequests are added to scheduler.
- New containers get allocated.
2) Determines the order that the nodes given in the CandidateNodeSet
will be used for allocating containers.
And different set of resource requests (E.g., resource requests with the same schedulerKey) can have one instance of AppPlacementAllocator, each AppPlacementAllocator can have different ways to order nodes depends on requests.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AppSchedulingInfoprotected RMContextprotected org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract ContainerRequestallocate(org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey schedulerKey, NodeType type, SchedulerNode node) Notify container allocated.abstract booleancanAllocate(NodeType type, SchedulerNode node) We can still have pending requirement for a given NodeType and nodeabstract booleancanDelayTo(String resourceName) Can delay to give locality?abstract intgetOutstandingAsksCount(String resourceName) Get #pending-allocations for given resourceName.abstract PendingAskgetPendingAsk(String resourceName) Get pending ask for given resourceName.intgetPreferredNodeIterator(CandidateNodeSet<N> candidateNodeSet) Get iterator of preferred node depends on requirement and/or availability.abstract StringIt is possible that one request can accept multiple node partition, So this method returns primary node partition for pending resource / headroom calculation.Get pending ResourceRequests by given schedulerRequestKeyabstract org.apache.hadoop.yarn.api.records.SchedulingRequestGet pending SchedulingRequest.abstract intvoidvoidinitialize(AppSchedulingInfo appSchedulingInfo, org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey schedulerRequestKey, RMContext rmContext) Initialize this allocator, this will be called by Factory automatically.abstract booleanprecheckNode(SchedulerNode schedulerNode, SchedulingMode schedulingMode) abstract booleanprecheckNode(SchedulerNode schedulerNode, SchedulingMode schedulingMode, Optional<DiagnosticsCollector> dcOpt) Does thisAppPlacementAllocatoraccept resources on given node?abstract voidPrint human-readable requests to LOG debug.abstract PendingAskUpdateResultupdatePendingAsk(Collection<org.apache.hadoop.yarn.api.records.ResourceRequest> requests, boolean recoverPreemptedRequestForAContainer) Replace existing pending asks by the new requestsabstract PendingAskUpdateResultupdatePendingAsk(org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey schedulerRequestKey, org.apache.hadoop.yarn.api.records.SchedulingRequest schedulingRequest, boolean recoverPreemptedRequestForAContainer) Replace existing pending asks by the new SchedulingRequest
-
Field Details
-
appSchedulingInfo
-
schedulerRequestKey
protected org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey schedulerRequestKey -
rmContext
-
-
Constructor Details
-
AppPlacementAllocator
public AppPlacementAllocator()
-
-
Method Details
-
getPreferredNodeIterator
Get iterator of preferred node depends on requirement and/or availability.- Parameters:
candidateNodeSet- input CandidateNodeSet- Returns:
- iterator of preferred node
-
updatePendingAsk
public abstract PendingAskUpdateResult updatePendingAsk(Collection<org.apache.hadoop.yarn.api.records.ResourceRequest> requests, boolean recoverPreemptedRequestForAContainer) Replace existing pending asks by the new requests- Parameters:
requests- new asksrecoverPreemptedRequestForAContainer- if we're recovering resource requests for preempted container- Returns:
- true if total pending resource changed
-
updatePendingAsk
public abstract PendingAskUpdateResult updatePendingAsk(org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey schedulerRequestKey, org.apache.hadoop.yarn.api.records.SchedulingRequest schedulingRequest, boolean recoverPreemptedRequestForAContainer) Replace existing pending asks by the new SchedulingRequest- Parameters:
schedulerRequestKey- scheduler request keyschedulingRequest- new asksrecoverPreemptedRequestForAContainer- if we're recovering resource requests for preempted container- Returns:
- true if total pending resource changed
-
getResourceRequests
public abstract Map<String,org.apache.hadoop.yarn.api.records.ResourceRequest> getResourceRequests()Get pending ResourceRequests by given schedulerRequestKey- Returns:
- Map of resourceName to ResourceRequest
-
getPendingAsk
Get pending ask for given resourceName. If there's no such pendingAsk, returnsPendingAsk.ZERO- Parameters:
resourceName- resourceName- Returns:
- PendingAsk
-
getOutstandingAsksCount
Get #pending-allocations for given resourceName. If there's no such pendingAsk, returns 0- Parameters:
resourceName- resourceName- Returns:
- #pending-allocations
-
allocate
public abstract ContainerRequest allocate(org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey schedulerKey, NodeType type, SchedulerNode node) Notify container allocated.- Parameters:
schedulerKey- SchedulerRequestKey for this ResourceRequesttype- Type of the allocationnode- Which node this container allocated on- Returns:
- ContainerRequest which include resource requests associated with
the container. This will be used by scheduler to recover requests.
Please refer to
ContainerRequestfor more details.
-
canAllocate
We can still have pending requirement for a given NodeType and node- Parameters:
type- Locality Typenode- which node we will allocate on- Returns:
- true if we has pending requirement
-
canDelayTo
Can delay to give locality? TODO: This should be moved out of AppPlacementAllocator and should belong to specific delay scheduling policy impl. See YARN-7457 for more details.- Parameters:
resourceName- resourceName- Returns:
- can/cannot
-
precheckNode
public abstract boolean precheckNode(SchedulerNode schedulerNode, SchedulingMode schedulingMode, Optional<DiagnosticsCollector> dcOpt) Does thisAppPlacementAllocatoraccept resources on given node?- Parameters:
schedulerNode- schedulerNodeschedulingMode- schedulingModedcOpt- optional diagnostics collector- Returns:
- accepted/not
-
precheckNode
-
getPrimaryRequestedNodePartition
It is possible that one request can accept multiple node partition, So this method returns primary node partition for pending resource / headroom calculation.- Returns:
- primary requested node partition
-
getUniqueLocationAsks
public abstract int getUniqueLocationAsks()- Returns:
- number of unique location asks with #pending greater than 0, (like /rack1, host1, etc.). TODO: This should be moved out of AppPlacementAllocator and should belong to specific delay scheduling policy impl. See YARN-7457 for more details.
-
showRequests
public abstract void showRequests()Print human-readable requests to LOG debug. -
initialize
public void initialize(AppSchedulingInfo appSchedulingInfo, org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey schedulerRequestKey, RMContext rmContext) Initialize this allocator, this will be called by Factory automatically.- Parameters:
appSchedulingInfo- appSchedulingInfoschedulerRequestKey- schedulerRequestKeyrmContext- rmContext
-
getSchedulingRequest
public abstract org.apache.hadoop.yarn.api.records.SchedulingRequest getSchedulingRequest()Get pending SchedulingRequest.- Returns:
- SchedulingRequest
-
getPlacementAttempt
public int getPlacementAttempt() -
incrementPlacementAttempt
public void incrementPlacementAttempt()
-