Interface DeclarativeSlotPool
-
- All Known Implementing Classes:
BlocklistDeclarativeSlotPool
,DefaultDeclarativeSlotPool
public interface DeclarativeSlotPool
Slot pool interface which uses Flink's declarative resource management protocol to acquire resources.In order to acquire new resources, users need to increase the required resources. Once they no longer need the resources, users need to decrease the required resources so that superfluous resources can be returned.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
DeclarativeSlotPool.NewSlotsListener
Listener interface for newly available slots.static class
DeclarativeSlotPool.NoOpNewSlotsListener
No-opDeclarativeSlotPool.NewSlotsListener
implementation.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
containsFreeSlot(AllocationID allocationId)
Checks whether the slot pool contains a slot with the givenAllocationID
and if it is free.boolean
containsSlots(ResourceID owner)
Returns whether the slot pool has a slot registered which is owned by the given TaskExecutor.void
decreaseResourceRequirementsBy(ResourceCounter decrement)
Decreases the resource requirements by decrement.ResourceCounter
freeReservedSlot(AllocationID allocationId, Throwable cause, long currentTime)
Frees the reserved slot identified by the given allocationId.Collection<? extends SlotInfo>
getAllSlotsInformation()
Returns the slot information for all slots (free and allocated slots).FreeSlotTracker
getFreeSlotTracker()
Returns the free slot tracker.Collection<ResourceRequirement>
getResourceRequirements()
Returns the current resource requirements.void
increaseResourceRequirementsBy(ResourceCounter increment)
Increases the resource requirements by increment.Collection<SlotOffer>
offerSlots(Collection<? extends SlotOffer> offers, TaskManagerLocation taskManagerLocation, TaskManagerGateway taskManagerGateway, long currentTime)
Offers slots to this slot pool.void
registerNewSlotsListener(DeclarativeSlotPool.NewSlotsListener listener)
Registers a listener which is called whenever new slots become available.Collection<SlotOffer>
registerSlots(Collection<? extends SlotOffer> slots, TaskManagerLocation taskManagerLocation, TaskManagerGateway taskManagerGateway, long currentTime)
Registers the given set of slots at the slot pool.void
releaseIdleSlots(long currentTimeMillis)
Releases slots which have exceeded the idle slot timeout and are no longer needed to fulfill the resource requirements.ResourceCounter
releaseSlot(AllocationID allocationId, Exception cause)
Releases the slot specified by allocationId if one exists.ResourceCounter
releaseSlots(ResourceID owner, Exception cause)
Releases all slots belonging to the owning TaskExecutor if it has been registered.PhysicalSlot
reserveFreeSlot(AllocationID allocationId, ResourceProfile requiredSlotProfile)
Reserves the free slot identified by the given allocationId and maps it to the given requiredSlotProfile.void
setResourceRequirements(ResourceCounter resourceRequirements)
Sets the resource requirements to the given resourceRequirements.
-
-
-
Method Detail
-
increaseResourceRequirementsBy
void increaseResourceRequirementsBy(ResourceCounter increment)
Increases the resource requirements by increment.- Parameters:
increment
- increment by which to increase the resource requirements
-
decreaseResourceRequirementsBy
void decreaseResourceRequirementsBy(ResourceCounter decrement)
Decreases the resource requirements by decrement.- Parameters:
decrement
- decrement by which to decrease the resource requirements
-
setResourceRequirements
void setResourceRequirements(ResourceCounter resourceRequirements)
Sets the resource requirements to the given resourceRequirements.- Parameters:
resourceRequirements
- new resource requirements
-
getResourceRequirements
Collection<ResourceRequirement> getResourceRequirements()
Returns the current resource requirements.- Returns:
- current resource requirements
-
offerSlots
Collection<SlotOffer> offerSlots(Collection<? extends SlotOffer> offers, TaskManagerLocation taskManagerLocation, TaskManagerGateway taskManagerGateway, long currentTime)
Offers slots to this slot pool. The slot pool is free to accept as many slots as it needs.- 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
Collection<SlotOffer> registerSlots(Collection<? extends SlotOffer> slots, TaskManagerLocation taskManagerLocation, TaskManagerGateway taskManagerGateway, long currentTime)
Registers 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
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 theofferSlots(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.- 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
-
getFreeSlotTracker
FreeSlotTracker getFreeSlotTracker()
Returns the free slot tracker.- Returns:
- free slot tracker
-
getAllSlotsInformation
Collection<? extends SlotInfo> getAllSlotsInformation()
Returns the slot information for all slots (free and allocated slots).- Returns:
- collection of slot information
-
containsFreeSlot
boolean containsFreeSlot(AllocationID allocationId)
Checks whether the slot pool contains a slot with the givenAllocationID
and if it is free.- Parameters:
allocationId
- allocationId specifies the slot to check for- Returns:
true
if the slot pool contains a free slot registered under the given allocation id; otherwisefalse
-
reserveFreeSlot
PhysicalSlot reserveFreeSlot(AllocationID allocationId, ResourceProfile requiredSlotProfile)
Reserves the free slot identified by the given allocationId and maps it to the given requiredSlotProfile.- Parameters:
allocationId
- allocationId identifies the free slot to allocaterequiredSlotProfile
- requiredSlotProfile specifying the resource requirement- Returns:
- a PhysicalSlot representing the allocated slot
- Throws:
IllegalStateException
- if no free slot with the given allocationId exists or if the specified slot cannot fulfill the requiredSlotProfile
-
freeReservedSlot
ResourceCounter freeReservedSlot(AllocationID allocationId, @Nullable Throwable cause, long currentTime)
Frees 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.
- Parameters:
allocationId
- allocationId identifying the slot to releasecause
- cause for releasing the slot; can benull
currentTime
- currentTime when the slot was released- Returns:
- the resource requirements that the slot was fulfilling
-
releaseSlots
ResourceCounter releaseSlots(ResourceID owner, Exception cause)
Releases all slots belonging to the owning TaskExecutor if it has been registered.- 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
ResourceCounter releaseSlot(AllocationID allocationId, Exception cause)
Releases the slot specified by allocationId if one exists.- 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
-
containsSlots
boolean containsSlots(ResourceID owner)
Returns whether the slot pool has a slot registered which is owned by the given TaskExecutor.- 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
-
releaseIdleSlots
void releaseIdleSlots(long currentTimeMillis)
Releases slots which have exceeded the idle slot timeout and are no longer needed to fulfill the resource requirements.- Parameters:
currentTimeMillis
- current time
-
registerNewSlotsListener
void registerNewSlotsListener(DeclarativeSlotPool.NewSlotsListener listener)
Registers a listener which is called whenever new slots become available.- Parameters:
listener
- which is called whenever new slots become available
-
-