use of com.alibaba.jstorm.task.TkHbCacheTime in project jstorm by alibaba.
the class NimbusUtils method updateTaskHbStartTime.
public static void updateTaskHbStartTime(NimbusData data, Assignment assignment, String topologyId) {
Map<Integer, TkHbCacheTime> taskHBs = data.getTaskHeartbeatsCache(topologyId, true);
Map<Integer, Integer> taskStartTimes = assignment.getTaskStartTimeSecs();
for (Entry<Integer, Integer> entry : taskStartTimes.entrySet()) {
Integer taskId = entry.getKey();
Integer taskStartTime = entry.getValue();
TkHbCacheTime taskHB = taskHBs.get(taskId);
if (taskHB == null) {
taskHB = new TkHbCacheTime();
taskHBs.put(taskId, taskHB);
}
taskHB.setTaskAssignedTime(taskStartTime);
}
}
use of com.alibaba.jstorm.task.TkHbCacheTime in project jstorm by alibaba.
the class NimbusUtils method isTaskDead.
public static boolean isTaskDead(NimbusData data, String topologyId, Integer taskId) {
String idStr = " topology:" + topologyId + ",taskid:" + taskId;
TopologyTaskHbInfo topoTasksHbInfo = data.getTasksHeartbeat().get(topologyId);
Map<Integer, TaskHeartbeat> taskHbMap = null;
Integer taskReportTime = null;
if (topoTasksHbInfo != null) {
taskHbMap = topoTasksHbInfo.get_taskHbs();
if (taskHbMap != null) {
TaskHeartbeat tHb = taskHbMap.get(taskId);
taskReportTime = ((tHb != null) ? tHb.get_time() : null);
}
}
Map<Integer, TkHbCacheTime> taskHBs = data.getTaskHeartbeatsCache(topologyId, true);
TkHbCacheTime taskHB = taskHBs.get(taskId);
if (taskHB == null) {
LOG.info("No task heartbeat cache " + idStr);
if (topoTasksHbInfo == null || taskHbMap == null) {
LOG.info("No task hearbeat was reported for " + idStr);
return true;
}
taskHB = new TkHbCacheTime();
taskHB.update(taskHbMap.get(taskId));
taskHBs.put(taskId, taskHB);
return false;
}
if (taskReportTime == null || taskReportTime < taskHB.getTaskAssignedTime()) {
LOG.debug("No task heartbeat was reported for " + idStr);
// Task hasn't finish init
int nowSecs = TimeUtils.current_time_secs();
int assignSecs = taskHB.getTaskAssignedTime();
int waitInitTimeout = JStormUtils.parseInt(data.getConf().get(Config.NIMBUS_TASK_LAUNCH_SECS));
if (nowSecs - assignSecs > waitInitTimeout) {
LOG.info(idStr + " failed to init ");
return true;
} else {
return false;
}
}
// the left is zkReportTime isn't null
// task has finished initialization
int nimbusTime = taskHB.getNimbusTime();
int reportTime = taskHB.getTaskReportedTime();
int nowSecs = TimeUtils.current_time_secs();
if (nimbusTime == 0) {
// taskHB no entry, first time
// update taskHBtaskReportTime
taskHB.setNimbusTime(nowSecs);
taskHB.setTaskReportedTime(taskReportTime);
LOG.info("Update taskheartbeat to nimbus cache " + idStr);
return false;
}
if (reportTime != taskReportTime) {
// zk has been updated the report time
taskHB.setNimbusTime(nowSecs);
taskHB.setTaskReportedTime(taskReportTime);
LOG.debug(idStr + ",nimbusTime " + nowSecs + ",zkReport:" + taskReportTime + ",report:" + reportTime);
return false;
}
// the following is (zkReportTime == reportTime)
Integer taskHBTimeout = data.getTopologyTaskTimeout().get(topologyId);
if (taskHBTimeout == null)
taskHBTimeout = JStormUtils.parseInt(data.getConf().get(Config.NIMBUS_TASK_TIMEOUT_SECS));
if (taskId == topoTasksHbInfo.get_topologyMasterId())
taskHBTimeout = (taskHBTimeout / 2);
if (nowSecs - nimbusTime > taskHBTimeout) {
// task is dead
long ts = ((long) nimbusTime) * 1000;
Date lastTaskHBDate = new Date(ts);
StringBuilder sb = new StringBuilder();
sb.append(idStr);
sb.append(" last tasktime is ");
sb.append(nimbusTime);
sb.append(":").append(lastTaskHBDate);
sb.append(",current ");
sb.append(nowSecs);
sb.append(":").append(new Date(((long) nowSecs) * 1000));
LOG.debug(sb.toString());
return true;
}
return false;
}
Aggregations