datax(12):调度源码解读AbstractScheduler「建议收藏」

datax(12):调度源码解读AbstractScheduler「建议收藏」datax的jobContainer最终会通过调度周期性的执行,今天把它看完;一、基类AbstractScheduler概述类继承关系全部方法二、AbstractScheduler的主要属性和方法1、主要属性/***脏数据行数检查器,用于运行中随时检查脏数据是否超过限制(脏数据行数,或脏数据百分比)*/privateErrorRecordCheckererrorLimit;/***积累容器通讯器,来处理JobContainer、Tas.

大家好,又见面了,我是你们的朋友全栈君。

datax的jobContainer最终会通过调度周期性的执行,今天把它看完;


一、基类AbstractScheduler概述

类继承关系
在这里插入图片描述

全部方法
在这里插入图片描述


二、AbstractScheduler的主要属性和方法

1、主要属性

  /** * 脏数据行数检查器,用于运行中随时检查脏数据是否超过限制(脏数据行数,或脏数据百分比) */
  private ErrorRecordChecker errorLimit;

  /** * 积累容器通讯器,来处理JobContainer、TaskGroupContainer和Task的通讯 */
  private AbstractContainerCommunicator containerCommunicator;

2、主要方法

  /** * 默认调度执行方法 <br> * 1 传入多个调度配置,获取报告时间+休息时间+jobId(赋值给全局jobId),生成错误记录检查类 * 2 给全局jobId赋值,生成错误记录检查类,生成容器通讯类(反馈任务信息) * 3 根据入参计算task的数量,开始所有taskGroup * * @param cfg List<Configuration> */
  public void schedule(List<Configuration> cfg) { 
   
    xxx
}
  /** * 开始所有的taskGroup,只允许本包的类访问 * * @param configurations List<Configuration> */
  protected abstract void startAllTaskGroup(List<Configuration> configurations);
 

三、谁调用AbstractScheduler的schedule

从JobContainer.schedule调用AbstractScheduler.schedule


四、schedule和startAllTaskGroup方法解析

schedule方法主要在AbstractScheduler实现
运行时序图

在这里插入图片描述

  /** * 默认调度执行方法 <br> * 1 传入多个调度配置,获取报告时间+休息时间+jobId(赋值给全局jobId),生成错误记录检查类 * 2 给全局jobId赋值,生成错误记录检查类,生成容器通讯类(反馈任务信息) * 3 根据入参计算task的数量,开始所有taskGroup * * @param cfg List<Configuration> */
  public void schedule(List<Configuration> cfg) { 
   
    Validate.notNull(cfg, "scheduler配置不能为空");
    int reportMillSec = cfg.get(0).getInt(DATAX_CORE_CONTAINER_JOB_REPORTINTERVAL, 30000);
    int sleepMillSec = cfg.get(0).getInt(DATAX_CORE_CONTAINER_JOB_SLEEPINTERVAL, 10000);

    this.jobId = cfg.get(0).getLong(CoreConstant.DATAX_CORE_CONTAINER_JOB_ID);
    errorLimit = new ErrorRecordChecker(cfg.get(0));
    //给 taskGroupContainer 的 Communication 注册
    this.containerCommunicator.registerCommunication(cfg);
    int taskCnt = calculateTaskCount(cfg);
    startAllTaskGroup(cfg);
    Communication lastComm = new Communication();
    long lastReportTimeStamp = System.currentTimeMillis();
    try { 
   
      while (true) { 
   
        /** * step 1: collect job stat * step 2: getReport info, then report it * step 3: errorLimit do check * step 4: dealSucceedStat(); * step 5: dealKillingStat(); * step 6: dealFailedStat(); * step 7: refresh last job stat, and then sleep for next while * * above steps, some ones should report info to DS * */
        Communication nowComm = this.containerCommunicator.collect();
        nowComm.setTimestamp(System.currentTimeMillis());
        LOG.debug(nowComm.toString());

        //汇报周期
        long now = System.currentTimeMillis();
        if (now - lastReportTimeStamp > reportMillSec) { 
   
          Communication comm = CommunicationTool.getReportCommunication(nowComm, lastComm, taskCnt);

          this.containerCommunicator.report(comm);
          lastReportTimeStamp = now;
          lastComm = nowComm;
        }

        errorLimit.checkRecordLimit(nowComm);
        if (nowComm.getState() == State.SUCCEEDED) { 
   
          LOG.info("Scheduler accomplished all tasks.");
          break;
        }

        if (isJobKilling(this.getJobId())) { 
   
          dealKillingStat(this.containerCommunicator, taskCnt);
        } else if (nowComm.getState() == State.FAILED) { 
   
          dealFailedStat(this.containerCommunicator, nowComm.getThrowable());
        }
        Thread.sleep(sleepMillSec);
      }
    } catch (InterruptedException e) { 
   
      // 以 failed 状态退出
      LOG.error("捕获到InterruptedException异常!", e);
      throw DataXException.asDataXException(FrameworkErrorCode.RUNTIME_ERROR, e);
    }
  }

