DolphinScheduler实例表备份、清理

news/2024/5/8 19:27:54/文章来源:https://blog.csdn.net/m0_51197424/article/details/126678183

😋DolphinScheduler实例表备份、清理

👊一、前言

  DolphinScheduler至今已经在项目中使用了将近一年,工作流实例和任务流实例都积累了百万级的数据量。在查看工作流实例和任务实例的时候,都要等待后台去查询数据库,感觉在使用上不太方便。所以想着以某一日期为界限,备份后再清除这部分数据。

在这里插入图片描述

👊二、查看实例表

🙇‍♀2.1 工作流实例

表结构

CREATE TABLE `t_ds_process_instance` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',`name` varchar(255) DEFAULT NULL COMMENT '流程定义名称',`process_definition_id` int(11) DEFAULT NULL COMMENT '流程定义ID',`state` tinyint(4) DEFAULT NULL COMMENT '流程实例状态:0提交成功,1运行,2准备暂停,3暂停,4准备停止,5停止,6失败,7成功,8需要容错,9终止,10等待线程,11等待依赖项完成',`recovery` tinyint(4) DEFAULT NULL COMMENT '流程实例故障转移标志:0:正常,1:故障转移实例',`start_time` datetime DEFAULT NULL COMMENT '流程实例开始事件',`end_time` datetime DEFAULT NULL COMMENT '流程实例结束事件',`run_times` int(11) DEFAULT NULL COMMENT '流程实例运行时间',`host` varchar(135) DEFAULT NULL COMMENT '主机',`command_type` tinyint(4) DEFAULT NULL COMMENT '命令类型',`command_param` text COMMENT 'json命令参数',`task_depend_type` tinyint(4) DEFAULT NULL COMMENT '任务取决于类型。0:仅当前节点,1:在节点之前,2:在节点之后',`max_try_times` tinyint(4) DEFAULT '0' COMMENT '最大尝试次数',`failure_strategy` tinyint(4) DEFAULT '0' COMMENT '失败策略。0:节点失败时结束进程,1:节点失败后继续运行其他节点',`warning_type` tinyint(4) DEFAULT '0' COMMENT '警告类型。0:无警告,1:进程成功时警告,2:进程失败时警告,3:成功时警告',`warning_group_id` int(11) DEFAULT NULL COMMENT '告警组ID',`schedule_time` datetime DEFAULT NULL COMMENT '调度事件',`command_start_time` datetime DEFAULT NULL COMMENT '命令开始事件',`global_params` text COMMENT '全局参数',`process_instance_json` longtext COMMENT '流程实例json(复制的过程定义的json)',`flag` tinyint(4) DEFAULT '1' COMMENT '标志',`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,`is_sub_process` int(11) DEFAULT '0' COMMENT '标志,进程是否为子进程',`executor_id` int(11) NOT NULL COMMENT '执行者ID',`locations` text COMMENT '节点位置信息',`connects` text COMMENT '节点连接信息',`history_cmd` text COMMENT '流程实例操作的历史命令',`dependence_schedule_times` text COMMENT '取决于火灾时间的安排',`process_instance_priority` int(11) DEFAULT NULL COMMENT '进程实例优先级。0最高,1高,2中等,3低,4最低',`worker_group` varchar(64) DEFAULT NULL COMMENT '工作组id',`timeout` int(11) DEFAULT '0' COMMENT '超时时间',`tenant_id` int(11) NOT NULL DEFAULT '-1' COMMENT '租户id',PRIMARY KEY (`id`),KEY `process_instance_index` (`process_definition_id`,`id`) USING BTREE,KEY `start_time_index` (`start_time`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

表数据案例

