1 | /** |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one |
---|
3 | * or more contributor license agreements. See the NOTICE file |
---|
4 | * distributed with this work for additional information |
---|
5 | * regarding copyright ownership. The ASF licenses this file |
---|
6 | * to you under the Apache License, Version 2.0 (the |
---|
7 | * "License"); you may not use this file except in compliance |
---|
8 | * with the License. You may obtain a copy of the License at |
---|
9 | * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | * |
---|
12 | * Unless required by applicable law or agreed to in writing, software |
---|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | * See the License for the specific language governing permissions and |
---|
16 | * limitations under the License. |
---|
17 | */ |
---|
18 | |
---|
19 | package org.apache.hadoop.mapreduce; |
---|
20 | |
---|
21 | import java.io.IOException; |
---|
22 | |
---|
23 | /** |
---|
24 | * <code>OutputCommitter</code> describes the commit of task output for a |
---|
25 | * Map-Reduce job. |
---|
26 | * |
---|
27 | * <p>The Map-Reduce framework relies on the <code>OutputCommitter</code> of |
---|
28 | * the job to:<p> |
---|
29 | * <ol> |
---|
30 | * <li> |
---|
31 | * Setup the job during initialization. For example, create the temporary |
---|
32 | * output directory for the job during the initialization of the job. |
---|
33 | * </li> |
---|
34 | * <li> |
---|
35 | * Cleanup the job after the job completion. For example, remove the |
---|
36 | * temporary output directory after the job completion. |
---|
37 | * </li> |
---|
38 | * <li> |
---|
39 | * Setup the task temporary output. |
---|
40 | * </li> |
---|
41 | * <li> |
---|
42 | * Check whether a task needs a commit. This is to avoid the commit |
---|
43 | * procedure if a task does not need commit. |
---|
44 | * </li> |
---|
45 | * <li> |
---|
46 | * Commit of the task output. |
---|
47 | * </li> |
---|
48 | * <li> |
---|
49 | * Discard the task commit. |
---|
50 | * </li> |
---|
51 | * </ol> |
---|
52 | * |
---|
53 | * @see org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter |
---|
54 | * @see JobContext |
---|
55 | * @see TaskAttemptContext |
---|
56 | * |
---|
57 | */ |
---|
58 | public abstract class OutputCommitter { |
---|
59 | /** |
---|
60 | * For the framework to setup the job output during initialization |
---|
61 | * |
---|
62 | * @param jobContext Context of the job whose output is being written. |
---|
63 | * @throws IOException if temporary output could not be created |
---|
64 | */ |
---|
65 | public abstract void setupJob(JobContext jobContext) throws IOException; |
---|
66 | |
---|
67 | /** |
---|
68 | * For cleaning up the job's output after job completion |
---|
69 | * |
---|
70 | * @param jobContext Context of the job whose output is being written. |
---|
71 | * @throws IOException |
---|
72 | */ |
---|
73 | public abstract void cleanupJob(JobContext jobContext) throws IOException; |
---|
74 | |
---|
75 | /** |
---|
76 | * Sets up output for the task. |
---|
77 | * |
---|
78 | * @param taskContext Context of the task whose output is being written. |
---|
79 | * @throws IOException |
---|
80 | */ |
---|
81 | public abstract void setupTask(TaskAttemptContext taskContext) |
---|
82 | throws IOException; |
---|
83 | |
---|
84 | /** |
---|
85 | * Check whether task needs a commit |
---|
86 | * |
---|
87 | * @param taskContext |
---|
88 | * @return true/false |
---|
89 | * @throws IOException |
---|
90 | */ |
---|
91 | public abstract boolean needsTaskCommit(TaskAttemptContext taskContext) |
---|
92 | throws IOException; |
---|
93 | |
---|
94 | /** |
---|
95 | * To promote the task's temporary output to final output location |
---|
96 | * |
---|
97 | * The task's output is moved to the job's output directory. |
---|
98 | * |
---|
99 | * @param taskContext Context of the task whose output is being written. |
---|
100 | * @throws IOException if commit is not |
---|
101 | */ |
---|
102 | public abstract void commitTask(TaskAttemptContext taskContext) |
---|
103 | throws IOException; |
---|
104 | |
---|
105 | /** |
---|
106 | * Discard the task output |
---|
107 | * |
---|
108 | * @param taskContext |
---|
109 | * @throws IOException |
---|
110 | */ |
---|
111 | public abstract void abortTask(TaskAttemptContext taskContext) |
---|
112 | throws IOException; |
---|
113 | } |
---|