DS调度是一个分布式易扩展的可视化DAG工作流任务调度系统,它通过工作流将task关联在一起,形成一个有向无环的DAG图,在工作流中流程定义内容显得非常重要。当前版本(1.3.4)DS采用了一个比较笨重的方式存储流程定义内容数据,DS直接将流程定义内容以json的形式存储在t_ds_process_definition表中,存储字段是process_definition_json。(官方已有拆解计划见issue#4417)。由于存储形式是一个比较复杂的json,单独拿到process_definition_json字段的数据的时候理解起来非常麻烦,本篇将详细介绍process_definition_json字段中每个json字段的含义。我们从process_definition_json解析对象ProcessData一层一层向下分析
ProcessData
字段名 | 类型 | 示例 | 描述 |
tasks | List<TaskNode> |
| task list,任务list |
globalParams | List<Property> |
| global parameters,全局参数list |
timeout | int |
| 流程运行超时时间 |
tenantId | int | -1 | 租户id |
任务列表的 TaskNode对象
字段名 | 类型 | 示例 | 描述 |
id | String |
| 随机生成的节点id字符串 |
name | String |
| 任务名称 |
desc | String |
| 任务描述 |
type | String |
| 任务类型 |
runFlag | String |
| 运行标志 正常或者禁止 |
loc | String |
| 前端域 暂未发现该字段作用 |
maxRetryTimes | int |
| 最大重试次数 |
retryInterval | int |
| 重试时间单位 |
params | String |
| 参数信息json 需进一步解析 |
preTasks | String |
| 依赖的上一个任务 jsonArray的String形式, 需进一步解析 |
extras | String |
| 用户储存附加信息json 无实际意义 |
depList | List<String> |
| 等同于preTasks字段 |
dependence | String |
| 外部任务依赖关系json 需进一步解析 |
conditionResult | String |
| 依赖条件json 官方规划中暂不考虑 |
taskInstancePriority | String |
| 任务实例优先级json |
workerGroup | String |
| 工作组 |
workerGroupId | String |
| 工作组id |
timeout | String |
| 超时时间设置json |
上面表格标红的字段params、dependence是我们需要重点进一步讨论的字段。
params字段
参数信息json字段,涵盖了所有类型的任务的参数,我们根据任务类型一个个分析。
SUB_PROCESS->SubProcessParameters 子流程类型任务参数
字段名 | 类型 | 示例 | 描述 |
processDefinitionId | int |
| 子节点流程定义Id |
Shell->ShellParameters shell类型任务参数
字段名 | 类型 | 示例 | 描述 |
rawScript | String |
| shell脚本内容 |
resourceList | List<ResourceInfo> |
| shell中引用的资源信息列表 |
PROCEDURE->ProcedureParameters 存储过程类型任务参数
字段名 | 类型 | 示例 | 描述 |
type | String |
| 数据源类型 |
datasource | int |
| 数据源id |
method | String |
| 存储过程方法 |
SQL->SqlParameters sql类型任务参数
字段名 | 类型 | 示例 | 描述 |
type | String |
| 数据源类型 |
datasource | int |
| 数据源id |
sql | String |
| sql脚本 |
sqlType | int |
| sql类型[0:查询|1:非查询] |
udfs | String |
| udf list |
showType | String |
| sql结果展示方式 [0:表格|1:Text|2:附件|3:表格+附件] |
connParams | String |
| hive sql连接参数 |
preStatements | List<String> |
| 前置sql |
postStatements | List<String> |
| 后置sql |
title | String |
| sql邮件主题 |
receivers | String |
| 收件人 |
receiversCc | String |
| 抄送人 |
MR->MapreduceParameters Mapreduce类型任务参数
字段名 | 类型 | 示例 | 描述 |
mainJar | ResourceInfo |
| 主jar包 |
mainClass | String |
| 主函数的class |
mainArgs | String |
| 命令行参数 |
others | String |
| 其他参数 |
queue | String |
| mapreduce任务队列 |
resourceList | List<ResourceInfo> |
| 引用的资源列表 |
programType | ProgramType |
| 程序类型[0:java|1:scala|2:python] |
SPARK->SparkParameters spark类型任务参数
字段名 | 类型 | 示例 | 描述 |
mainJar | ResourceInfo |
| 主jar包 |
mainClass | String |
| 主函数的class |
deployMode | String |
| 部署方式 |
mainArgs | String |
| 命令行参数 |
driverCores | int |
| Driver内核数 |
driverMemory | String |
| Driver内存数 |
numExecutors | int |
| Executor数量 |
executorCores | int |
| Executor内核数 |
executorMemory | String |
| Executor内存数 |
others | String |
| 其他参数 |
queue | String |
| mapreduce任务队列 |
resourceList | List<ResourceInfo> |
| 引用的资源列表 |
programType | ProgramType |
| 程序类型[0:java|1:scala|2:python] |
sparkVersion | String |
| spark版本 |
PYTHON->PythonParameters python类型任务参数
字段名 | 类型 | 示例 | 描述 |
rawScript | String |
| python脚本内容 |
resourceList | List<ResourceInfo> |
| python中引用的资源信息列表 |
DEPENDENT->DependentParameters 依赖类型任务参数
字段名 | 类型 | 示例 | 描述 |
dependTaskList | List<DependentTaskModel> |
| 依赖关系组列表 |
relation | DependentRelation |
| 依赖关系 与/或 |
DependentTaskModel:
字段名 | 类型 | 示例 | 描述 |
dependItemList | List<DependentItem> |
| 依赖关系组 |
relation | DependentRelation |
| 依赖关系 与/或 |
DependentItem:
字段名 | 类型 | 示例 | 描述 |
definitionId | int |
| 依赖的流程定义Id |
depTasks | String |
| 依赖的流程定义内的任务集合 |
cycle | String |
| 依赖的周期 |
dateValue | String |
| 日期范围 |
dependResult | DependResult |
| 依赖结果 |
status | status |
| 执行状态 |
依赖关系组:一个依赖关系组中可能存在一个或多个同类型关系流程任务依赖,比如说一个依赖关系组中可以有一个/多个与关系依赖
依赖关系组列表:多个不同依赖关系组最终组成了一个依赖关系列表,他们之间有一个最终的关系是与/或
FLINK->FlinkParameters flink实时计算类型任务参数
字段名 | 类型 | 示例 | 描述 |
mainJar | ResourceInfo |
| 主jar包 |
mainClass | String |
| 主函数的class |
deployMode | String |
| 部署方式 |
mainArgs | String |
| 命令行参数 |
slot | int |
| slot数量 |
appName | String |
| Yarn 上的application name |
taskManager | int |
| taskManage数量 |
jobManagerMemory | String |
| jobManager内存数 |
taskManagerMemory | String |
| taskManager内存数 |
others | String |
| 其他参数 |
queue | String |
| mapreduce任务队列 |
resourceList | List<ResourceInfo> |
| 引用的资源列表 |
programType | ProgramType |
| 程序类型[0:java|1:scala|2:python] |
HTTP->HttpParameters http类型任务参数
字段名 | 类型 | 示例 | 描述 |
url | String |
| url |
httpMethod | HttpMethod |
| httpMethod请求类型 |
httpParams | List<HttpProperty> |
| http参数 |
httpCheckCondition | HttpCheckCondition |
| http请求结果校验条件类型 |
condition | String |
| http请求结果校验条件 |
DATAX->DataxParameters dataX类型任务参数
字段名 | 类型 | 示例 | 描述 |
customConfig | int |
| 是否自定义json |
json | String |
| 自定义json |
dsType | String |
| 数据源类型 |
dataSource | int |
| 数据源Id |
dtType | String |
| 目标数据源类型 |
dataTarget | int |
| 目标数据源Id |
sql | String |
| sql |
targetTable | String |
| 目标表 |
preStatements | List<String> |
| 目标库前置sql |
postStatements | List<String> |
| 目标库后置sql |
jobSpeedByte | int |
| 限流(字节数 KB) 0代表不限制 |
jobSpeedRecord | int |
| 限流(记录数) |
CONDITIONS->ConditionsParameters CONDITIONS类型任务 官方规划中 暂不做详细分析
字段名 | 类型 | 示例 | 描述 |
dependTaskList | List<DependentTaskModel> |
| 依赖关系组列表 |
relation | DependentRelation |
| 依赖关系 与/或 |
successNode | List<String> |
|
|
failedNode | List<String> |
|
|
SQOOP->SqoopParameters SQOOP类型任务 官方规划中 暂不做分析
dependence字段
dependence字段是一个存储了外部任务依赖关系信息的json字段,使用时会将json解析至DependentParameters对象,然后通过DependentParameters对象的实例进行引用。所以dependence字段内容和DependentParameters是一样的。
全局参数globalParams
Property对象
字段名 | 类型 | 示例 | 描述 |
prop | String |
| 参数key |
direct | Direct |
| procedure参数 |
type | DataType |
| 数据类型 |
value | String |
| 参数value |
总结:
DS的process_definition_json字段设计使用了一个longtext去存储,其实是很不优雅的,可读性也比较差,节点数目比较大的时候对资源的消耗也是比较多的,拆分process_definition_json是必然的。
如果想要对process_definition_json进行拆分,也必须要对process_definition_json字段json的每一个字段细节了解很清楚,我们才好着手去拆分他。
同时我们详细了解process_definition_json字段内容,对我们排查问题也是非常有帮助的,有时候一些任务可能是由于一些参数问题之类的导致失败,我们对process_definition_json够熟悉的话,这种问题能够很快定位到。
附:
流程定义表:
create table t_ds_process_definition
(
id int auto_increment comment 'key'
primary key,
name varchar(255) null comment 'process definition name',
version int null comment 'process definition version',
release_state tinyint null comment 'process definition release state:0:offline,1:online',
project_id int null comment 'project id',
user_id int null comment 'process definition creator id',
process_definition_json longtext null comment 'process definition json content',
description text null,
global_params text null comment 'global parameters',
flag tinyint null comment '0 not available, 1 available',
locations longtext null comment 'Node location information',
connects longtext null comment 'Node connection information',
receivers text null comment 'receivers',
receivers_cc text null comment 'cc',
create_time datetime null comment 'create time',
timeout int default 0 null comment 'time out',
tenant_id int default -1 not null comment 'tenant id',
update_time datetime null comment 'update time',
process_type tinyint default 2 null comment '流程类型(1:实时|2:离线)',
is_micro_batch tinyint null comment '是否微批流程(0:否|1:是)',
alert_type tinyint null comment '0:email,1:sms',
alert_url varchar(512) null comment '告警通知链接'
);
create index process_definition_index
on t_ds_process_definition (project_id, id);