Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status

...

Page properties


Discussion thread

...

...

JIRA:

Vote thread
JIRA

Jira
serverASF JIRA
serverId5aa69414-a9e9-3523-82ec-879b028fb15b
keyFLINK-28130

Release1.16

...


Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).

Table of Contents

Motivation

Flink jobs typically run in a distributed way. In a large cluster, cluster nodes often encounter the following issues that affect jobs running:

  1. Unrecoverable problems, such as insufficient disk space, bad hardware, network abnormalities. These problems will result in continuous job failures. Currently, Flink users need to take the problematic node offline to solve this problem. However, taking a node offline can be a heavy process. Users may need to contact cluster administors to do this. The operation can even be dangerous and not allowed during some important business events.
  2. Recoverable problems, such as temporary node hotspots. These problems can slow the jobs running on it, but it can resume after a period of time. In this case, users may just want to limit the load of the node and do not want to kill all the processes on it. Unfortunately, currently neither Flink itself nor external resource management systems can do this.

To solve the above problems, we propose to introduce a blocklist mechanism for Flink to filter out problematic resources. Two granularities of blocked resources will be supported: task managers and nodes, and two block actions will be introduced:

  1. MARK_BLOCKED: Just mark a task manager or node as blocked. Future slots should not be allocated from the blocked task manager or node. But slots that are already allocated will not be affected.
  2. MARK_BLOCKED_AND_EVACUATE_TASKS: Mark the task manager or node as blocked, and evacuate all tasks on it. Evacuated tasks will be restarted on non-blocked task managers.

In this design, only support manually specifying blocked resources via the REST API, auto-detection may be introduced in the future.

Public Interfaces

Configurations

We propose to introduce following configuration options for blocklist:

  • cluster.resource-blocklist.enabled: Whether to enable blocklist mechanism.

Metrics

We propose to introduce following Gauge metrics:

  1. numBlockedTaskMangers: The number of currently blocked task managers (including task managers on blocked nodes)
  2. numBlockedNodes: The number of currently blocked nodes

REST API

We propose to introduce following REST APIs for blocklist mechanism:

  1. REST API for querying blocklist information.
  2. REST API for adding new blocked items.
  3. REST API for removing existing blocked items.

Query

GET: http://{jm_rest_address:port}/blocklist

Request

Request body: {}

Response

Response code: 200(OK)

Response body:

Code Block
titleResponse Example
{
  /** This group only contains directly blocked task managers */
  "blockedTaskManagers": [
      {
          "id" : "container1",
          "action" : "MARK_BLOCKED",
          "startTimestamp" : "1652313600000",
          "endTimestamp" : "1652317200000",
          "cause" : "Hot machine"
      },
      {
          "id" : "container2",
          "action" : "MARK_BLOCKED_AND_EVACUATE_TASKS",
          "startTimestamp" : "1652315400000",
          "endTimestamp" : "1652319000000",
          "cause" : "No space left on device"
      }, 
      ...
  ],
  "blockedNodes": [
      {
          "id" : "node1",
          "action" : "MARK_BLOCKED",
          "startTimestamp" : "1652313600000",
          "endTimestamp" : "1652317200000",
          "cause" : "Hot machine",
          /** The task managers on this blocked node */
          "taskManagers" : ["container3", "container4"]
      },
      ...
  ]
} 

Field meanings in responses:

  1. id: A string value that represents the identifier of the blocked task manager or node.
  2. action: An enum value(MARK_BLOCKED or MARK_BLOCKED_AND_EVACUATE_TASKS) that represents the block action when a task manager/node is marked as blocked.
  3. startTimestamp: A long value that represents the unix timestamp(milliseconds) of creating this item. 
  4. endTimestamp:  A long value that represents the unix timestamp(milliseconds) at which the item should be removed. If the blocked item is permanent, this value will be Long.MAX_VALUE(9223372036854775807).
  5. cause: A string value that represents the cause for blocking this task manager or node.

Add

POST: http://{jm_rest_address:port}/blocklist/nodes

POST: http://{jm_rest_address:port}/blocklist/taskmanagers

Request

Request body:

Code Block
titleRequest Example
{
    [
        {
            "id" : "node1/container1",
            "action" : "MARK_BLOCKED",
            "endTimestamp" : "1652317200000",
            "cause" : "Hot machine",
			"allowMerge" : "true"
        },
        {
            "id" : "node2/container2",
            "action" : "MARK_BLOCKED_AND_EVACUATE_TASKS",
            "timeout" : "3600000",
            "cause" : "No space left on device"
        }, 
        ...
    ]
}

