TaskTracker

main函数

JobTracker实现了线程接口,main方法创建一个JobTracker实例并且启动该线程

JobConf conf=new JobConf();
      // enable the server to track time spent waiting on locks
      ReflectionUtils.setContentionTracing
        (conf.getBoolean("tasktracker.contention.tracking", false));
      new TaskTracker(conf).run();


构造方法

TaskTracker在构造方法中先初始化部分变量,并在构造方法里调用initialize函数,

 this.server = new HttpServer("task", httpBindAddress, httpPort,
        httpPort == 0, conf);

 

initialize();


initialize函数

initialize函数完成reportServer的创建,负责向JobTracker报告状态;jobClient的创建,负责向JobTracker索要任务;然后创建一个mapLauncher和reduceLauncher并启动,负责启动map任务或者reduce任务。

 this.taskReportServer =
      RPC.getServer(this, bindAddress, tmpPort, 2 * max, false, this.fConf);
    this.taskReportServer.start();


 

this.jobClient = (InterTrackerProtocol) 
      RPC.waitForProxy(InterTrackerProtocol.class,
                       InterTrackerProtocol.versionID, 
                       jobTrackAddr, this.fConf);


 

    mapLauncher = new TaskLauncher(maxCurrentMapTasks);
    reduceLauncher = new TaskLauncher(maxCurrentReduceTasks);
    mapLauncher.start();
    reduceLauncher.start();


run函数

首先启动了清理线程,该线程不断从待清理的TaskTrackerAction队列里取出Action并处理。

startCleanupThreads();

 

调用了offerservice函数

offerService函数

offerService函数通过transmitHeartBeat传送心跳并获得任务

 

HeartbeatResponse heartbeatResponse = transmitHeartBeat(now);

 

获取任务后,根据任务的属性放到相应的队列,并等待后台的mapLauncher,reduceLauncher,taskCleanupThread等线程处理。注意到tasksToCleanup队列就是介绍run函数一节中提到的清理队列。

TaskTrackerAction[] actions = heartbeatResponse.getActions();

 

if (actions != null){ 
          for(TaskTrackerAction action: actions) {
            if (action instanceof LaunchTaskAction) {
              addToTaskQueue((LaunchTaskAction)action);
            } else if (action instanceof CommitTaskAction) {
              CommitTaskAction commitAction = (CommitTaskAction)action;
              if (!commitResponses.contains(commitAction.getTaskID())) {
                LOG.info("Received commit task action for " + 
                          commitAction.getTaskID());
                commitResponses.add(commitAction.getTaskID());
              }
            } else {
              tasksToCleanup.put(action);
            }
          }
        }


 


transmitHeartBeat函数

transmitHeartBeat正是通过jobClient的远程调用返回HeartbeatResponse

 HeartbeatResponse heartbeatResponse = jobClient.heartbeat(status, 
                                                              justStarted,
                                                              justInited,
                                                              askForNewTask, 
                                                              heartbeatResponseId);
      


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值