startAllTaskGroup方法在ProcessInnerScheduler实现
运行时序图

在这里插入图片描述


  /** * 1、创建线程池 <br/> * 2、变量传入的cfgs,生成tgRunner,然后线程池执行 <br/> * 3、线程池关闭 <br/> * * @param cfgs List<Configuration> */
  @Override
  public void startAllTaskGroup(List<Configuration> cfgs) { 
   
    this.taskGroupContainerExecutorService = new ThreadPoolExecutor(cfgs.size(), cfgs.size(),
        0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>());
    for (Configuration taskGroupCfg : cfgs) { 
   
      TaskGroupContainerRunner taskGroupContainerRunner = newTaskGroupContainerRunner(taskGroupCfg);
      this.taskGroupContainerExecutorService.execute(taskGroupContainerRunner);
    }
    this.taskGroupContainerExecutorService.shutdown();
  }

注:

  1. 对源码进行略微改动,主要修改为 1 阿里代码规约扫描出来的,2 clean code;

  2. 所有代码都已经上传到github(master分支和dev),可以免费白嫖

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/145542.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 协调世界时utc_utc协调世界时什么意思

    协调世界时utc_utc协调世界时什么意思协调世界时UTC:又称世界标准时间或世界协调时间,简称UTC(从英文“CoordinatedUniversalTime”/法文“TempsUniverselCordonné”而来

    2022年8月2日
    8
  • nginx的负载均衡算法_redis负载均衡

    nginx的负载均衡算法_redis负载均衡1、轮询     就是按照时间顺序分配下一个请求的服务器。2、权值轮询     给每一个服务器加上权值,权值和分配的请求成正比,比较适应于服务器配置不均的情况。3、ip哈希     根据ip的哈希值分配,这样每个ip每次访问的服务器都相同,这样session的处理会容易些。4、响应时间动态分配   根据请求的响应时间来分配,时间越短,说明处理能力较强,这样会…

    2022年10月12日
    2
  • read digest_view the readme file

    read digest_view the readme file一、本文大纲系统调用的两种方式:中断门和快速调用_KUSER_SHARED_DATA结构使用cpuid指令判断当前CPU是否支持快速调用3环进0环需要更改的4个寄存器以ReadProcessMemory为例说明系统调用全过程重写ReadProcessMemory和WriteProcessMemoryint0x2e和sysenter都做了什么工作?二、中断门和快速调用以我的理解,系统调用,即从调用操作系统提供的3环API开始,到进0环,再到返回结果到3环的全过程

    2022年9月12日
    3
  • python写入txt文件中文乱码_python中怎么输入文件

    python写入txt文件中文乱码_python中怎么输入文件python写入txt文件出现省略号原因是print不完全,添加代码设置np.set_printoptions(threshold=np.nan)如果报错ValueError:thresholdmustbenumericandnon-NAN,trysys.maxsizeforuntruncatedrepresentation只需要importsys设置np.set_printoptions(threshold=sys.maxsize)将阈值设置在一个较大的数值就可以了.

    2022年9月1日
    4
  • java flowable_Flowable流程引擎入门[通俗易懂]

    java flowable_Flowable流程引擎入门[通俗易懂]Flowable是一个流行的轻量级的采用Java开发的业务流程引擎。通过Flowable流程引擎,我们可以部署BPMN2.0的流程定义(一般为XML文件),通过流程定义创建流程实例,查询和访问流程相关的实例与数据,等等。Flowable可以灵活地添加到我们的服务、应用、架构中,可以通过引入Flowablejar包,或者直接使用Flowable的RestAPI来进行业务流程引擎的操作。Flowa…

    2022年10月20日
    1
  • 【C++】0314算法阿里笔试题「建议收藏」

    【C++】0314算法阿里笔试题「建议收藏」一、题目二、自己的dfs的题解#include<bits/stdc++.h>usingnamespacestd;intres3=INT_MAX;inttransfet(vector<string>&tmp){intsum=0;for(auto&t:tmp){sum+=stoi(t);}returnsum;}voiddfs(stringstr,vector&l

    2022年9月8日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号