Field meanings in requests:

  1. id: A string value that specifies the identifier of the blocked task manager or node.
  2. action: An enum value(MARK_BLOCKED or MARK_BLOCKED_AND_EVACUATE_TASKS) that specifies the block action when a task manager/node is marked as blocked.
  3. timeout(optional): A long value that specifies the timeout (milliseconds).
  4. endTimestamp(optional): A long value that specifies the unix timestamp(milliseconds) at which the item should be removed. Note that only one of timeout and endTimestamp can be specified. If neither is specified, it means that the blocked item is permanent and will not be removed. If both are specified, will return error.
  5. cause: A string value that specifies the cause for blocking this task manager or node.
  6. allowMerge(optional): A boolean value that specifies whether to merge when a conflict occurs. The default value is false. 

When trying to add a taskmanager or node, if the corresponding taskmanager/node already exists in blocklist, we propose to introduce two processing behaviors:

  1. If field allowMerge is false, return error. 
  2. If field allowMerge is true. The newly added item and the existing item will be merged into one. Regarding the 3 fields, the merging algorithm:
    1. For action, merge(MARK_BLOCKED, MARK_BLOCKED_AND_EVACUATE_TASKS) = MARK_BLOCKED_AND_EVACUATE_TASKS
    2. For endTimestamp, merge(endTimestampA, endTimestampB) = max(endTimestampA, endTimestampB)
    3. For cause, we will combine all causes, merge("causeA", "causeB") = "causeA,causeB"

Response

  1. If no conflict, the response code is 201(CREATED), the response body is empty.
  2. If conflict occurs:
    1. If allowMerge is false, the response code is 409(CONFLICT), and returns error.
    2. if allowMerge is true, the response code is 202(ACCEPTED), the response body is the merged result.

Remove

DELETE: http://{jm_rest_address:port}/blocklist/node/<id>

DELETE: http://{jm_rest_address:port}/blocklist/taskmanager/<id>

Request

Request body: {}

Response

if the item identified by id does not exist, the response code is 404(NOT FOUND), and returns error. Else, the response code is 200(OK), and returns an empty response body.

Proposed Changes

In this design, two granularities of blocked resources are supported: task managers and nodes. A record of blocklist information is called a blocked item, which is generally generated by the scheduler according to the exception of the tasks. These blocked items will be recorded in a special component and affect the resource allocation of Flink clusters. However,the blocked items are not permanent, there will be a timeout for it. Once an item times out, it will be removed, and the resource will become available again. The overall structure of the blocklist mechanism is shown in the figure below. 

Image Removed

In JM, there will be a component (JobMasterBlocklistHandler) responsible for managing all blocked items and performing them on SlotPool. 

In RM, there will also be a component (ResourceManagerBlocklistHandler) responsible for managing the cluster-level blocklist. SlotManager will be aware of the blocklist information  and filter out resources in the blocklist when allocating slots from registered task managers. Similarly, when the ResourceManagerDriver requests new resources from an external resource manager (Yarn or Kubernetes), it also needs to filter out the blocked nodes.

Blocked Item

A blocked item corresponds to the blocklist information of a specific task manager or node, including the following 6 fields:

  1. type: The blocked item type, TASK_MANAGER or NODE
  2. id: The identifier of the blocked task manager or node.
  3. action: The block action when a task manager/node is marked as blocked, MARK_BLOCKED or MARK_BLOCKED_AND_EVACUATE_TASKS
  4. startTimestamp: The timestamp of creating this item.
  5. endTimestamp: The timestamp at which the item should be removed.
  6. cause: The cause for creating this item.
Code Block
titleBlocklistedItem
/**
 * This class represents a blocked item.
 *
 * @param <ID> Identifier of the blocked item.
 */
public abstract class BlockedItem<ID> {
    public BlockedItemType getType();

    public BlockAction getAction();
    
    public long getStartTimestamp();

    public long getEndTimestamp();
    
    public String getCause();

    public abstract ID getId();
}

/** This class represents a blocked node. */
public class BlockedNode extends BlockedItem<String> {
}

/** This class represents a blocked task manager. */
public class BlockedTaskManager extends BlockedItem<ResourceID> {
}

Blocklist on JobMaster

JobMasterBlocklistHandler

JobMasterBlocklistHandler is the component in JM responsible for managing all blocked items and performing them on SlotPool. It consists of two sub-components:BlocklistTracker and BlocklistContext. When receiving a new blocked items, the JobMasterBlocklistHandler will handle it as following:

  1. Add the new blocked items to the BlocklistTracker. 
  2. Synchronize the new blocked items to RM.
  3. Perform block actions on the resources via the BlocklistContext.

