Interface TaskSlotTable<T extends TaskSlotPayload>
-
- All Superinterfaces:
AutoCloseable
,AutoCloseableAsync
,TimeoutListener<AllocationID>
- All Known Implementing Classes:
TaskSlotTableImpl
public interface TaskSlotTable<T extends TaskSlotPayload> extends TimeoutListener<AllocationID>, AutoCloseableAsync
Container for multipleTaskSlot
instances. Additionally, it maintains multiple indices for faster access to tasks and sets of allocated slots.The task slot table automatically registers timeouts for allocated slots which cannot be assigned to a job manager.
Before the task slot table can be used, it must be started via the
start(org.apache.flink.runtime.taskexecutor.slot.SlotActions, org.apache.flink.runtime.concurrent.ComponentMainThreadExecutor)
method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description boolean
addTask(T task)
Add the given task to the slot identified by the task's allocation id.boolean
allocateSlot(int index, JobID jobId, AllocationID allocationId, Duration slotTimeout)
Allocate the slot with the given index for the given job and allocation id.boolean
allocateSlot(int index, JobID jobId, AllocationID allocationId, ResourceProfile resourceProfile, Duration slotTimeout)
Allocate the slot with the given index for the given job and allocation id.SlotReport
createSlotReport(ResourceID resourceId)
default int
freeSlot(AllocationID allocationId)
Try to free the slot.int
freeSlot(AllocationID allocationId, Throwable cause)
Tries to free the slot.Set<AllocationID>
getActiveTaskSlotAllocationIds()
Returns theAllocationID
of any active task listed in thisTaskSlotTable
.Set<AllocationID>
getActiveTaskSlotAllocationIdsPerJob(JobID jobId)
Iterator<TaskSlot<T>>
getAllocatedSlots(JobID jobId)
Return an iterator of allocated slots for the given job id.Set<AllocationID>
getAllocationIdsPerJob(JobID jobId)
Returns the allAllocationID
for the given job.AllocationID
getCurrentAllocation(int index)
Get the current allocation for the task slot with the given index.JobID
getOwningJob(AllocationID allocationId)
Returns the owning job of theTaskSlot
identified by the givenAllocationID
.T
getTask(ExecutionAttemptID executionAttemptID)
Get the task for the given execution attempt id.MemoryManager
getTaskMemoryManager(AllocationID allocationID)
Get the memory manager of the slot allocated for the task.Iterator<T>
getTasks(JobID jobId)
Return an iterator over all tasks for a given job.boolean
hasAllocatedSlots(JobID jobId)
Check whether the job has allocated (not active) slots.boolean
isAllocated(int index, JobID jobId, AllocationID allocationId)
Check whether the slot for the given index is allocated for the given job and allocation id.boolean
isSlotFree(int index)
Check whether the task slot with the given index is free.boolean
isValidTimeout(AllocationID allocationId, UUID ticket)
Check whether the timeout with ticket is valid for the given allocation id.boolean
markSlotActive(AllocationID allocationId)
Marks the slot under the given allocation id as active.boolean
markSlotInactive(AllocationID allocationId, Duration slotTimeout)
Marks the slot under the given allocation id as inactive.T
removeTask(ExecutionAttemptID executionAttemptID)
Remove the task with the given execution attempt id from its task slot.void
start(SlotActions initialSlotActions, ComponentMainThreadExecutor mainThreadExecutor)
Start the task slot table with the given slot actions.boolean
tryMarkSlotActive(JobID jobId, AllocationID allocationId)
Try to mark the specified slot as active if it has been allocated by the given job.-
Methods inherited from interface org.apache.flink.util.AutoCloseableAsync
close, closeAsync
-
Methods inherited from interface org.apache.flink.runtime.taskexecutor.slot.TimeoutListener
notifyTimeout
-
-
-
-
Method Detail
-
start
void start(SlotActions initialSlotActions, ComponentMainThreadExecutor mainThreadExecutor)
Start the task slot table with the given slot actions.- Parameters:
initialSlotActions
- to use for slot actionsmainThreadExecutor
-ComponentMainThreadExecutor
to schedule internal calls to the main thread
-
getAllocationIdsPerJob
Set<AllocationID> getAllocationIdsPerJob(JobID jobId)
Returns the allAllocationID
for the given job.- Parameters:
jobId
- for which to return the set ofAllocationID
.- Returns:
- Set of
AllocationID
for the given job
-
getActiveTaskSlotAllocationIds
Set<AllocationID> getActiveTaskSlotAllocationIds()
Returns theAllocationID
of any active task listed in thisTaskSlotTable
.- Returns:
- The
AllocationID
of any active task.
-
getActiveTaskSlotAllocationIdsPerJob
Set<AllocationID> getActiveTaskSlotAllocationIdsPerJob(JobID jobId)
- Parameters:
jobId
- TheJobID
of the job for which theAllocationID
s of the attached activeTaskSlot
s shall be returned.- Returns:
- A set of
AllocationID
s that belong to activeTaskSlot
s having the passedJobID
.
-
createSlotReport
SlotReport createSlotReport(ResourceID resourceId)
-
allocateSlot
@VisibleForTesting boolean allocateSlot(int index, JobID jobId, AllocationID allocationId, Duration slotTimeout)
Allocate 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.- 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
boolean allocateSlot(int index, JobID jobId, AllocationID allocationId, ResourceProfile resourceProfile, Duration slotTimeout)
Allocate 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.- Parameters:
index
- 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
boolean markSlotActive(AllocationID allocationId) throws SlotNotFoundException
Marks the slot under the given allocation id as active. If the slot could not be found, then aSlotNotFoundException
is thrown.- 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
boolean markSlotInactive(AllocationID allocationId, Duration slotTimeout) throws SlotNotFoundException
Marks the slot under the given allocation id as inactive. If the slot could not be found, then aSlotNotFoundException
is thrown.- 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
default int freeSlot(AllocationID allocationId) throws SlotNotFoundException
Try 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.- Parameters:
allocationId
- identifying the task slot to be freed- 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
-
freeSlot
int freeSlot(AllocationID allocationId, Throwable cause) throws SlotNotFoundException
Tries 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.- 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
boolean isValidTimeout(AllocationID allocationId, UUID ticket)
Check whether the timeout with ticket is valid for the given allocation id.- Parameters:
allocationId
- to check againstticket
- of the timeout- Returns:
- True if the timeout is valid; otherwise false
-
isAllocated
boolean isAllocated(int index, JobID jobId, AllocationID allocationId)
Check whether the slot for the given index is allocated for the given job and allocation id.- 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
boolean tryMarkSlotActive(JobID jobId, AllocationID allocationId)
Try to mark the specified slot as active if it has been allocated by the given job.- Parameters:
jobId
- of the allocated slotallocationId
- identifying the allocation- Returns:
- True if the task slot could be marked active.
-
isSlotFree
boolean isSlotFree(int index)
Check whether the task slot with the given index is free.- Parameters:
index
- of the task slot- Returns:
- True if the task slot is free; otherwise false
-
hasAllocatedSlots
boolean hasAllocatedSlots(JobID jobId)
Check whether the job has allocated (not active) slots.- Parameters:
jobId
- for which to check for allocated slots- Returns:
- True if there are allocated slots for the given job id.
-
getAllocatedSlots
Iterator<TaskSlot<T>> getAllocatedSlots(JobID jobId)
Return an iterator of allocated slots for the given job id.- Parameters:
jobId
- for which to return the allocated slots- Returns:
- Iterator of allocated slots.
-
getOwningJob
@Nullable JobID getOwningJob(AllocationID allocationId)
Returns the owning job of theTaskSlot
identified by the givenAllocationID
.- Parameters:
allocationId
- identifying the slot for which to retrieve the owning job- Returns:
- Owning job of the specified
TaskSlot
or null if there is no slot for the given allocation id or if the slot has no owning job assigned
-
addTask
boolean addTask(T task) throws SlotNotFoundException, SlotNotActiveException
Add the given task to the slot identified by the task's allocation id.- 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
T removeTask(ExecutionAttemptID executionAttemptID)
Remove 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.- Parameters:
executionAttemptID
- identifying the task to remove- Returns:
- The removed task if there is any for the given execution attempt id; otherwise null
-
getTask
T getTask(ExecutionAttemptID executionAttemptID)
Get the task for the given execution attempt id. If none could be found, then return null.- Parameters:
executionAttemptID
- identifying the requested task- Returns:
- The task for the given execution attempt id if it exist; otherwise null
-
getTasks
Iterator<T> getTasks(JobID jobId)
Return an iterator over all tasks for a given job.- Parameters:
jobId
- identifying the job of the requested tasks- Returns:
- Iterator over all task for a given job
-
getCurrentAllocation
AllocationID getCurrentAllocation(int index)
Get the current allocation for the task slot with the given index.- 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
MemoryManager getTaskMemoryManager(AllocationID allocationID) throws SlotNotFoundException
Get the memory manager of the slot allocated for the task.- Parameters:
allocationID
- allocation id of the slot allocated for the task- Returns:
- the memory manager of the slot allocated for the task
- Throws:
SlotNotFoundException
-
-