mysql> select * from t_ds_process_instance where start_time = '2022-09-02 10:45:03' \G;id: 839795name: 流程实例-0-1662086702806process_definition_id: 20state: 7recovery: 0start_time: 2022-09-02 10:45:03end_time: 2022-09-02 10:45:17run_times: 1host: 10.23.165.209:5678command_type: 6command_param: NULLtask_depend_type: 2max_try_times: 0failure_strategy: 1warning_type: 0warning_group_id: 0schedule_time: 2022-09-02 10:45:00command_start_time: 2022-09-02 10:45:02global_params: NULLprocess_instance_json: {"globalParams":[],"tasks":[{"conditionResult":{"successNode":[""],"failedNode":[""]},"description":"流程实例","runFlag":"NORMAL","type":"SQL","params":{"type":"POSTGRESQL","datasource":1,"sql":"select dws.p_dws_table()","udfs":"","sqlType":"0","sendEmail":false,"displayRows":10,"limit":"1","title":"","receivers":"123456789@qq.com","receiversCc":"","showType":"TABLE","localParams":[],"connParams":"","preStatements":[],"postStatements":[]},"timeout":{"strategy":"FAILED","interval":30,"enable":true},"maxRetryTimes":"0","taskInstancePriority":"MEDIUM","name":"dws.p_dws_table","dependence":{},"retryInterval":"1","preTasks":[],"id":"tasks-80778","workerGroup":"default"}],"tenantId":1,"timeout":0}flag: 1update_time: 2022-09-02 10:45:16is_sub_process: 0executor_id: 5locations: {"tasks-80778":{"name":"dws.p_dws_table","targetarr":"","nodenumber":"0","x":212,"y":98}}connects: []history_cmd: SCHEDULER
dependence_schedule_times: NULL
process_instance_priority: 2worker_group: defaulttimeout: 0tenant_id: 1

🙇‍♀2.2 任务实例

表结构

