\
Background\ \ Note: In Dolphinscheduler, offline tasks have a complete lifecycle, such as stopping, pausing, resuming from pause, rerunning, etc., all are organized in the form of DAG (Directed Acyclic Graph) for T+1 offline tasks.
Dolphinscheduler DAG Implementationorg.apache.dolphinscheduler.common.graph.DAG
Three important data structures of DAG:
// Vertex information private final Map\ Example below:
DAG\ Source code analysis: org.apache.dolphinscheduler.common.graph.DAG#addEdge
public boolean addEdge(Node fromNode, Node toNode, EdgeInfo edge, boolean createNode) { lock.writeLock().lock(); try { // TODO Whether the edge can be added if (!isLegalAddEdge(fromNode, toNode, createNode)) { log.error("serious error: add edge({} -> {}) is invalid, cause cycle!", fromNode, toNode); return false; } // TODO Add nodes addNodeIfAbsent(fromNode, null); addNodeIfAbsent(toNode, null); // TODO Add edges addEdge(fromNode, toNode, edge, edgesMap); addEdge(toNode, fromNode, edge, reverseEdgesMap); return true; } finally { lock.writeLock().unlock(); } } private boolean isLegalAddEdge(Node fromNode, Node toNode, boolean createNode) { // TODO If fromNode and toNode are the same vertex, this edge cannot be added if (fromNode.equals(toNode)) { log.error("edge fromNode({}) can't equals toNode({})", fromNode, toNode); return false; } // TODO If not creating a node, meaning fromNode and toNode must be existing vertices if (!createNode) { if (!containsNode(fromNode) || !containsNode(toNode)) { log.error("edge fromNode({}) or toNode({}) is not in vertices map", fromNode, toNode); return false; } } // Whether an edge can be successfully added(fromNode -> toNode), need to determine whether the // DAG has a cycle! // TODO Get the number of nodes int verticesCount = getNodesCount(); QueueThe DAG class is a basic general-purpose DAG tool class, and DagHelper is a business tool class that assembles task definitions and relationships between task definitions into a DAG.
\ org.apache.dolphinscheduler.server.master.graph.WorkflowGraphFactory#createWorkflowGraph
public IWorkflowGraph createWorkflowGraph(ProcessInstance workflowInstance) throws Exception { // TODO Here is actually to get the number of tasks and their relationships corresponding to the process instance List\ org.apache.dolphinscheduler.service.utils.DagHelper#generateFlowDag
public static ProcessDag generateFlowDag( List\ Set destTaskNodeList and taskNodeRelations
org.apache.dolphinscheduler.service.utils.DagHelper#buildDagGraph
public static DAG\
All Rights Reserved. Copyright , Central Coast Communications, Inc.