Class TaskSlot<T extends TaskSlotPayload>
- java.lang.Object
-
- org.apache.flink.runtime.taskexecutor.slot.TaskSlot<T>
-
- Type Parameters:
T
- type of theTaskSlotPayload
stored in this slot
- All Implemented Interfaces:
AutoCloseable
,AutoCloseableAsync
public class TaskSlot<T extends TaskSlotPayload> extends Object implements AutoCloseableAsync
Container for multipletasks
belonging to the same slot. ATaskSlot
can be in one of the following states:- Free - The slot is empty and not allocated to a job
- Releasing - The slot is about to be freed after it has become empty.
- Allocated - The slot has been allocated for a job.
- Active - The slot is in active use by a job manager which is the leader of the allocating job.
A task slot can only be allocated if it is in state free. An allocated task slot can transit to state active.
An active slot allows to add tasks from the respective job and with the correct allocation id. An active slot can be marked as inactive which sets the state back to allocated.
An allocated or active slot can only be freed if it is empty. If it is not empty, then it's state can be set to releasing indicating that it can be freed once it becomes empty.
-
-
Constructor Summary
Constructors Constructor Description TaskSlot(int index, ResourceProfile resourceProfile, int memoryPageSize, JobID jobId, AllocationID allocationId, Executor asyncExecutor)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T task)
Add the given task to the task slot.void
clear()
Removes all tasks from this task slot.CompletableFuture<Void>
closeAsync()
Trigger the closing of the resource and return the corresponding close future.SlotOffer
generateSlotOffer()
Generate the slot offer from this TaskSlot.AllocationID
getAllocationId()
int
getIndex()
JobID
getJobId()
MemoryManager
getMemoryManager()
ResourceProfile
getResourceProfile()
Iterator<T>
getTasks()
Get all tasks running in this task slot.boolean
isActive(JobID activeJobId, AllocationID activeAllocationId)
boolean
isAllocated(JobID jobIdToCheck, AllocationID allocationIDToCheck)
boolean
isEmpty()
boolean
isReleasing()
boolean
markActive()
Mark this slot as active.boolean
markInactive()
Mark the slot as inactive/allocated.T
remove(ExecutionAttemptID executionAttemptId)
Remove the task identified by the given execution attempt id.String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.flink.util.AutoCloseableAsync
close
-
-
-
-
Constructor Detail
-
TaskSlot
public TaskSlot(int index, ResourceProfile resourceProfile, int memoryPageSize, JobID jobId, AllocationID allocationId, Executor asyncExecutor)
-
-
Method Detail
-
getIndex
public int getIndex()
-
getResourceProfile
public ResourceProfile getResourceProfile()
-
getJobId
public JobID getJobId()
-
getAllocationId
public AllocationID getAllocationId()
-
isEmpty
public boolean isEmpty()
-
isActive
public boolean isActive(JobID activeJobId, AllocationID activeAllocationId)
-
isAllocated
public boolean isAllocated(JobID jobIdToCheck, AllocationID allocationIDToCheck)
-
isReleasing
public boolean isReleasing()
-
getTasks
public Iterator<T> getTasks()
Get all tasks running in this task slot.- Returns:
- Iterator to all currently contained tasks in this task slot.
-
getMemoryManager
public MemoryManager getMemoryManager()
-
add
public boolean add(T task)
Add the given task to the task slot. This is only possible if there is not already another task with the same execution attempt id added to the task slot. In this case, the method returns true. Otherwise the task slot is left unchanged and false is returned.In case that the task slot state is not active an
IllegalStateException
is thrown. In case that the task's job id and allocation id don't match with the job id and allocation id for which the task slot has been allocated, anIllegalArgumentException
is thrown.- Parameters:
task
- to be added to the task slot- Returns:
- true if the task was added to the task slot; otherwise false
- Throws:
IllegalStateException
- if the task slot is not in state active
-
remove
public T remove(ExecutionAttemptID executionAttemptId)
Remove the task identified by the given execution attempt id.- Parameters:
executionAttemptId
- identifying the task to be removed- Returns:
- The removed task if there was any; otherwise null.
-
clear
public void clear()
Removes all tasks from this task slot.
-
markActive
public boolean markActive()
Mark this slot as active. A slot can only be marked active if it's in state allocated.The method returns true if the slot was set to active. Otherwise it returns false.
- Returns:
- True if the new state of the slot is active; otherwise false
-
markInactive
public boolean markInactive()
Mark the slot as inactive/allocated. A slot can only be marked as inactive/allocated if it's in state allocated or active.- Returns:
- True if the new state of the slot is allocated; otherwise false
-
generateSlotOffer
public SlotOffer generateSlotOffer()
Generate the slot offer from this TaskSlot.- Returns:
- The sot offer which this task slot can provide
-
closeAsync
public CompletableFuture<Void> closeAsync()
Description copied from interface:AutoCloseableAsync
Trigger the closing of the resource and return the corresponding close future.- Specified by:
closeAsync
in interfaceAutoCloseableAsync
- Returns:
- Future which is completed once the resource has been closed
-
-