public class Scheduler extends Object implements InstanceListener, SlotAvailabilityListener, SlotProvider
The scheduler supports two scheduling modes:
NoResourceAvailableException
.Constructor and Description |
---|
Scheduler(Executor executor)
Creates a new scheduler.
|
Modifier and Type | Method and Description |
---|---|
CompletableFuture<LogicalSlot> |
allocateSlot(SlotRequestId slotRequestId,
ScheduledUnit task,
boolean allowQueued,
SlotProfile slotProfile,
Time allocationTimeout)
Allocating slot with specific requirement.
|
CompletableFuture<Acknowledge> |
cancelSlotRequest(SlotRequestId slotRequestId,
SlotSharingGroupId slotSharingGroupId,
Throwable cause)
Cancels the slot request with the given
SlotRequestId and SlotSharingGroupId . |
protected SimpleSlot |
getFreeSlotForTask(ExecutionVertex vertex,
Iterable<TaskManagerLocation> requestedLocations,
boolean localOnly)
Gets a suitable instance to schedule the vertex execution to.
|
Instance |
getInstance(ResourceID resourceId) |
Map<String,List<Instance>> |
getInstancesByHost() |
protected SimpleSlot |
getNewSlotForSharingGroup(ExecutionVertex vertex,
Iterable<TaskManagerLocation> requestedLocations,
SlotSharingGroupAssignment groupAssignment,
CoLocationConstraint constraint,
boolean localOnly)
Tries to allocate a new slot for a vertex that is part of a slot sharing group.
|
int |
getNumberOfAvailableInstances() |
int |
getNumberOfAvailableSlots()
NOTE: In the presence of multi-threaded operations, this number may be inexact.
|
int |
getNumberOfInstancesWithAvailableSlots() |
int |
getNumberOfLocalizedAssignments() |
int |
getNumberOfNonLocalizedAssignments() |
int |
getNumberOfUnconstrainedAssignments() |
int |
getTotalNumberOfSlots() |
void |
instanceDied(Instance instance)
Called when an instance died.
|
void |
newInstanceAvailable(Instance instance)
Called when a new instance becomes available.
|
void |
newSlotAvailable(Instance instance) |
void |
shutdown()
Shuts the scheduler down.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
allocateSlot
public Scheduler(Executor executor)
public void shutdown()
public CompletableFuture<LogicalSlot> allocateSlot(SlotRequestId slotRequestId, ScheduledUnit task, boolean allowQueued, SlotProfile slotProfile, Time allocationTimeout)
SlotProvider
allocateSlot
in interface SlotProvider
slotRequestId
- identifying the slot requesttask
- The task to allocate the slot forallowQueued
- Whether allow the task be queued if we do not have enough resourceslotProfile
- profile of the requested slotallocationTimeout
- after which the allocation fails with a timeout exceptionpublic CompletableFuture<Acknowledge> cancelSlotRequest(SlotRequestId slotRequestId, @Nullable SlotSharingGroupId slotSharingGroupId, Throwable cause)
SlotProvider
SlotRequestId
and SlotSharingGroupId
.cancelSlotRequest
in interface SlotProvider
slotRequestId
- identifying the slot request to cancelslotSharingGroupId
- identifying the slot request to cancelcause
- of the cancellationprotected SimpleSlot getFreeSlotForTask(ExecutionVertex vertex, Iterable<TaskManagerLocation> requestedLocations, boolean localOnly)
NOTE: This method does is not thread-safe, it needs to be synchronized by the caller.
vertex
- The task to run.null
, if no instance is available.protected SimpleSlot getNewSlotForSharingGroup(ExecutionVertex vertex, Iterable<TaskManagerLocation> requestedLocations, SlotSharingGroupAssignment groupAssignment, CoLocationConstraint constraint, boolean localOnly)
This method will try to allocate a slot from one of the local instances, and fall back to non-local instances, if permitted.
vertex
- The vertex to allocate the slot for.requestedLocations
- The locations that are considered local. May be null or empty, if the
vertex has no location preferences.groupAssignment
- The slot sharing group of the vertex. Mandatory parameter.constraint
- The co-location constraint of the vertex. May be null.localOnly
- Flag to indicate if non-local choices are acceptable.null
, if no slot is available.public void newSlotAvailable(Instance instance)
newSlotAvailable
in interface SlotAvailabilityListener
public void newInstanceAvailable(Instance instance)
InstanceListener
newInstanceAvailable
in interface InstanceListener
instance
- The instance that became available.public void instanceDied(Instance instance)
InstanceListener
instanceDied
in interface InstanceListener
instance
- The instance that died.public int getNumberOfAvailableSlots()
public int getTotalNumberOfSlots()
public int getNumberOfAvailableInstances()
public int getNumberOfInstancesWithAvailableSlots()
public int getNumberOfUnconstrainedAssignments()
public int getNumberOfLocalizedAssignments()
public int getNumberOfNonLocalizedAssignments()
@VisibleForTesting @Nullable public Instance getInstance(ResourceID resourceId)
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.