public TrackingTask(Task task, long interval, TimeUnit timeUnit) { long now = System.currentTimeMillis(); long timeToRun = now + timeUnit.toMillis(interval); LOG.debug(String.format("Task %s queued to run %s.", task.getTaskId(), timeToRun <= now ? "now" : "at " + timeToRun)); queuedTasks.putIfAbsent(task.getTaskId(), timeToRun); this.underlyingTask = task; }
@Override public void registerNewTask(Task task) { try { this.scheduledReporters.put(task.getTaskId(), scheduleTaskMetricsUpdater(new TaskMetricsUpdater(task), task)); } catch (RejectedExecutionException ree) { LOGGER.error(String.format("Scheduling of task state reporter for task %s was rejected", task.getTaskId())); } }
@Override public void registerNewTask(Task task) { try { this.scheduledReporters.put(task.getTaskId(), scheduleTaskMetricsUpdater(new TaskMetricsUpdater(task), task)); } catch (RejectedExecutionException ree) { LOG.error(String.format("Scheduling of task state reporter for task %s was rejected", task.getTaskId())); } }
/** * Execute a {@link Task}. * * @param task {@link Task} to be executed */ public void execute(Task task) { LOG.info(String.format("Executing task %s", task.getTaskId())); this.taskExecutor.execute(new TrackingTask(task)); }
/** * Submit a {@link Task} to run. * * @param task {@link Task} to be submitted * @return a {@link java.util.concurrent.Future} for the submitted {@link Task} */ public Future<?> submit(Task task) { LOG.info(String.format("Submitting task %s", task.getTaskId())); return this.taskExecutor.submit(new TrackingTask(task)); }
@Override public void registerNewTask(Task task) { try { scheduleTaskMetricsUpdater(new MRTaskMetricsUpdater(task, this.context), task); } catch (RejectedExecutionException ree) { LOG.error(String.format("Scheduling of task state reporter for task %s was rejected", task.getTaskId())); } }
private void onStart(long startTime) { Long queueTime = queuedTasks.remove(this.underlyingTask.getTaskId()); long workUnitCreationTime = this.underlyingTask.getTaskContext().getTaskState().getPropAsLong(ConfigurationKeys.WORK_UNIT_CREATION_TIME_IN_MILLIS, 0); long timeInQueue = startTime - queueTime; long timeSinceWorkUnitCreation = startTime - workUnitCreationTime; taskCreateAndRunTimer.update(timeSinceWorkUnitCreation, TimeUnit.MILLISECONDS); LOG.debug(String.format("Task %s started. Saving queued time of %d ms to history.", underlyingTask.getTaskId(), timeInQueue)); queuedTaskTimeHistorical.putIfAbsent(System.currentTimeMillis(), timeInQueue); runningTaskCount.inc(); } }
/** * A method that shuts down all running tasks managed by this instance. * TODO: Call this from the right place. */ public void shutdownTasks() throws InterruptedException { log.info("Shutting down tasks"); for (Task task: this.tasks) { task.shutdown(); } for (Task task : this.tasks) { task.awaitShutdown(1000); } for (Task task : this.tasks) { if (task.cancel()) { log.info("Task {} cancelled.", task.getTaskId()); } else { log.info("Task {} could not be cancelled.", task.getTaskId()); } } }
@Override public void onTaskCommitCompletion(Task task) { if (GobblinMetrics.isEnabled(task.getTaskState().getWorkunit())) { // Update record-level metrics after the task is done task.updateRecordMetrics(); task.updateByteMetrics(); } // Cancel the task state reporter associated with this task. The reporter might // not be found for the given task because the task fails before the task is // registered. So we need to make sure the reporter exists before calling cancel. if (this.scheduledReporters.containsKey(task.getTaskId())) { this.scheduledReporters.remove(task.getTaskId()).cancel(false); } LOGGER.info(String .format("Task %s completed in %dms with state %s", task.getTaskId(), task.getTaskState().getTaskDuration(), task.getTaskState().getWorkingState())); }
String taskId = task.getTaskId(); log.info("Writing task state for task " + task.getTaskId()); taskStateStore.put(task.getJobId(), task.getTaskId() + AbstractJobLauncher.TASK_STATE_STORE_TABLE_SUFFIX, task.getTaskState()); for (Task task : tasks) { if (task.getTaskState().contains(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY)) { log.error(String.format("Task %s failed due to exception: %s", task.getTaskId(), task.getTaskState().getProp(ConfigurationKeys.TASK_FAILURE_EXCEPTION_KEY))); taskStateStore.put(task.getJobId(), task.getTaskId() + TASK_STATE_STORE_SUCCESS_MARKER_SUFFIX, task.getTaskState());
/** * Retry a failed {@link Task}. * * @param task failed {@link Task} to be retried */ public void retry(Task task) { if (GobblinMetrics.isEnabled(task.getTaskState().getWorkunit()) && task.getTaskState().contains(ConfigurationKeys.FORK_BRANCHES_KEY)) { // Adjust metrics to clean up numbers from the failed task task.getTaskState() .adjustJobMetricsOnRetry(task.getTaskState().getPropAsInt(ConfigurationKeys.FORK_BRANCHES_KEY)); } // Task retry interval increases linearly with number of retries long interval = task.getRetryCount() * this.retryIntervalInSeconds; // Schedule the retry of the failed task this.taskExecutor.schedule(new TrackingTask(task, interval, TimeUnit.SECONDS), interval, TimeUnit.SECONDS); LOG.info(String.format("Scheduled retry of failed task %s to run in %d seconds", task.getTaskId(), interval)); task.incrementRetryCount(); }
@Override public void onTaskCommitCompletion(Task task) { WorkUnit workUnit = task.getTaskState().getWorkunit(); if (GobblinMetrics.isEnabled(workUnit)) { task.updateRecordMetrics(); task.updateByteMetrics(); if (workUnit.getPropAsBoolean(ConfigurationKeys.MR_REPORT_METRICS_AS_COUNTERS_KEY, ConfigurationKeys.DEFAULT_MR_REPORT_METRICS_AS_COUNTERS)) { updateCounters(task); } } LOG.info(String .format("Task %s completed running in %dms with state %s", task.getTaskId(), task.getTaskState().getTaskDuration(), task.getTaskState().getWorkingState())); }
public TrackingTask(Task task, long interval, TimeUnit timeUnit) { long now = System.currentTimeMillis(); long timeToRun = now + timeUnit.toMillis(interval); LOG.debug(String.format("Task %s queued to run %s.", task.getTaskId(), timeToRun <= now ? "now" : "at " + timeToRun)); queuedTasks.putIfAbsent(task.getTaskId(), timeToRun); this.underlyingTask = task; }
@Override public void registerNewTask(Task task) { try { this.scheduledReporters.put(task.getTaskId(), scheduleTaskMetricsUpdater(new TaskMetricsUpdater(task), task)); } catch (RejectedExecutionException ree) { LOG.error(String.format("Scheduling of task state reporter for task %s was rejected", task.getTaskId())); } }
/** * Execute a {@link Task}. * * @param task {@link Task} to be executed */ public void execute(Task task) { LOG.info(String.format("Executing task %s", task.getTaskId())); this.taskExecutor.execute(new TrackingTask(task)); }
@Override public void registerNewTask(Task task) { try { this.scheduledReporters.put(task.getTaskId(), scheduleTaskMetricsUpdater(new TaskMetricsUpdater(task), task)); } catch (RejectedExecutionException ree) { LOGGER.error(String.format("Scheduling of task state reporter for task %s was rejected", task.getTaskId())); } }
/** * Submit a {@link Task} to run. * * @param task {@link Task} to be submitted * @return a {@link java.util.concurrent.Future} for the submitted {@link Task} */ public Future<?> submit(Task task) { LOG.info(String.format("Submitting task %s", task.getTaskId())); return this.taskExecutor.submit(new TrackingTask(task)); }
@Override public void registerNewTask(Task task) { try { scheduleTaskMetricsUpdater(new MRTaskMetricsUpdater(task, this.context), task); } catch (RejectedExecutionException ree) { LOG.error(String.format("Scheduling of task state reporter for task %s was rejected", task.getTaskId())); } }
private void onStart(long startTime) { Long queueTime = queuedTasks.remove(this.underlyingTask.getTaskId()); long workUnitCreationTime = this.underlyingTask.getTaskContext().getTaskState().getPropAsLong(ConfigurationKeys.WORK_UNIT_CREATION_TIME_IN_MILLIS, 0); long timeInQueue = startTime - queueTime; long timeSinceWorkUnitCreation = startTime - workUnitCreationTime; taskCreateAndRunTimer.update(timeSinceWorkUnitCreation, TimeUnit.MILLISECONDS); LOG.debug(String.format("Task %s started. Saving queued time of %d ms to history.", underlyingTask.getTaskId(), timeInQueue)); queuedTaskTimeHistorical.putIfAbsent(System.currentTimeMillis(), timeInQueue); runningTaskCount.inc(); } }