BlocklistTracker

BlocklistTracker is the component responsible for tracking blocked items. The tracker will regularly remove timeout blocked items.

Code Block
titleBlocklistTracker
public interface BlocklistTracker {
    /** Starts the blocklist tracker. */
    void start(ComponentMainThreadExecutor mainThreadExecutor);

    /**
     * Add new blocked items or update existing items.
     *
     * @param items The items to add or update
     * @return Newly added or updated items.
     */
    Collection<BlockedItem<?>> addNewBlockedItems(Collection<BlockedItem<?>> items);

    /** Returns whether the given task manager is blocked. */
    boolean isBlockedTaskManager(ResourceID resourceID);

    /** Get all blocked nodes. */
    Set<String> getBlockedNodes();

    /** Close the blocklist tracker. */
    void close();
}
     

BlocklistContext

BlocklistContext is the component responsible for performing block actions on SlotPool, the details will be described in SlotPool.

Code Block
titleBlocklistContext
public interface BlocklistContext {
    /** Perform the newly added or updated blocked items on resources. */
    void blocklistResources(Collection<BlockedItem<?>> newlyAddedOrUpdatedItems);
}
   
Code Block
titleBlocklistHandler & JobMasterBlocklistHandler
public interface BlocklistHandler extends BlocklistTracker {
    /** Add a new blocked node. */
    void blockNode(String nodeId, BlockAction action, String cause, long startTimestamp, long endTimestamp);

    /** Add a new blocked task manager. */
    void blockTaskManager(ResourceID taskManagerId, BlockAction action, String cause, long startTimestamp, long endTimestamp);
 }

public interface JobMasterBlocklistHandler extends BlocklistHandler {
}

SlotPool

SlotPool should avoid allocating slots from blocked task managers. Blocked task managers include those directly blocked and those located on blocked nodes. To do that, our core idea is to keep the SlotPool in such a state: there is no slot in SlotPool that is free (no task assigned) and blocked. Details are as following:

  1. When SlotPool starts, BlockedTaskManagerChecker will be passed in to check whether a task manager is blocked.
  2. When receiving slot offers from blocked task managers (including task managers on blocked nodes), all offers should be rejected.
  3. When a task manager is newly blocked, BlocklistContext will perform the following on SlotPool:
    1. If the action is MARK_BLOCKED, release all free(no task assigned) slots on the blocked task manager.
    2. If the action is MARK_BLOCKED_AND_EVACUATE_TASKS, release all slots on the blocked task manager.
  4. When a slot state changes from reserved(task assigned) to free(no task assigned), it will check whether the corresponding task manager is blocked. If yes, release the slot.

Code Block
titleSlotPoolService
public interface BlockedTaskManagerChecker {
    /**
     * Returns whether the given task manager is blocked.
     */
    boolean isBlockedTaskManager(ResourceID resourceID);
}


public interface SlotPoolService {

    /** Start the encapsulated slot pool implementation. */
    void start(
            JobMasterId jobMasterId,
            String address,
            ComponentMainThreadExecutor mainThreadExecutor,
            BlockedTaskManagerChecker blockedTaskManagerChecker)
            throws Exception;

   /**
     * Releases all slots belonging to the owning TaskExecutor if it has been registered.
     *
     * @param taskManagerId identifying the TaskExecutor
     * @param cause cause for failing the slots
     */
    void releaseSlotsOnTaskManager(ResourceID taskManagerId, Exception cause);

    /**
     * Releases all free slots belonging to the owning TaskExecutor if it has been registered.
     *
     * @param taskManagerId identifying the TaskExecutor
     * @param cause cause for failing the slots
     */
    void releaseFreeSlotsOnTaskManager(ResourceID taskManagerId, Exception cause);

    //...
}

Blocklist on ResourceManager

ResourceManagerBlocklistHandler

ResourceManagerBlocklistHandler is a new component introduced in RM for the blocklist mechanism. It has only one sub-component: BlocklistTracker, which is responsible for managing cluster-level blocked items.

Code Block
titleResourceManagerBlocklistHandler
public interface ResourceManagerBlocklistHandler extends BlocklistHandler {
}

SlotManager

SlotManager should filter out blocked resources when allocating registered resources. To do that, we need following changes:

...

In order to support speculative execution for batch jobs(FLIP-168), we need a mechanism to block resources on nodes where the slow tasks are located. We propose to introduce a blocklist mechanism as follows:  Once a node is marked as blocked, future slots should not be allocated from the blocked node, but the slots that are already allocated will not be affected.

Proposed Changes

