java.lang.Object
org.apache.hadoop.service.AbstractService
org.apache.hadoop.yarn.server.resourcemanager.scheduler.AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
org.apache.hadoop.yarn.server.resourcemanager.scheduler.fair.FairScheduler
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.hadoop.service.Service, org.apache.hadoop.yarn.event.EventHandler<SchedulerEvent>, Recoverable, ResourceScheduler, YarnScheduler

@LimitedPrivate("yarn") @Unstable public class FairScheduler extends AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
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".
  • Field Details

    • CONTAINER_RESERVED

      public static final org.apache.hadoop.yarn.api.records.Resource CONTAINER_RESERVED
    • sizeBasedWeight

      protected boolean sizeBasedWeight
    • continuousSchedulingEnabled

      @Deprecated protected boolean continuousSchedulingEnabled
      Deprecated.
    • continuousSchedulingSleepMs

      @Deprecated protected volatile int continuousSchedulingSleepMs
      Deprecated.
    • nodeLocalityThreshold

      protected double nodeLocalityThreshold
    • rackLocalityThreshold

      protected double rackLocalityThreshold
    • nodeLocalityDelayMs

      @Deprecated protected long nodeLocalityDelayMs
      Deprecated.
    • rackLocalityDelayMs

      @Deprecated protected long rackLocalityDelayMs
      Deprecated.
    • assignMultiple

      protected boolean assignMultiple
    • maxAssign

      protected int maxAssign
  • Constructor Details

    • FairScheduler

      public FairScheduler()
  • Method Details

    • getContext

      public FSContext getContext()
    • getRMContext

      public RMContext getRMContext()
    • isAtLeastReservationThreshold

      public boolean isAtLeastReservationThreshold(org.apache.hadoop.yarn.util.resource.ResourceCalculator resourceCalculator, org.apache.hadoop.yarn.api.records.Resource resource)
    • getConf

      public FairSchedulerConfiguration getConf()
    • getNumNodesInRack

      public int getNumNodesInRack(String rackName)
    • getQueueManager

      public QueueManager getQueueManager()
    • update

      @VisibleForTesting public void update()
      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.
      Overrides:
      update in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
    • getContainerTokenSecretManager

      public RMContainerTokenSecretManager getContainerTokenSecretManager()
    • isSizeBasedWeight

      public boolean isSizeBasedWeight()
    • getIncrementResourceCapability

      public org.apache.hadoop.yarn.api.records.Resource getIncrementResourceCapability()
    • getNodeLocalityThreshold

      public double getNodeLocalityThreshold()
    • getRackLocalityThreshold

      public double getRackLocalityThreshold()
    • getNodeLocalityDelayMs

      @Deprecated public long getNodeLocalityDelayMs()
      Deprecated.
      linked to isContinuousSchedulingEnabled() deprecation
      Delay in milliseconds for locality fallback node to rack.
      Returns:
      delay in ms
    • getRackLocalityDelayMs

      @Deprecated public long getRackLocalityDelayMs()
      Deprecated.
      linked to isContinuousSchedulingEnabled() deprecation
      Delay in milliseconds for locality fallback rack to other.
      Returns:
      delay in ms
    • isContinuousSchedulingEnabled

      @Deprecated public boolean isContinuousSchedulingEnabled()
      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.
      Whether continuous scheduling is turned on.
      Returns:
      whether continuous scheduling is enabled
    • getContinuousSchedulingSleepMs

      @Deprecated public int getContinuousSchedulingSleepMs()
      Deprecated.
      linked to isContinuousSchedulingEnabled() deprecation
      The sleep time of the continuous scheduler thread.
      Returns:
      sleep time in ms
    • addApplication

      protected void addApplication(org.apache.hadoop.yarn.api.records.ApplicationId applicationId, String queueName, String user, boolean isAppRecovering, ApplicationPlacementContext placementContext)
      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.
      Parameters:
      applicationId - applicationId.
      queueName - queue name.
      user - submit application user.
      isAppRecovering - true, app recover; false, app not recover.
      placementContext - application placement context.
    • addApplicationAttempt

      protected void addApplicationAttempt(org.apache.hadoop.yarn.api.records.ApplicationAttemptId applicationAttemptId, boolean transferStateFromPreviousAttempt, boolean isAttemptRecovering)
      Add a new application attempt to the scheduler.
      Parameters:
      applicationAttemptId - application AttemptId.
      transferStateFromPreviousAttempt - transferStateFromPreviousAttempt.
      isAttemptRecovering - true, attempt recovering;false, attempt not recovering.
    • completedContainerInternal

      protected void completedContainerInternal(RMContainer rmContainer, org.apache.hadoop.yarn.api.records.ContainerStatus containerStatus, RMContainerEventType event)
      Clean up a completed container.
      Specified by:
      completedContainerInternal in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
    • getNormalizedResource

      public org.apache.hadoop.yarn.api.records.Resource getNormalizedResource(org.apache.hadoop.yarn.api.records.Resource requestedResource, org.apache.hadoop.yarn.api.records.Resource maxResourceCapability)
      Description copied from interface: YarnScheduler
      Normalize a resource request using scheduler level maximum resource or queue based maximum resource.
      Specified by:
      getNormalizedResource in interface YarnScheduler
      Overrides:
      getNormalizedResource in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      requestedResource - the resource to be normalized
      maxResourceCapability - Maximum container allocation value, if null or empty scheduler level maximum container allocation value will be used
      Returns:
      the normalized resource
    • getMaximumResourceCapability

      public org.apache.hadoop.yarn.api.records.Resource getMaximumResourceCapability(String queueName)
      Description copied from interface: YarnScheduler
      Get maximum allocatable Resource for the queue specified.
      Specified by:
      getMaximumResourceCapability in interface YarnScheduler
      Overrides:
      getMaximumResourceCapability in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      queueName - queue name
      Returns:
      maximum allocatable resource
    • killContainer

      @VisibleForTesting public void killContainer(RMContainer container)
      Description copied from class: AbstractYarnScheduler
      Kill a RMContainer. This is meant to be called in tests only to simulate AM container failures.
      Specified by:
      killContainer in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      container - the container to kill
    • allocate

      public Allocation allocate(org.apache.hadoop.yarn.api.records.ApplicationAttemptId appAttemptId, List<org.apache.hadoop.yarn.api.records.ResourceRequest> ask, List<org.apache.hadoop.yarn.api.records.SchedulingRequest> schedulingRequests, List<org.apache.hadoop.yarn.api.records.ContainerId> release, List<String> blacklistAdditions, List<String> blacklistRemovals, ContainerUpdates updateRequests)
      Description copied from interface: YarnScheduler
      The main API between the ApplicationMaster and the Scheduler. The ApplicationMaster may request/update container resources, number of containers, node/rack preference for allocations etc. to the Scheduler.
      Parameters:
      appAttemptId - the id of the application attempt.
      ask - the request made by an application to obtain various allocations like host/rack, resource, number of containers, relaxLocality etc., see ResourceRequest.
      schedulingRequests - similar to ask, but with added ability to specify allocation tags etc., see SchedulingRequest.
      release - the list of containers to be released.
      blacklistAdditions - places (node/rack) to be added to the blacklist.
      blacklistRemovals - places (node/rack) to be removed from the blacklist.
      updateRequests - container promotion/demotion updates.
      Returns:
      the Allocation for the application.
    • nodeUpdate

      protected void nodeUpdate(RMNode nm)
      Description copied from class: AbstractYarnScheduler
      Process a heartbeat update from a node.
      Overrides:
      nodeUpdate in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      nm - The RMNode corresponding to the NodeManager
    • getSchedulerApp

      public FSAppAttempt getSchedulerApp(org.apache.hadoop.yarn.api.records.ApplicationAttemptId appAttemptId)
    • getResourceCalculator

      public org.apache.hadoop.yarn.util.resource.ResourceCalculator getResourceCalculator()
    • getRootQueueMetrics

      public QueueMetrics getRootQueueMetrics()
      Description copied from interface: YarnScheduler
      Get the root queue for the scheduler.
      Returns:
      the root queue for the scheduler.
    • handle

      public void handle(SchedulerEvent event)
    • recover

      public void recover(RMStateStore.RMState state) throws Exception
      Throws:
      Exception
    • setRMContext

      public void setRMContext(RMContext rmContext)
      Description copied from interface: ResourceScheduler
      Set RMContext for ResourceScheduler. This method should be called immediately after instantiating a scheduler once.
      Parameters:
      rmContext - created by ResourceManager
    • createPreemptionThread

      @VisibleForTesting protected void createPreemptionThread()
    • serviceInit

      public void serviceInit(org.apache.hadoop.conf.Configuration conf) throws Exception
      Overrides:
      serviceInit in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Throws:
      Exception
    • serviceStart

      public void serviceStart() throws Exception
      Overrides:
      serviceStart in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Throws:
      Exception
    • serviceStop

      public void serviceStop() throws Exception
      Overrides:
      serviceStop in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Throws:
      Exception
    • reinitialize

      public void reinitialize(org.apache.hadoop.conf.Configuration conf, RMContext rmContext) throws IOException
      Description copied from interface: ResourceScheduler
      Re-initialize the ResourceScheduler.
      Specified by:
      reinitialize in interface ResourceScheduler
      Overrides:
      reinitialize in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      conf - configuration
      rmContext - RMContext.
      Throws:
      IOException - an I/O exception has occurred.
    • getQueueInfo

      public org.apache.hadoop.yarn.api.records.QueueInfo getQueueInfo(String queueName, boolean includeChildQueues, boolean recursive) throws IOException
      Description copied from interface: YarnScheduler
      Get queue information.
      Parameters:
      queueName - queue name
      includeChildQueues - include child queues?
      recursive - get children queues?
      Returns:
      queue information
      Throws:
      IOException - an I/O exception has occurred.
    • getQueueUserAclInfo

      public List<org.apache.hadoop.yarn.api.records.QueueUserACLInfo> getQueueUserAclInfo()
      Description copied from interface: YarnScheduler
      Get acls for queues for current user.
      Returns:
      acls for queues for current user
    • getNumClusterNodes

      public int getNumClusterNodes()
      Description copied from interface: YarnScheduler
      Get the number of nodes available in the cluster.
      Returns:
      the number of available nodes.
    • checkAccess

      public boolean checkAccess(org.apache.hadoop.security.UserGroupInformation callerUGI, org.apache.hadoop.yarn.api.records.QueueACL acl, String queueName)
      Description copied from interface: YarnScheduler
      Check if the user has permission to perform the operation. If the user has QueueACL.ADMINISTER_QUEUE permission, this user can view/modify the applications in this queue.
      Parameters:
      callerUGI - caller UserGroupInformation.
      acl - queue ACL.
      queueName - queue Name.
      Returns:
      true if the user has the permission, false otherwise
    • getAllocationConfiguration

      public AllocationConfiguration getAllocationConfiguration()
    • getAppsInQueue

      public List<org.apache.hadoop.yarn.api.records.ApplicationAttemptId> getAppsInQueue(String queueName)
      Description copied from interface: YarnScheduler
      Gets the apps under a given queue
      Parameters:
      queueName - the name of the queue.
      Returns:
      a collection of app attempt ids in the given queue.
    • moveApplication

      public String moveApplication(org.apache.hadoop.yarn.api.records.ApplicationId appId, String queueName) throws org.apache.hadoop.yarn.exceptions.YarnException
      Description copied from interface: YarnScheduler
      Moves the given application to the given queue.
      Specified by:
      moveApplication in interface YarnScheduler
      Overrides:
      moveApplication in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      appId - application Id
      queueName - the given queue.
      Returns:
      the name of the queue the application was placed into
      Throws:
      org.apache.hadoop.yarn.exceptions.YarnException - if the move cannot be carried out
    • preValidateMoveApplication

      public void preValidateMoveApplication(org.apache.hadoop.yarn.api.records.ApplicationId appId, String newQueue) throws org.apache.hadoop.yarn.exceptions.YarnException
      Perform pre-checks while moving the application. This should not check any application values that can change since the check is not part of an atomic action. During a move the scheduler can still assign containers and the app can still be updated until the real move is performed under proper locking.
      Specified by:
      preValidateMoveApplication in interface YarnScheduler
      Overrides:
      preValidateMoveApplication in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      appId - The ID of the app to be moved
      newQueue - The name of the queue the app should move to
      Throws:
      org.apache.hadoop.yarn.exceptions.YarnException - if the validate fails
    • updateNodeResource

      public void updateNodeResource(RMNode nm, org.apache.hadoop.yarn.api.records.ResourceOption resourceOption)
      Process resource update on a node and update Queue.
      Overrides:
      updateNodeResource in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      nm - RMNode.
      resourceOption - resourceOption.
    • getSchedulingResourceTypes

      public EnumSet<org.apache.hadoop.yarn.proto.YarnServiceProtos.SchedulerResourceTypes> getSchedulingResourceTypes()
      Return a collection of the resource types that are considered when scheduling
      Specified by:
      getSchedulingResourceTypes in interface YarnScheduler
      Overrides:
      getSchedulingResourceTypes in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Returns:
      an EnumSet containing the resource types
    • getPlanQueues

      public Set<String> getPlanQueues() throws org.apache.hadoop.yarn.exceptions.YarnException
      Description copied from interface: YarnScheduler
      Gets the list of names for queues managed by the Reservation System.
      Specified by:
      getPlanQueues in interface YarnScheduler
      Overrides:
      getPlanQueues in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Returns:
      the list of queues which support reservations
      Throws:
      org.apache.hadoop.yarn.exceptions.YarnException - when yarn exception occur.
    • setEntitlement

      public void setEntitlement(String queueName, QueueEntitlement entitlement) throws org.apache.hadoop.yarn.exceptions.YarnException
      Description copied from interface: YarnScheduler
      This method increase the entitlement for current queue (must respect invariants, e.g., no overcommit of parents, non negative, etc.). Entitlement is a general term for weights in FairScheduler, capacity for the CapacityScheduler, etc.
      Specified by:
      setEntitlement in interface YarnScheduler
      Overrides:
      setEntitlement in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      queueName - the queue for which we change entitlement
      entitlement - the new entitlement for the queue (capacity, maxCapacity, etc..)
      Throws:
      org.apache.hadoop.yarn.exceptions.YarnException - when yarn exception occur.
    • removeQueue

      public void removeQueue(String queueName) throws org.apache.hadoop.yarn.exceptions.YarnException
      Only supports removing empty leaf queues
      Specified by:
      removeQueue in interface YarnScheduler
      Overrides:
      removeQueue in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      queueName - name of queue to remove
      Throws:
      org.apache.hadoop.yarn.exceptions.YarnException - if queue to remove is either not a leaf or if its not empty
    • getReservableNodesRatio

      public float getReservableNodesRatio()
    • checkAndGetApplicationLifetime

      public long checkAndGetApplicationLifetime(String queueName, long lifetime, RMAppImpl app)
      Description copied from interface: YarnScheduler
      Verify whether a submitted application lifetime is valid as per configured Queue lifetime.
      Specified by:
      checkAndGetApplicationLifetime in interface YarnScheduler
      Overrides:
      checkAndGetApplicationLifetime in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      queueName - Name of the Queue
      lifetime - configured application lifetime
      app - details of app
      Returns:
      valid lifetime as per queue
    • updateApplicationPriority

      public org.apache.hadoop.yarn.api.records.Priority updateApplicationPriority(org.apache.hadoop.yarn.api.records.Priority newPriority, org.apache.hadoop.yarn.api.records.ApplicationId applicationId, org.apache.hadoop.thirdparty.com.google.common.util.concurrent.SettableFuture<Object> future, org.apache.hadoop.security.UserGroupInformation user) throws org.apache.hadoop.yarn.exceptions.YarnException
      Description copied from interface: YarnScheduler
      Change application priority of a submitted application at runtime
      Specified by:
      updateApplicationPriority in interface YarnScheduler
      Overrides:
      updateApplicationPriority in class AbstractYarnScheduler<FSAppAttempt,FSSchedulerNode>
      Parameters:
      newPriority - Submitted Application priority.
      applicationId - Application ID
      future - Sets any type of exception happened from StateStore
      user - who submitted the application
      Returns:
      updated priority
      Throws:
      org.apache.hadoop.yarn.exceptions.YarnException - when yarn exception occur.
    • isNoTerminalRuleCheck

      public boolean isNoTerminalRuleCheck()