Class DefaultDeclarativeSlotPool
- All Implemented Interfaces:
DeclarativeSlotPool
- Direct Known Subclasses:
BlocklistDeclarativeSlotPool
DeclarativeSlotPool implementation.
The implementation collects the current resource requirements and declares them at the ResourceManager. Whenever new slots are offered, the slot pool compares the offered slots to the set of available and required resources and only accepts those slots which are required.
Slots which are released won't be returned directly to their owners. Instead, the slot pool implementation will only return them after the idleSlotTimeout has been exceeded by a free slot.
The slot pool will call newSlotsListener whenever newly offered slots are accepted or
if an allocated slot should become free after it is being freed.
This class expects 1 of 2 access patterns for changing requirements, which should not be mixed:
1) the legacy approach (used by the DefaultScheduler) tightly couples requirements to reserved
slots. When a slot is requested it increases the requirements, when the slot is freed they are
decreased again. In the general case what happens is that requirements are increased, a free slot
is reserved, (the slot is used for a bit,) the slot is freed, the requirements are reduced. To
this end freeReservedSlot(org.apache.flink.runtime.clusterframework.types.AllocationID, java.lang.Throwable, long), releaseSlot(org.apache.flink.runtime.clusterframework.types.AllocationID, java.lang.Exception) and releaseSlots(org.apache.flink.runtime.clusterframework.types.ResourceID, java.lang.Exception) return a
ResourceCounter describing which requirement the slot(s) were fulfilling, with the
expectation that the scheduler will subsequently decrease the requirements by that amount.
2) The declarative approach (used by the AdaptiveScheduler) in contrast derives requirements exclusively based on what a given job currently requires. It may repeatedly reserve/free slots without any modifications to the requirements.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.flink.runtime.jobmaster.slotpool.DeclarativeSlotPool
DeclarativeSlotPool.NewSlotsListener, DeclarativeSlotPool.NoOpNewSlotsListener -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.slf4j.Loggerprotected final AllocatedSlotPool -
Constructor Summary
ConstructorsConstructorDescriptionDefaultDeclarativeSlotPool(org.apache.flink.api.common.JobID jobId, AllocatedSlotPool slotPool, Consumer<? super Collection<ResourceRequirement>> notifyNewResourceRequirements, Duration idleSlotTimeout, Duration rpcTimeout, Duration slotRequestMaxInterval, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor componentMainThreadExecutor) -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsFreeSlot(AllocationID allocationId) Checks whether the slot pool contains a slot with the givenAllocationIDand if it is free.booleancontainsSlots(ResourceID owner) Returns whether the slot pool has a slot registered which is owned by the given TaskExecutor.voiddecreaseResourceRequirementsBy(ResourceCounter decrement) Decreases the resource requirements by decrement.freeReservedSlot(AllocationID allocationId, Throwable cause, long currentTime) Frees the reserved slot identified by the given allocationId.Collection<? extends SlotInfo>Returns the slot information for all slots (free and allocated slots).Returns the free slot tracker.Returns the current resource requirements.voidincreaseResourceRequirementsBy(ResourceCounter increment) Increases the resource requirements by increment.offerSlots(Collection<? extends SlotOffer> offers, TaskManagerLocation taskManagerLocation, TaskManagerGateway taskManagerGateway, long currentTime) Offers slots to this slot pool.voidregisterNewSlotsListener(DeclarativeSlotPool.NewSlotsListener newSlotsListener) Registers a listener which is called whenever new slots become available.registerSlots(Collection<? extends SlotOffer> slots, TaskManagerLocation taskManagerLocation, TaskManagerGateway taskManagerGateway, long currentTime) Registers the given set of slots at the slot pool.voidreleaseIdleSlots(long currentTimeMillis) Releases slots which have exceeded the idle slot timeout and are no longer needed to fulfill the resource requirements.releaseSlot(AllocationID allocationId, Exception cause) Releases the slot specified by allocationId if one exists.releaseSlots(ResourceID owner, Exception cause) Releases all slots belonging to the owning TaskExecutor if it has been registered.reserveFreeSlot(AllocationID allocationId, ResourceProfile requiredSlotProfile) Reserves the free slot identified by the given allocationId and maps it to the given requiredSlotProfile.voidsetResourceRequirements(ResourceCounter resourceRequirements) Sets the resource requirements to the given resourceRequirements.
-
Field Details
-
log
protected final org.slf4j.Logger log -
slotPool
-
-
Constructor Details
-
DefaultDeclarativeSlotPool
public DefaultDeclarativeSlotPool(org.apache.flink.api.common.JobID jobId, AllocatedSlotPool slotPool, Consumer<? super Collection<ResourceRequirement>> notifyNewResourceRequirements, Duration idleSlotTimeout, Duration rpcTimeout, Duration slotRequestMaxInterval, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor componentMainThreadExecutor)
-
-
Method Details
-
increaseResourceRequirementsBy
Description copied from interface:DeclarativeSlotPoolIncreases the resource requirements by increment.- Specified by:
increaseResourceRequirementsByin interfaceDeclarativeSlotPool- Parameters:
increment- increment by which to increase the resource requirements
-
decreaseResourceRequirementsBy
Description copied from interface:DeclarativeSlotPoolDecreases the resource requirements by decrement.- Specified by:
decreaseResourceRequirementsByin interfaceDeclarativeSlotPool- Parameters:
decrement- decrement by which to decrease the resource requirements
-
setResourceRequirements
Description copied from interface:DeclarativeSlotPoolSets the resource requirements to the given resourceRequirements.- Specified by:
setResourceRequirementsin interfaceDeclarativeSlotPool- Parameters:
resourceRequirements- new resource requirements
-
getResourceRequirements
Description copied from interface:DeclarativeSlotPoolReturns the current resource requirements.- Specified by:
getResourceRequirementsin interfaceDeclarativeSlotPool- Returns:
- current resource requirements
-
offerSlots
public Collection<SlotOffer> offerSlots(Collection<? extends SlotOffer> offers, TaskManagerLocation taskManagerLocation, TaskManagerGateway taskManagerGateway, long currentTime) Description copied from interface:DeclarativeSlotPoolOffers slots to this slot pool. The slot pool is free to accept as many slots as it needs.- Specified by:
offerSlotsin interfaceDeclarativeSlotPool- Parameters:
offers- offers containing the list of slots offered to this slot pooltaskManagerLocation- taskManagerLocation is the location of the offering TaskExecutortaskManagerGateway- taskManagerGateway is the gateway to talk to the offering TaskExecutorcurrentTime- currentTime is the time the slots are being offered- Returns:
- collection of accepted slots; the other slot offers are implicitly rejected
-
registerSlots
public Collection<SlotOffer> registerSlots(Collection<? extends SlotOffer> slots, TaskManagerLocation taskManagerLocation, TaskManagerGateway taskManagerGateway, long currentTime) Description copied from interface:DeclarativeSlotPoolRegisters the given set of slots at the slot pool. The slot pool will try to accept all slots unless the slot is unavailable (for example, the TaskManger is blocked).The difference from
DeclarativeSlotPool.offerSlots(java.util.Collection<? extends org.apache.flink.runtime.taskexecutor.slot.SlotOffer>, org.apache.flink.runtime.taskmanager.TaskManagerLocation, org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway, long)is that this method allows accepting slots which exceed the currently required, but theDeclarativeSlotPool.offerSlots(java.util.Collection<? extends org.apache.flink.runtime.taskexecutor.slot.SlotOffer>, org.apache.flink.runtime.taskmanager.TaskManagerLocation, org.apache.flink.runtime.jobmanager.slots.TaskManagerGateway, long)only accepts those slots that are currently required.- Specified by:
registerSlotsin interfaceDeclarativeSlotPool- Parameters:
slots- slots to registertaskManagerLocation- taskManagerLocation is the location of the offering TaskExecutortaskManagerGateway- taskManagerGateway is the gateway to talk to the offering TaskExecutorcurrentTime- currentTime is the time the slots are being offered- Returns:
- the successfully registered slots; the other slot offers are implicitly rejected
-
reserveFreeSlot
Description copied from interface:DeclarativeSlotPoolReserves the free slot identified by the given allocationId and maps it to the given requiredSlotProfile.- Specified by:
reserveFreeSlotin interfaceDeclarativeSlotPool- Parameters:
allocationId- allocationId identifies the free slot to allocaterequiredSlotProfile- requiredSlotProfile specifying the resource requirement- Returns:
- a PhysicalSlot representing the allocated slot
-
freeReservedSlot
public ResourceCounter freeReservedSlot(AllocationID allocationId, @Nullable Throwable cause, long currentTime) Description copied from interface:DeclarativeSlotPoolFrees the reserved slot identified by the given allocationId. If no slot with allocationId exists, then the call is ignored.Whether the freed slot is returned to the owning TaskExecutor is implementation dependent.
- Specified by:
freeReservedSlotin interfaceDeclarativeSlotPool- Parameters:
allocationId- allocationId identifying the slot to releasecause- cause for releasing the slot; can benullcurrentTime- currentTime when the slot was released- Returns:
- the resource requirements that the slot was fulfilling
-
registerNewSlotsListener
Description copied from interface:DeclarativeSlotPoolRegisters a listener which is called whenever new slots become available.- Specified by:
registerNewSlotsListenerin interfaceDeclarativeSlotPool- Parameters:
newSlotsListener- which is called whenever new slots become available
-
releaseSlots
Description copied from interface:DeclarativeSlotPoolReleases all slots belonging to the owning TaskExecutor if it has been registered.- Specified by:
releaseSlotsin interfaceDeclarativeSlotPool- Parameters:
owner- owner identifying the owning TaskExecutorcause- cause for failing the slots- Returns:
- the resource requirements that all slots were fulfilling; empty if all slots were currently free
-
releaseSlot
Description copied from interface:DeclarativeSlotPoolReleases the slot specified by allocationId if one exists.- Specified by:
releaseSlotin interfaceDeclarativeSlotPool- Parameters:
allocationId- allocationId identifying the slot to failcause- cause for failing the slot- Returns:
- the resource requirements that the slot was fulfilling; empty if the slot was currently free
-
releaseIdleSlots
public void releaseIdleSlots(long currentTimeMillis) Description copied from interface:DeclarativeSlotPoolReleases slots which have exceeded the idle slot timeout and are no longer needed to fulfill the resource requirements.- Specified by:
releaseIdleSlotsin interfaceDeclarativeSlotPool- Parameters:
currentTimeMillis- current time
-
getFreeSlotTracker
Description copied from interface:DeclarativeSlotPoolReturns the free slot tracker.- Specified by:
getFreeSlotTrackerin interfaceDeclarativeSlotPool- Returns:
- free slot tracker
-
getAllSlotsInformation
Description copied from interface:DeclarativeSlotPoolReturns the slot information for all slots (free and allocated slots).- Specified by:
getAllSlotsInformationin interfaceDeclarativeSlotPool- Returns:
- collection of slot information
-
containsFreeSlot
Description copied from interface:DeclarativeSlotPoolChecks whether the slot pool contains a slot with the givenAllocationIDand if it is free.- Specified by:
containsFreeSlotin interfaceDeclarativeSlotPool- Parameters:
allocationId- allocationId specifies the slot to check for- Returns:
trueif the slot pool contains a free slot registered under the given allocation id; otherwisefalse
-
containsSlots
Description copied from interface:DeclarativeSlotPoolReturns whether the slot pool has a slot registered which is owned by the given TaskExecutor.- Specified by:
containsSlotsin interfaceDeclarativeSlotPool- Parameters:
owner- owner identifying the TaskExecutor for which to check whether the slot pool has some slots registered- Returns:
- true if the given TaskExecutor has a slot registered at the slot pool
-