We introduce a new data structure: BlockedNode to record the information of a blocked node. This information will be recorded in a special component and affect the resource allocation of Flink clusters. However,the blocking of nodes is not permanent, there will be a timeout for it. Once it times out, the nodes will become available again. The overall structure of the blocklist mechanism is shown in the figure below. 

Image Added

In JM, there will be a component (JobMasterBlocklistHandler) responsible for managing all BlockedNode(s) and performing them on SlotPool. 

In RM, there will also be a component (ResourceManagerBlocklistHandler) responsible for managing the cluster-level blocklist. SlotManager will be aware of the blocklist information and filter out resources in the blocklist when allocating slots from registered task managers. Similarly, when the ResourceManagerDriver requests new resources from an external resource manager (Yarn or Kubernetes), it also needs to filter out the blocked nodes.

BlockedNode

A BlockedNode corresponds to the blocked information of a specific node, including the following 4 fields:

  1. id: The identifier of the node.
  2. startTimestamp: The start time of the blocking.
  3. endTimestamp: The end time of the blocking (at which time the node will become available again). 
  4. cause: The cause for blocking this node.
Code Block
titleBlockedNode
/**
 * This class represents a blocked node.
 */
public class BlockedNode {
    
    public long getStartTimestamp();

    public long getEndTimestamp();
    
    public String getCause();

    public String getId();
}

Blocklist on JobMaster

JobMasterBlocklistHandler

JobMasterBlocklistHandler is the component in JM responsible for managing all blocked node information and performing them on SlotPool. It consists of two sub-components:BlocklistTracker and BlocklistContext. When receiving a new blocked node information, the JobMasterBlocklistHandler will handle it as following:

  1. Add the new blocked nodes to the BlocklistTracker. 
  2. Synchronize the new blocked nodes to RM.
  3. Block the resources on newly added nodes via the BlocklistContext.

BlocklistTracker

BlocklistTracker is the component responsible for tracking blocked nodes. The tracker will regularly remove timeout blocked nodes.

Code Block
titleBlocklistTracker
public interface BlocklistTracker {

    /**
     * Add or update blocked nodes.
     *
     * @param nodes The nodes to add or update
     * @return Newly added or updated nodes.
     */
    Collection<BlockedNode> addNewBlockedNodes(Collection<BlockedNode> nodes);

    /** Returns whether the given task manager is located on blocked nodes. */
    boolean isBlockedTaskManager(ResourceID taskManagerId);

    /** Get all blocked nodes. */
    Set<String> getBlockedNodes();

    /** Remove the timeout nodes. */
    void removeTimeoutNodes();
}
     

BlocklistContext

BlocklistContext is the component responsible for blocking slots in SlotPool, the details will be described in SlotPool.

Code Block
titleBlocklistContext
public interface BlocklistContext {
    /** Block resources on the newly added nodes. */
    void blockResources(Collection<BlockedNode> newlyAddedOrUpdatedNodes);
}
   


Code Block
titleBlocklistHandler & JobMasterBlocklistHandler
public interface BlocklistHandler {

    /** Add a new blocked node. */
    void blockNode(String nodeId, String cause, long startTimestamp, long endTimestamp);

    /** Returns whether the given task manager is located on blocked nodes. */
    boolean isBlockedTaskManager(ResourceID taskManagerId); 

    /** Get all blocked nodes. */
    Set<String> getBlockedNodes();    
}

public interface JobMasterBlocklistHandler extends BlocklistHandler {
}

SlotPool

SlotPool should avoid allocating slots that located on blocked nodes. To do that, our core idea is to keep the SlotPool in such a state: there is no slot in SlotPool that is free (no task assigned) and located on blocked nodes. Details are as following:

  1. When receiving slot offers from task managers located on blocked nodes, all offers should be rejected.
  2. When a node is newly blocked, we should release all free(no task assigned) slots on it. We need to find all task managers on blocked nodes and release all free slots on them by SlotPoolService#releaseFreeSlotsOnTaskManager.
  3. When a slot state changes from reserved(task assigned) to free(no task assigned), it will check whether the corresponding task manager is blocked. If yes, release the slot.

We will introduce a new slot pool implementation: BlocklistSlotPool, which extends the DefaultDeclarativeSlotPool and overrides some methods to implement the blocklist-related functions described above, and the blocklist information will be passed in the constructor. This new implementation will be only used when the blocklist is enabled.

Code Block
titleSlotPoolService
public interface SlotPoolService {
    /**
     * Releases all free slots belonging to the owning TaskExecutor if it has been registered.
     *
     * @param taskManagerId identifying the TaskExecutor
     * @param cause cause for failing the slots
     */
    void releaseFreeSlotsOnTaskManager(ResourceID taskManagerId, Exception cause);

