Class OutputCommitter

java.lang.Object
org.apache.hadoop.mapreduce.OutputCommitter
org.apache.hadoop.mapred.OutputCommitter
Direct Known Subclasses:
FileOutputCommitter

@Public @Stable public abstract class OutputCommitter extends OutputCommitter
OutputCommitter describes the commit of task output for a Map-Reduce job.

The Map-Reduce framework relies on the OutputCommitter of the job to:

  1. Setup the job during initialization. For example, create the temporary output directory for the job during the initialization of the job.
  2. Cleanup the job after the job completion. For example, remove the temporary output directory after the job completion.
  3. Setup the task temporary output.
  4. Check whether a task needs a commit. This is to avoid the commit procedure if a task does not need commit.
  5. Commit of the task output.
  6. Discard the task commit.
The methods in this class can be called from several different processes and from several different contexts. It is important to know which process and which context each is called from. Each method should be marked accordingly in its documentation. It is also important to note that not all methods are guaranteed to be called once and only once. If a method is not guaranteed to have this property the output committer needs to handle this appropriately. Also note it will only be in rare situations where they may be called multiple times for the same task.
See Also:
  • Constructor Details

    • OutputCommitter

      public OutputCommitter()
  • Method Details

    • setupJob

      public abstract void setupJob(JobContext jobContext) throws IOException
      For the framework to setup the job output during initialization. This is called from the application master process for the entire job. This will be called multiple times, once per job attempt.
      Parameters:
      jobContext - Context of the job whose output is being written.
      Throws:
      IOException - if temporary output could not be created
    • cleanupJob

      @Deprecated public void cleanupJob(JobContext jobContext) throws IOException
      For cleaning up the job's output after job completion. This is called from the application master process for the entire job. This may be called multiple times.
      Parameters:
      jobContext - Context of the job whose output is being written.
      Throws:
      IOException
    • commitJob

      public void commitJob(JobContext jobContext) throws IOException
      For committing job's output after successful job completion. Note that this is invoked for jobs with final runstate as SUCCESSFUL. This is called from the application master process for the entire job. This is guaranteed to only be called once. If it throws an exception the entire job will fail.
      Parameters:
      jobContext - Context of the job whose output is being written.
      Throws:
      IOException
    • abortJob

      public void abortJob(JobContext jobContext, int status) throws IOException
      For aborting an unsuccessful job's output. Note that this is invoked for jobs with final runstate as JobStatus.FAILED or JobStatus.KILLED. This is called from the application master process for the entire job. This may be called multiple times.
      Parameters:
      jobContext - Context of the job whose output is being written.
      status - final runstate of the job
      Throws:
      IOException
    • setupTask

      public abstract void setupTask(TaskAttemptContext taskContext) throws IOException
      Sets up output for the task. This is called from each individual task's process that will output to HDFS, and it is called just for that task. This may be called multiple times for the same task, but for different task attempts.
      Parameters:
      taskContext - Context of the task whose output is being written.
      Throws:
      IOException
    • needsTaskCommit

      public abstract boolean needsTaskCommit(TaskAttemptContext taskContext) throws IOException
      Check whether task needs a commit. This is called from each individual task's process that will output to HDFS, and it is called just for that task.
      Parameters:
      taskContext -
      Returns:
      true/false
      Throws:
      IOException
    • commitTask

      public abstract void commitTask(TaskAttemptContext taskContext) throws IOException
      To promote the task's temporary output to final output location. If needsTaskCommit(TaskAttemptContext) returns true and this task is the task that the AM determines finished first, this method is called to commit an individual task's output. This is to mark that tasks output as complete, as commitJob(JobContext) will also be called later on if the entire job finished successfully. This is called from a task's process. This may be called multiple times for the same task, but different task attempts. It should be very rare for this to be called multiple times and requires odd networking failures to make this happen. In the future the Hadoop framework may eliminate this race.
      Parameters:
      taskContext - Context of the task whose output is being written.
      Throws:
      IOException - if commit is not
    • abortTask

      public abstract void abortTask(TaskAttemptContext taskContext) throws IOException
      Discard the task output. This is called from a task's process to clean up a single task's output that can not yet been committed. This may be called multiple times for the same task, but for different task attempts.
      Parameters:
      taskContext -
      Throws:
      IOException
    • isRecoverySupported

      @Deprecated public boolean isRecoverySupported()
      Deprecated.
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Overrides:
      isRecoverySupported in class OutputCommitter
      Returns:
      true if task output recovery is supported, false otherwise
      See Also:
    • isRecoverySupported

      public boolean isRecoverySupported(JobContext jobContext) throws IOException
      Is task output recovery supported for restarting jobs? If task output recovery is supported, job restart can be done more efficiently.
      Parameters:
      jobContext - Context of the job whose output is being written.
      Returns:
      true if task output recovery is supported, false otherwise
      Throws:
      IOException
      See Also:
    • isCommitJobRepeatable

      public boolean isCommitJobRepeatable(JobContext jobContext) throws IOException
      Returns true if an in-progress job commit can be retried. If the MR AM is re-run then it will check this value to determine if it can retry an in-progress commit that was started by a previous version. Note that in rare scenarios, the previous AM version might still be running at that time, due to system anomalies. Hence if this method returns true then the retry commit operation should be able to run concurrently with the previous operation. If repeatable job commit is supported, job restart can tolerate previous AM failures during job commit. By default, it is not supported. Extended classes (like: FileOutputCommitter) should explicitly override it if provide support.
      Parameters:
      jobContext - Context of the job whose output is being written.
      Returns:
      true repeatable job commit is supported, false otherwise
      Throws:
      IOException
    • isCommitJobRepeatable

      public boolean isCommitJobRepeatable(JobContext jobContext) throws IOException
      Description copied from class: OutputCommitter
      Returns true if an in-progress job commit can be retried. If the MR AM is re-run then it will check this value to determine if it can retry an in-progress commit that was started by a previous version. Note that in rare scenarios, the previous AM version might still be running at that time, due to system anomalies. Hence if this method returns true then the retry commit operation should be able to run concurrently with the previous operation. If repeatable job commit is supported, job restart can tolerate previous AM failures during job commit. By default, it is not supported. Extended classes (like: FileOutputCommitter) should explicitly override it if provide support.
      Overrides:
      isCommitJobRepeatable in class OutputCommitter
      Parameters:
      jobContext - Context of the job whose output is being written.
      Returns:
      true repeatable job commit is supported, false otherwise
      Throws:
      IOException
    • recoverTask

      public void recoverTask(TaskAttemptContext taskContext) throws IOException
      Recover the task output. The retry-count for the job will be passed via the MRConstants.APPLICATION_ATTEMPT_ID key in JobContext.getConfiguration() for the OutputCommitter. This is called from the application master process, but it is called individually for each task. If an exception is thrown the task will be attempted again.
      Parameters:
      taskContext - Context of the task whose output is being recovered
      Throws:
      IOException
    • setupJob

      public final void setupJob(JobContext jobContext) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Specified by:
      setupJob in class OutputCommitter
      Parameters:
      jobContext - Context of the job whose output is being written.
      Throws:
      IOException - if temporary output could not be created
    • cleanupJob

      @Deprecated public final void cleanupJob(JobContext context) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Overrides:
      cleanupJob in class OutputCommitter
      Parameters:
      context - Context of the job whose output is being written.
      Throws:
      IOException
    • commitJob

      public final void commitJob(JobContext context) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Overrides:
      commitJob in class OutputCommitter
      Parameters:
      context - Context of the job whose output is being written.
      Throws:
      IOException
    • abortJob

      public final void abortJob(JobContext context, JobStatus.State runState) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Overrides:
      abortJob in class OutputCommitter
      Parameters:
      context - Context of the job whose output is being written.
      runState - final runstate of the job
      Throws:
      IOException
    • setupTask

      public final void setupTask(TaskAttemptContext taskContext) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Specified by:
      setupTask in class OutputCommitter
      Parameters:
      taskContext - Context of the task whose output is being written.
      Throws:
      IOException
    • needsTaskCommit

      public final boolean needsTaskCommit(TaskAttemptContext taskContext) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Specified by:
      needsTaskCommit in class OutputCommitter
      Returns:
      true/false
      Throws:
      IOException
    • commitTask

      public final void commitTask(TaskAttemptContext taskContext) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Specified by:
      commitTask in class OutputCommitter
      Parameters:
      taskContext - Context of the task whose output is being written.
      Throws:
      IOException - if commit is not successful.
    • abortTask

      public final void abortTask(TaskAttemptContext taskContext) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Specified by:
      abortTask in class OutputCommitter
      Throws:
      IOException
    • recoverTask

      public final void recoverTask(TaskAttemptContext taskContext) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Overrides:
      recoverTask in class OutputCommitter
      Parameters:
      taskContext - Context of the task whose output is being recovered
      Throws:
      IOException
    • isRecoverySupported

      public final boolean isRecoverySupported(JobContext context) throws IOException
      This method implements the new interface by calling the old method. Note that the input types are different between the new and old apis and this is a bridge between the two.
      Overrides:
      isRecoverySupported in class OutputCommitter
      Parameters:
      context - Context of the job whose output is being written.
      Returns:
      true if task output recovery is supported, false otherwise
      Throws:
      IOException
      See Also: