Class TaskSlotTableImpl<T extends TaskSlotPayload>
java.lang.Object
org.apache.flink.runtime.taskexecutor.slot.TaskSlotTableImpl<T>
- All Implemented Interfaces:
AutoCloseable,TaskSlotTable<T>,TimeoutListener<AllocationID>,org.apache.flink.util.AutoCloseableAsync
public class TaskSlotTableImpl<T extends TaskSlotPayload>
extends Object
implements TaskSlotTable<T>
Default implementation of
TaskSlotTable.-
Constructor Summary
ConstructorsConstructorDescriptionTaskSlotTableImpl(int numberSlots, ResourceProfile totalAvailableResourceProfile, ResourceProfile defaultSlotResourceProfile, int memoryPageSize, TimerService<AllocationID> timerService, Executor memoryVerificationExecutor) -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd the given task to the slot identified by the task's allocation id.booleanallocateSlot(int index, org.apache.flink.api.common.JobID jobId, AllocationID allocationId, Duration slotTimeout) Allocate the slot with the given index for the given job and allocation id.booleanallocateSlot(int requestedIndex, org.apache.flink.api.common.JobID jobId, AllocationID allocationId, ResourceProfile resourceProfile, Duration slotTimeout) Allocate the slot with the given index for the given job and allocation id.createSlotReport(ResourceID resourceId) intfreeSlot(AllocationID allocationId, Throwable cause) Tries to free the slot.Returns theAllocationIDof any active task listed in thisTaskSlotTable.getActiveTaskSlotAllocationIdsPerJob(org.apache.flink.api.common.JobID jobId) getAllocatedSlots(org.apache.flink.api.common.JobID jobId) Return an iterator of allocated slots for the given job id.getAllocationIdsPerJob(org.apache.flink.api.common.JobID jobId) Returns the allAllocationIDfor the given job.getCurrentAllocation(int index) Get the current allocation for the task slot with the given index.org.apache.flink.api.common.JobIDgetOwningJob(AllocationID allocationId) Returns the owning job of theTaskSlotidentified by the givenAllocationID.getTask(ExecutionAttemptID executionAttemptID) Get the task for the given execution attempt id.getTaskMemoryManager(AllocationID allocationID) Get the memory manager of the slot allocated for the task.getTasks(org.apache.flink.api.common.JobID jobId) Return an iterator over all tasks for a given job.booleanhasAllocatedSlots(org.apache.flink.api.common.JobID jobId) Check whether the job has allocated (not active) slots.booleanisAllocated(int index, org.apache.flink.api.common.JobID jobId, AllocationID allocationId) Check whether the slot for the given index is allocated for the given job and allocation id.booleanisClosed()booleanisSlotFree(int index) Check whether the task slot with the given index is free.booleanisValidTimeout(AllocationID allocationId, UUID ticket) Check whether the timeout with ticket is valid for the given allocation id.booleanmarkSlotActive(AllocationID allocationId) Marks the slot under the given allocation id as active.booleanmarkSlotInactive(AllocationID allocationId, Duration slotTimeout) Marks the slot under the given allocation id as inactive.voidnotifyTimeout(AllocationID key, UUID ticket) Notify the listener about the timeout for an event identified by key.removeTask(ExecutionAttemptID executionAttemptID) Remove the task with the given execution attempt id from its task slot.voidstart(SlotActions initialSlotActions, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor mainThreadExecutor) Start the task slot table with the given slot actions.booleantryMarkSlotActive(org.apache.flink.api.common.JobID jobId, AllocationID allocationId) Try to mark the specified slot as active if it has been allocated by the given job.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.flink.util.AutoCloseableAsync
closeMethods inherited from interface org.apache.flink.runtime.taskexecutor.slot.TaskSlotTable
freeSlot
-
Constructor Details
-
TaskSlotTableImpl
public TaskSlotTableImpl(int numberSlots, ResourceProfile totalAvailableResourceProfile, ResourceProfile defaultSlotResourceProfile, int memoryPageSize, TimerService<AllocationID> timerService, Executor memoryVerificationExecutor)
-
-
Method Details
-
start
public void start(SlotActions initialSlotActions, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor mainThreadExecutor) Description copied from interface:TaskSlotTableStart the task slot table with the given slot actions.- Specified by:
startin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
initialSlotActions- to use for slot actionsmainThreadExecutor-ComponentMainThreadExecutorto schedule internal calls to the main thread
-
closeAsync
- Specified by:
closeAsyncin interfaceorg.apache.flink.util.AutoCloseableAsync
-
isClosed
@VisibleForTesting public boolean isClosed() -
getAllocationIdsPerJob
Description copied from interface:TaskSlotTableReturns the allAllocationIDfor the given job.- Specified by:
getAllocationIdsPerJobin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
jobId- for which to return the set ofAllocationID.- Returns:
- Set of
AllocationIDfor the given job
-
getActiveTaskSlotAllocationIds
Description copied from interface:TaskSlotTableReturns theAllocationIDof any active task listed in thisTaskSlotTable.- Specified by:
getActiveTaskSlotAllocationIdsin interfaceTaskSlotTable<T extends TaskSlotPayload>- Returns:
- The
AllocationIDof any active task.
-
getActiveTaskSlotAllocationIdsPerJob
public Set<AllocationID> getActiveTaskSlotAllocationIdsPerJob(org.apache.flink.api.common.JobID jobId) Description copied from interface:TaskSlotTable- Specified by:
getActiveTaskSlotAllocationIdsPerJobin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
jobId- TheJobIDof the job for which theAllocationIDs of the attached activeTaskSlots shall be returned.- Returns:
- A set of
AllocationIDs that belong to activeTaskSlots having the passedJobID.
-
createSlotReport
- Specified by:
createSlotReportin interfaceTaskSlotTable<T extends TaskSlotPayload>
-
allocateSlot
@VisibleForTesting public boolean allocateSlot(int index, org.apache.flink.api.common.JobID jobId, AllocationID allocationId, Duration slotTimeout) Description copied from interface:TaskSlotTableAllocate the slot with the given index for the given job and allocation id. If negative index is given, a new auto increasing index will be generated. Returns true if the slot could be allocated. Otherwise it returns false.- Specified by:
allocateSlotin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
index- of the task slot to allocate, use negative value for dynamic slot allocationjobId- to allocate the task slot forallocationId- identifying the allocationslotTimeout- until the slot times out- Returns:
- True if the task slot could be allocated; otherwise false
-
allocateSlot
public boolean allocateSlot(int requestedIndex, org.apache.flink.api.common.JobID jobId, AllocationID allocationId, ResourceProfile resourceProfile, Duration slotTimeout) Description copied from interface:TaskSlotTableAllocate the slot with the given index for the given job and allocation id. If negative index is given, a new auto increasing index will be generated. Returns true if the slot could be allocated. Otherwise it returns false.- Specified by:
allocateSlotin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
requestedIndex- of the task slot to allocate, use negative value for dynamic slot allocationjobId- to allocate the task slot forallocationId- identifying the allocationresourceProfile- of the requested slot, used only for dynamic slot allocation and will be ignored otherwiseslotTimeout- until the slot times out- Returns:
- True if the task slot could be allocated; otherwise false
-
markSlotActive
Description copied from interface:TaskSlotTableMarks the slot under the given allocation id as active. If the slot could not be found, then aSlotNotFoundExceptionis thrown.- Specified by:
markSlotActivein interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
allocationId- to identify the task slot to mark as active- Returns:
- True if the slot could be marked active; otherwise false
- Throws:
SlotNotFoundException- if the slot could not be found for the given allocation id
-
markSlotInactive
public boolean markSlotInactive(AllocationID allocationId, Duration slotTimeout) throws SlotNotFoundException Description copied from interface:TaskSlotTableMarks the slot under the given allocation id as inactive. If the slot could not be found, then aSlotNotFoundExceptionis thrown.- Specified by:
markSlotInactivein interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
allocationId- to identify the task slot to mark as inactiveslotTimeout- until the slot times out- Returns:
- True if the slot could be marked inactive
- Throws:
SlotNotFoundException- if the slot could not be found for the given allocation id
-
freeSlot
Description copied from interface:TaskSlotTableTries to free the slot. If the slot is empty it will set the state of the task slot to free and return its index. If the slot is not empty, then it will set the state of the task slot to releasing, fail all tasks and return -1.- Specified by:
freeSlotin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
allocationId- identifying the task slot to be freedcause- to fail the tasks with if slot is not empty- Returns:
- Index of the freed slot if the slot could be freed; otherwise -1
- Throws:
SlotNotFoundException- if there is not task slot for the given allocation id
-
isValidTimeout
Description copied from interface:TaskSlotTableCheck whether the timeout with ticket is valid for the given allocation id.- Specified by:
isValidTimeoutin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
allocationId- to check againstticket- of the timeout- Returns:
- True if the timeout is valid; otherwise false
-
isAllocated
public boolean isAllocated(int index, org.apache.flink.api.common.JobID jobId, AllocationID allocationId) Description copied from interface:TaskSlotTableCheck whether the slot for the given index is allocated for the given job and allocation id.- Specified by:
isAllocatedin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
index- of the task slotjobId- for which the task slot should be allocatedallocationId- which should match the task slot's allocation id- Returns:
- True if the given task slot is allocated for the given job and allocation id
-
tryMarkSlotActive
public boolean tryMarkSlotActive(org.apache.flink.api.common.JobID jobId, AllocationID allocationId) Description copied from interface:TaskSlotTableTry to mark the specified slot as active if it has been allocated by the given job.- Specified by:
tryMarkSlotActivein interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
jobId- of the allocated slotallocationId- identifying the allocation- Returns:
- True if the task slot could be marked active.
-
isSlotFree
public boolean isSlotFree(int index) Description copied from interface:TaskSlotTableCheck whether the task slot with the given index is free.- Specified by:
isSlotFreein interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
index- of the task slot- Returns:
- True if the task slot is free; otherwise false
-
hasAllocatedSlots
public boolean hasAllocatedSlots(org.apache.flink.api.common.JobID jobId) Description copied from interface:TaskSlotTableCheck whether the job has allocated (not active) slots.- Specified by:
hasAllocatedSlotsin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
jobId- for which to check for allocated slots- Returns:
- True if there are allocated slots for the given job id.
-
getAllocatedSlots
Description copied from interface:TaskSlotTableReturn an iterator of allocated slots for the given job id.- Specified by:
getAllocatedSlotsin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
jobId- for which to return the allocated slots- Returns:
- Iterator of allocated slots.
-
getOwningJob
Description copied from interface:TaskSlotTableReturns the owning job of theTaskSlotidentified by the givenAllocationID.- Specified by:
getOwningJobin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
allocationId- identifying the slot for which to retrieve the owning job- Returns:
- Owning job of the specified
TaskSlotor null if there is no slot for the given allocation id or if the slot has no owning job assigned
-
addTask
Description copied from interface:TaskSlotTableAdd the given task to the slot identified by the task's allocation id.- Specified by:
addTaskin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
task- to add to the task slot with the respective allocation id- Returns:
- True if the task could be added to the task slot; otherwise false
- Throws:
SlotNotFoundException- if there was no slot for the given allocation idSlotNotActiveException- if there was no slot active for task's job and allocation id
-
removeTask
Description copied from interface:TaskSlotTableRemove the task with the given execution attempt id from its task slot. If the owning task slot is in state releasing and empty after removing the task, the slot is freed via the slot actions.- Specified by:
removeTaskin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
executionAttemptID- identifying the task to remove- Returns:
- The removed task if there is any for the given execution attempt id; otherwise null
-
getTask
Description copied from interface:TaskSlotTableGet the task for the given execution attempt id. If none could be found, then return null.- Specified by:
getTaskin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
executionAttemptID- identifying the requested task- Returns:
- The task for the given execution attempt id if it exist; otherwise null
-
getTasks
Description copied from interface:TaskSlotTableReturn an iterator over all tasks for a given job.- Specified by:
getTasksin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
jobId- identifying the job of the requested tasks- Returns:
- Iterator over all task for a given job
-
getCurrentAllocation
Description copied from interface:TaskSlotTableGet the current allocation for the task slot with the given index.- Specified by:
getCurrentAllocationin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
index- identifying the slot for which the allocation id shall be retrieved- Returns:
- Allocation id of the specified slot if allocated; otherwise null
-
getTaskMemoryManager
Description copied from interface:TaskSlotTableGet the memory manager of the slot allocated for the task.- Specified by:
getTaskMemoryManagerin interfaceTaskSlotTable<T extends TaskSlotPayload>- Parameters:
allocationID- allocation id of the slot allocated for the task- Returns:
- the memory manager of the slot allocated for the task
- Throws:
SlotNotFoundException
-
notifyTimeout
Description copied from interface:TimeoutListenerNotify the listener about the timeout for an event identified by key. Additionally the method is called with the timeout ticket which allows to identify outdated timeout events.- Specified by:
notifyTimeoutin interfaceTimeoutListener<T extends TaskSlotPayload>- Parameters:
key- identifying the timed out eventticket- used to check whether the timeout is still valid
-