    //...
}


Code Block
titleBlocklistSlotPool
public class BlocklistSlotPool extends DefaultDeclarativeSlotPool {
    // ...
}

Blocklist on ResourceManager

ResourceManagerBlocklistHandler

ResourceManagerBlocklistHandler is a new component introduced in RM for the blocklist mechanism. It has only one sub-component: BlocklistTracker, which is responsible for managing cluster-level blocklist.

Code Block
titleResourceManagerBlocklistHandler
public interface ResourceManagerBlocklistHandler extends BlocklistHandler {
}

SlotManager

SlotManager should filter out blocked resources when allocating registered resources. To do that, we need following changes:

  1. When starting SlotManager, the BlockedTaskManagerChecker will be passed in to check whether a registered task manager is located on blocked nodes.
  2. When trying to fulfill the slot requirements by registered task managers, the task managers located on blocked nodes will be filtered out.
  3. SlotManager will request new task managers from external resource managers if the registered resources cannot fulfill the requirements. The blocklist also takes effect when requesting new task managers, the details will be described in ResourceManagerDriver.
Code Block
titleBlockedTaskManagerChecker
/** This checker helps to query whether a given task manager is located on blocked nodes. */
public interface BlockedTaskManagerChecker {

    /** Returns whether the given task manager is located on blocked nodes. */
    boolean isBlockedTaskManager(ResourceID taskManagerId);
}

...


Code Block
titleSlotManager
public interface SlotManager {

    /** Starts the slot manager with the given leader id and resource manager actions. */
    void start(
            ResourceManagerId newResourceManagerId,
            Executor newMainThreadExecutor,
            ResourceActions newResourceActions,
            BlockedTaskManagerChecker newBlockedTaskManagerChecker);

    //...
}

...

Synchronize Blocklist between JM & RM

The newly added or /updated blocked items nodes will be synchronized between JM and RM via RPC: 

  1. Once a few blocked items nodes are newly added (or /updated ) to the JobMasterBlocklistHandler, RM will be notified of these items via ResourceManagerGateway#notifyNewBlockedItemsnodes via ResourceManagerGateway#notifyNewBlockedNodes.
  2. When RM receives the blocked items nodes notified by a JM, it will add them into ResourceManagerBlocklistHandler, and notify all JMs of the successfully added (or updated) items through JobMasterGateway#notifyNewBlockedItems/updated nodes through JobMasterGateway#notifyNewBlockedNodes
  3. Similarly, when JM receives the blocked items nodes notified by RM, it will also add them to JobMasterBlocklistHandler.
Code Block
titleBlocklistListener
public interface BlocklistListener {

    /** Notify newly newadded/updated blocked itemsnodes. */
    void notifyNewBlockedItemsnotifyNewBlockedNodes(Collection<BlockedItem<?>>Collection<BlockedNode> newItemsnewlyAddedOrUpdatedNodes);
}

public interface JobManagerGateway extends BlocklistListener {
    //...
}

public interface ResourceManagerGateway extends BlocklistListener {     
    //...
}  

Enrich TaskManagerLocation with node information

In order to support blocked nodesblocked nodes, it is necessary to know the node where the task is located. To do that, we need to add a node identifier into TaskManagerLocation. This node identifier should be set by the resource manager when requesting new task managers.

Code Block
titleTaskManagerLocation
public class TaskManagerLocation {

    public String getNodeId();

    //...
}


Compatibility, Deprecation, and Migration Plan

The blocklist mechanism is only used when speculative execution is enabled, which entails that Flink's default behavior won't change.

...

Limitations

No integration with Flink's web UI

This FLIP does not modify the web UI, but it's in our plan. Currently, we have a preliminary idea of the UI intergration, including improve the slots information displaying and add a page to show the blocklist information.

No support for JM failover

Currently, the blocklist information will be lost after JM failover.  In the future, we may persist the blocklist information in HA to support JM failover

Compatibility, Deprecation, and Migration Plan

The blocklist mechanism will be an optional feature which the user has to activate explicitly by setting the config option cluster.resource-blocklist.enabled: true. This entails that Flink's default behavior won't change.

Future improvements

Automatically detect abnormal resources

We may introduce an auto-detection mechanism in the future. To do that, we need to introduce a pluggable abnormal resources detector and allow users to load their own implementations. This means the detector needs to be opened to users as a public interface, which requires more thought and discussion.


Test Plan

  1. The changes will be covered by unit and IT cases.
  2. Test the functionality in a real Standanlone/Yarn/Kubernetes cluster.

...