CREATE TABLE `t_ds_task_instance` (`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',`name` varchar(255) DEFAULT NULL COMMENT '任务名称',`task_type` varchar(64) DEFAULT NULL COMMENT '任务类型',`process_definition_id` int(11) DEFAULT NULL COMMENT '流程定义ID',`process_instance_id` int(11) DEFAULT NULL COMMENT '流程实例ID',`task_json` longtext COMMENT '任务内容Json',`state` tinyint(4) DEFAULT NULL COMMENT '状态:0提交成功,1运行,2准备暂停,3暂停,4准备停止,5停止,6失败,7成功,8需要容错,9终止,10等待线程,11等待依赖项完成',`submit_time` datetime DEFAULT NULL COMMENT '任务提交时间',`start_time` datetime DEFAULT NULL COMMENT '任务开始时间',`end_time` datetime DEFAULT NULL COMMENT '任务结束时间',`host` varchar(135) DEFAULT NULL COMMENT '任务运行主机',`execute_path` varchar(200) DEFAULT NULL COMMENT '主机中的任务执行路径',`log_path` varchar(200) DEFAULT NULL COMMENT '任务日志路径',`alert_flag` tinyint(4) DEFAULT NULL COMMENT '告警标志',`retry_times` int(4) DEFAULT '0' COMMENT '任务重试时间',`pid` int(4) DEFAULT NULL COMMENT '任务的PID',`app_link` text COMMENT 'yarn app id',`flag` tinyint(4) DEFAULT '1' COMMENT '0不可用,1可用',`retry_interval` int(4) DEFAULT NULL COMMENT '任务失败时的重试间隔',`max_retry_times` int(2) DEFAULT NULL COMMENT '最大重试时间',`task_instance_priority` int(11) DEFAULT NULL COMMENT '任务实例优先级:0最高,1高,2中等,3低,4最低',`worker_group` varchar(64) DEFAULT NULL COMMENT '工作组id',`executor_id` int(11) DEFAULT NULL,PRIMARY KEY (`id`),KEY `process_instance_id` (`process_instance_id`) USING BTREE,KEY `task_instance_index` (`process_definition_id`,`process_instance_id`) USING BTREE,CONSTRAINT `foreign_key_instance_id` FOREIGN KEY (`process_instance_id`) REFERENCES `t_ds_process_instance` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

表数据案例

ysql> select * from t_ds_task_instance where submit_time = '2022-09-02 10:34:13' \G;
*************************** 1. row ***************************id: 4089352name: p_dws_wms_table()task_type: SQLprocess_definition_id: 12process_instance_id: 839778task_json: {"conditionResult":"{\"successNode\":[\"\"],\"failedNode\":[\"\"]}","conditionsTask":false,"depList":["dws.p_dws_wms_table"],"dependence":"{}","forbidden":false,"id":"tasks-49159","maxRetryTimes":0,"name":"p_dws_wms_table()","params":"{\"postStatements\":[],\"connParams\":\"\",\"receiversCc\":\"\",\"udfs\":\"\",\"type\":\"POSTGRESQL\",\"title\":\"\",\"sql\":\"select dws.p_dws_wms_table()\",\"preStatements\":[],\"sqlType\":\"0\",\"sendEmail\":false,\"receivers\":\"\",\"datasource\":1,\"displayRows\":10,\"limit\":10000,\"showType\":\"TABLE\",\"localParams\":[]}","preTasks":"[\"dws.p_dws_wms_table\"]","retryInterval":1,"runFlag":"NORMAL","taskInstancePriority":"MEDIUM","taskTimeoutParameter":{"enable":true,"interval":30,"strategy":"FAILED"},"timeout":"{\"enable\":true,\"interval\":30,\"strategy\":\"FAILED\"}","type":"SQL","workerGroup":"default"}state: 7submit_time: 2022-09-02 10:34:13start_time: 2022-09-02 10:34:13end_time: 2022-09-02 10:34:15host: 10.23.165.209:1234execute_path: NULLlog_path: /opt/soft/dolphinscheduler/logs/12/839778/4089352.logalert_flag: 0retry_times: 0pid: 0app_link: NULLflag: 1retry_interval: 1max_retry_times: 0
task_instance_priority: 2worker_group: defaultexecutor_id: 3

👊三、查看实例取值逻辑

🙇‍♀3.1 工作流实例(queryProcessInstanceListPaging)

<select id="queryProcessInstanceListPaging"  resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">select instance.id, instance.command_type, instance.executor_id, instance.process_definition_version,instance.process_definition_code, instance.name, instance.state, instance.schedule_time, instance.start_time,instance.end_time, instance.run_times, instance.recovery, instance.host, instance.dry_run ,instance.next_process_instance_id,restart_timefrom t_ds_process_instance instancejoin t_ds_process_definition define ON instance.process_definition_code = define.codewhere instance.is_sub_process=0and define.project_code = #{projectCode}<if test="processDefinitionCode != 0">and instance.process_definition_code = #{processDefinitionCode}</if><if test="searchVal != null and searchVal != ''">and instance.name like concat('%', #{searchVal}, '%')</if><if test="startTime != null ">and instance.start_time > #{startTime} and instance.start_time <![CDATA[ <=]]> #{endTime}</if><if test="states != null and states.length > 0">and instance.state in<foreach collection="states" index="index" item="i" open="(" separator="," close=")">#{i}</foreach></if><if test="host != null and host != ''">and instance.host like concat('%', #{host}, '%')</if><if test="executorId != 0">and instance.executor_id = #{executorId}</if>order by instance.start_time desc,instance.end_time desc
</select>

🙇‍♀3.2 任务实例(queryTaskInstanceListPaging)

<select id="queryTaskInstanceListPaging" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">select<include refid="baseSqlV2"><property name="alias" value="instance"/></include>,process.name as process_instance_namefrom t_ds_task_instance instanceleft join t_ds_task_definition_log define on define.code=instance.task_code and define.version=instance.task_definition_versionleft join t_ds_process_instance process on process.id=instance.process_instance_idwhere define.project_code = #{projectCode}<if test="startTime != null">and instance.start_time > #{startTime} and instance.start_time <![CDATA[ <=]]> #{endTime}</if><if test="processInstanceId != 0">and instance.process_instance_id = #{processInstanceId}</if><if test="searchVal != null and searchVal != ''">and instance.name like concat('%', #{searchVal}, '%')</if><if test="taskName != null and taskName != ''">and instance.name=#{taskName}</if><if test="states != null and states.length != 0">and instance.state in<foreach collection="states" index="index" item="i" open="(" separator="," close=")">#{i}</foreach></if><if test="host != null and host != ''">and instance.host like concat('%', #{host}, '%')</if><if test="executorId != 0">and instance.executor_id = #{executorId}</if><if test="processInstanceName != null and processInstanceName != ''">and process.name like concat('%', #{processInstanceName}, '%')</if>order by instance.start_time desc
</select>

👊四、数据备份

  暂时打算的是,通过select data into outfile file.txt、load data infile file.txt into table的方式备份表中全部数据,为什么采用这种备份方案呢?因为我这里只想要备份t_ds_process_instancet_ds_task_instance两张表,表数据量达到百万级别,通过文件导入导出的备份效率比较高,用于备份全量数据。

  通过资料查询,针对百万级别的数据,如果采用mysqldump工具导出sql文件的方式,大概需要耗时几分钟,而导出的SQL文件大小也在几个G左右。如果后续需要需要恢复数据,使用source命令恢复一个几个G大小的SQL文件,是相对耗资源和耗时的。而通过select data into outfile file.txt、load data infile file.txt into table的方式,以文件的形式导入导出,可以在几分钟内完成百万级数据的备份和恢复工作。

  但是MySQL在实施这种备份方案的时候,需要检查MySQL是否配置了secure_file_priv参数,并开启。如果没有开启,需要修改mysql的参数文件my.cnf,并配置secure_file_priv。

mysql> show global variables like '%secure%';
+--------------------------+-----------------------+
| Variable_name            | Value                 |
+--------------------------+-----------------------+
| require_secure_transport | OFF                   |
| secure_auth              | ON                    |
| secure_file_priv         | /var/data/mysql-files/ |
+--------------------------+-----------------------+

  总之,小数据量的备份和恢复,可以使用mysqldump和source命令进行的。数据量大的时候,就可以通过这种方式以文件导出导入的时候进行备份和恢复,效率相对较高。

👊五、表数据拆分

  通过create table tablename nologging as select * from table备份部分数据。为什么要将数据拆分呢?因为每次查看任务实例,都会查询t_ds_task_instance表,通过create table方式,既可以方便我们通过SQL查询以往的数据,也减少了查看任务实例的等待时长。

  1.create table as select结构比create table再insert into性能好的多,该测试性能差三倍。2.使用nologging,性能提高一半。3.索引对insert的性能影响极大,10倍以上。

  默认情况下,建立表、插入数据等动作都会先写到重做日志中,然后建立相关的表并插入数据,也就是说,相当于数据库系统这个动作要操作两遍。降低了数据库建表的速度,当记录越多,速度越慢。而nologging选项就是让数据库在插入大量数据或其他复杂操作的时候记录写操作,而是直接建表或插入数据。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.luyixian.cn/news_show_5171.aspx

如若内容造成侵权/违法违规/事实不符,请联系dt猫网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【电商项目实战】拦截器(详细篇)

&#x1f341;博客主页&#xff1a;&#x1f449;不会压弯的小飞侠 ✨欢迎关注&#xff1a;&#x1f449;点赞&#x1f44d;收藏⭐留言✒ ✨系列专栏&#xff1a;&#x1f449;SpringBoot电商项目实战 ✨学习社区&#xff1a; &#x1f449;不会压弯的小飞侠 ✨知足上进&#x…

Python tkinter 制作一个经典的登录界面和点击事件

前言Tkinter(即 tk interface) 是 Python 标准 GUI 库,简称 “Tk”;从本质上来说,它是对 TCL/TK 工具包的一种 Python 接口封装。Tkinter 是 Python 自带的标准库,因此无须另行安装,它支持跨平台运行,不仅可以在 Windows 平台上运行,还支持在 Linux 和 Mac 平台上运行…

怎样在LaTeX中方便输入带圆圈的数字

这个也是这两天修改别人论文的时候得到的经验。正如这里所说&#xff1a;latex 如何添加圆圈数字&#xff1f;_Tsingke的博客-CSDN博客 如果使用\textcircled&#xff0c;数字编号大的时候&#xff0c;数字会跑到圆圈外面。但是上面这篇博客的解决方案太复杂了&#xff0c;就像…

电子数据取证-流程与技术

推荐公众号&#xff1a;安全猎人 专注于全栈攻防&#xff0c;学习笔记等&#xff1b; 原文url&#xff1a;https://mp.weixin.qq.com/s/hwpBcp-55ycXnSdObEffGg 电子数据取证流程与技术 根据某大佬经验&#xff0c;汇总出一系列取证流程、理论和模型&#xff1b; 在模型中&am…

pacman 升级软件包提示 “failed to commit transaction (invalid or corrupted package)“

很久没打开 WSL 2 里面的 Arch Linux, 想着更新一下软件包, 执行 pacman -Syu, 遇到 “signature is marginal trust” “failed to commit transaction (invalid or corrupted package)” 等错误. 观察输出的信息, 似乎提到了 “签名” “信任” 的问题 (signature … is marg…

快鲸智慧楼宇:助力商业地产快速实现数字化转型升级

作为国内领先的商业地产运营管理数字化服务商&#xff0c;快鲸搭建了集资产管理、合同管理、租客管理、财务管理、招商管理、物业管理等一套完整的 “商办招商营销管理空间资产运营管理租客运营服务体系”&#xff0c;致力于打造全场景商办地产标准化运营管理平台。 该平台具备…

C++之二叉树进阶|搜索树|key/value模型

&#x1f427;主页详情&#xff1a;Choice~的个人主页 &#x1f4e2;作者简介&#xff1a;&#x1f3c5;物联网领域创作者&#x1f3c5; and &#x1f3c5;阿里专家博主&#x1f3c5; and &#x1f3c5;华为云享专家&#x1f3c5; ✍️人生格言&#xff1a;最慢的步伐不是跬步&…

线程与进程的关联

上篇博客 我们说了进程 下面我来用一个我们回忆一下 其实啊 进程在频繁的创建 / 销毁的时候 是非常低效的 -因为创建的时候 要给进程分配资源(内存/文件) 赋值到CPU上 是一个大活 所以 有了线程 那咱们已经很了解进程了 直接说 线程 与 进程 的区别: 对比进程线程1包含线程2…

微服务项目:尚融宝(14)(前端平台:尚融宝管理系统路由配置)

认清现实&#xff0c;放弃幻想&#xff0c;准备斗争 一、组件定义 1、创建vue组件 在src/views文件夹下创建以下文件夹和文件 2、core/integral-grade/list.vue <template><div class"app-container">积分等级列表</div> </template> 3、…

文章组合生成-免费文章组合生成软件

文章组合生成软件&#xff0c;今天给大家分享一款免费的文章组合工具&#xff0c;自动从组文章生成段落目录详细参考图片。 网络的速度让一切的信息都是尽可能快的传达&#xff0c;为了给用户供给新鲜的信息&#xff0c;搜索引擎也是不断的增加抓取内容的频率&#xff0c;但是蜘…

设计模式-概述. 类图.软件设计原则详细讲解

1.1 软件设计模式的产生背景 "设计模式"最初并不是出现在软件设计中&#xff0c;而是被用于建筑领域的设计中。 1990年软件工程界开始研讨设计模式的话题&#xff0c;后来召开了多次关于设计模式的研讨会。直到1995 年&#xff0c;艾瑞克伽马&#xff08;ErichGamm…

kafka原理解读

一、Kafka Kafka是一个分布式的消息系统。 二、解决问题 消息系统通常被应用于异步处理、应用解耦、流量削峰、消息通信等场景。 异步处理 生产者将消息写入消息队列中&#xff0c;消费者异步拉取消息队列消息&#xff0c;从而提升消息处理能力。 应用解耦 Kafka作为消息传递…

【Linux操作系统】-- 多线程(三)-- 线程池+单例模式+读写者模型

目录 线程池 场景 代码实现 线程安全的单例模式 懒汉实现方式和懒汉实现方式 饿汉方式实现单例模式 懒汉方式实现单例模式 实战代码演练单例模式 读者写者模型 解释 基本操作 创建/销毁读写锁 读者锁和写者锁 解锁 伪代码理解读写锁 优先级 挂起等待锁vs自旋锁…

关于我在字节跳动青训营做了个抖音这件事

一、实践介绍 1.1项目核心信息 本项目实现了影视综艺榜单及其历史数据查询&#xff0c;实现个人页面展示、个人页面粉丝和关注列表、个人页面已发布视频列表及其详情页 1.2项目服务地址 https://github.com/gujunhe/douyin 1.3GitHub地址 https://github.com/gujunhe/dou…

centos8同步时间安装时间校准服务

多余的话都写在教程的后面&#xff0c;直接进入下面的操作命令。下面所有的操作都必须使用root账户来操作。切记。 #1. 查看当前时间 date#2. 添加wlnmp源 rpm -ivh http://mirrors.wlnmp.com/centos/wlnmp-release-centos.noarch.rpm#3. 安装ntp服务 yum install wntp#4. 时间…

Python爬虫之Js逆向案例(10)-爬虫数据批量写入mysql数据库

最近收到小伙伴们的私信&#xff0c;说如何将爬取的数据批量存到数据库中&#xff1f;数据入库也是童鞋们必须掌握的技能&#xff01;数据回来之后&#xff0c;肯定需要存放&#xff0c;实效高、数量少的可能大多存放在cvs文件中&#xff0c;通常情况都是要存放到数据库的&…

[JS入门到进阶] 7条关于 async await 的使用口诀,新学 async await?背10遍,以后要考!快收藏

我是HullQin&#xff0c;公众号线下聚会游戏的作者&#xff08;欢迎关注公众号&#xff0c;发送加微信&#xff0c;交个朋友&#xff09;&#xff0c;转发本文前需获得作者HullQin授权。我独立开发了《联机桌游合集》&#xff0c;是个网页&#xff0c;可以很方便的跟朋友联机玩…

蓝牙音响插着电源线就会一直有电流声怎么回事呢 All In One

蓝牙音响插着电源线就会一直有电流声怎么回事呢 All In One蓝牙音响插着电源线就会一直有电流声怎么回事呢 All In One周围存在电源的电磁干扰 ✅之前使用 USB 集线器的旁边上有一个电源插板,估计是收到了电磁干扰了 ❌直接使用电脑自带的 USB 接口连接即可 🚀refs https://…

软件测试概念总结

软件测试1.软件测试&#xff1a;2.软件测试的特点&#xff1a;3.软件测试和开发的区别&#xff1a;4.软件测试与调试的区别&#xff1a;5.优秀的软件测试人员具备的素质6.核心竞争力7.学习方法8.学习内容9.需求的概念10.用户需求11.软件需求12.生成测试用例的过程13.为什么需求…

GO语言自学_001_环境配置_windowx11_x64版本

GO语言自学_001_环境配置_windowx11_x64版本下载地址: https://golang.google.cn/ 1、看到那个下载按钮了么?点她!2、点击download到这个页面,根据电脑自身系统配置下载包。3、下载完毕后,运行.msi文件,一路next就可以了。本人电脑默认下载到C:\Program Files\Go路径。需要…