郭姐 發表於 2025-7-2 11:53:00

DolphinScheduler 6 个高频 SQL 操作技巧

<p>摘要: Apache DolphinScheduler系列4-后台SQL经验分享</p>
<p>关键词: 大数据、数据质量、数据调度</p>
<h2 id="整体说明">整体说明</h2>
<p>在调研了 DolphinScheduler 之后,在项目上实际使用了一段时间,有了一些后台SQL实际经验,分享如下。<br>
<img alt="" loading="lazy" src="https://img2024.cnblogs.com/other/2685289/202507/2685289-20250702115337481-358060917.jpg" class="lazyload"></p>
<p>进入DolphinScheduler 后台数据库,我这里使用的是MySQL数据库。</p>
<p>以任务名称包含“ods_xf_act” 的任务为例。</p>
<h2 id="一修改任务组操作">一、修改任务组操作</h2>
<pre><code>UPDATE t_ds_task_definition a
join t_ds_task_definition_log b on a.`code`=b.`code`and a.version=b.version
set a.task_group_id = 19,b.task_group_id=19
where a.name like'%ods_xf_act%'
</code></pre>
<h2 id="二批量修改任务执行类型">二、批量修改任务执行类型</h2>
<pre><code>UPDATE t_ds_process_definition a
join t_ds_process_definition_log b on a.code=b.code and a.version=b.version
set a.execution_type = 1,b.execution_type=1
where a.name like'%ods_xf_act%';
</code></pre>
<h2 id="三查看定时器配置情况">三、查看定时器配置情况</h2>
<p>根据此来选择配置定时器</p>
<pre><code>select crontab,count(*) from t_ds_schedules
groupby crontab
orderbycount(*) desc
</code></pre>
<h2 id="四批量更改定时器">四、批量更改定时器</h2>
<p>定时器,在前台页面修改很麻烦,一个个改很慢,所以想着从后台批量修改。</p>
<ol>
<li>确定需要更新的定时器列表</li>
</ol>
<pre><code>select t1.id,t1.process_definition_code,crontab,t2.name from t_ds_schedules t1
join t_ds_process_definition t2
on t1.process_definition_code = t2.`code`
wherenamelike'%ods_xf_act%'
and crontab like'%0 0 5 *%'
</code></pre>
<ol start="2">
<li>更新成需要的crontab定时器</li>
</ol>
<pre><code>update t_ds_schedules t1
join t_ds_process_definition t2
on t1.process_definition_code = t2.`code`
set t1.crontab = '0 0 11 * * ? *'
wherenamelike'%ods_xf_act%'
and crontab like'%0 0 5 *%'
</code></pre>
<ol start="3">
<li>更新成需要的crontab定时器触发表 由于定时器已经 5 -&gt; 11修改完成, 所以后面的where 条件都是 11</li>
</ol>
<pre><code>update qrtz_cron_triggers t1
set t1.CRON_EXPRESSION = '0 0 11 * * ? *'
where t1.TRIGGER_NAME in (
selectconcat("job_",t1.id) from t_ds_schedules t1
join t_ds_process_definition t2
on t1.process_definition_code = t2.`code`
wherenamelike'%ods_xf_act%'
and crontab like'%0 0 11 *%'
)
</code></pre>
<ol start="4">
<li>更新成最新crontab定时触发时间的起始时间 由于<code>NEXT_FIRE_TIME</code>有更新时差,所以往前推8小时</li>
</ol>
<pre><code>update qrtz_triggers t1
set t1.NEXT_FIRE_TIME = round(UNIX_TIMESTAMP(date_sub("2024-07-23 11:00:00", INTERVAL8HOUR) )*1000)
where t1.TRIGGER_NAME in (
selectconcat("job_",t1.id) from t_ds_schedules t1
join t_ds_process_definition t2
on t1.process_definition_code = t2.`code`
wherenamelike'%ods_xf_act%'
and crontab like'%0 0 11 *%'
)
</code></pre>
<h2 id="五通知策略修改为都不发仍然告警">五、通知策略修改为“都不发”,仍然告警</h2>
<p>现象: 原先选择“失败发”,后面修改为“都不发”<br>
<img alt="" loading="lazy" src="https://img2024.cnblogs.com/other/2685289/202507/2685289-20250702115337931-1713154836.jpg" class="lazyload"></p>
<p>原因: 原先有告警组,然后修改为都不发,原告警组后台并没有修改,是一个bug。</p>
<p>临时解决方案:</p>
<pre><code>select t1.*
from t_ds_schedules t1
join t_ds_process_definition t2
on t1.process_definition_code = t2.`code`
wherenamelike'%ods_xf_act%'
</code></pre>
<p>把warning_type = 0 的,对应warning_group_id 都修改为 0</p>
<p><img alt="" loading="lazy" src="https://img2024.cnblogs.com/other/2685289/202507/2685289-20250702115338212-406123659.jpg" class="lazyload"></p>
<h2 id="六任务组队列页面没有任务已用资源却占满">六、任务组队列,页面没有任务,已用资源却占满</h2>
<p>查看任务组列表</p>
<pre><code>select * from t_ds_task_group
orderby create_time desc

</code></pre>
<p>如果遇到任务组是满的,页面查询却没有任务,可以手动修改字段值图片<br>
<img alt="" loading="lazy" src="https://img2024.cnblogs.com/other/2685289/202507/2685289-20250702115338496-1388954297.jpg" class="lazyload"></p>
<p>查看任务组队列列表,找出没有完成,修改成已完成,就是修改值为2。</p>
<pre><code>-- t_ds_task_group_queue.`status` tinyint(4) DEFAULT '-1' COMMENT '-1: waiting1: running2: finished'

select * from t_ds_task_group_queue
where1=1
andstatus &lt;&gt; 2-- finished 完成
orderby create_time desc
</code></pre>
<p>查看任务列表,找出没有完成,修改成已完成,就是修改值为7。</p>
<pre><code>-- t_ds_task_instance.`state` tinyint(4) DEFAULT NULL COMMENT 'Status: 0 commit succeeded, 1 running, 2 prepare to pause, 3 pause, 4 prepare to stop, 5 stop, 6 fail, 7 succeed, 8 need fault tolerance, 9 kill, 10 wait for thread, 11 wait for dependency to complete'

-- id 是上面t_ds_task_group_queue的task_id

select * from t_ds_task_instance
where state &lt;&gt; 7-- success
andidin (
selectidfrom t_ds_task_group_queue
where1=1
andstatus &lt;&gt; 2-- finished 完成
orderby create_time desc
)
orderby submit_time desc
limit100
</code></pre>
<p>转载自鹏说大数据</p>
<p>原文链接:Apache DolphinScheduler系列4-后台SQL经验分享</p>
<blockquote>
<p>本文由 白鲸开源 提供发布支持!</p>
</blockquote><br><br>
来源:https://www.cnblogs.com/DolphinScheduler/p/18961275
頁: [1]
查看完整版本: DolphinScheduler 6 个高频 SQL 操作技巧