瀏覽代碼

HADOOP-794. Fix a divide-by-zero exception when a job specifies zero map tasks. Contributed by Owen.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@486810 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 年之前
父節點
當前提交
3adf710103

+ 3 - 0
CHANGES.txt

@@ -86,6 +86,9 @@ Trunk (unreleased changes)
 24. HADOOP-720.  Add an HDFS white paper to website.
     (Dhruba Borthakur via cutting) 
 
+25. HADOOP-794.  Fix a divide-by-zero exception when a job specifies
+    zero map tasks.  (omalley via cutting)
+
 
 Release 0.9.1 - 2006-12-06
 

+ 2 - 3
src/java/org/apache/hadoop/mapred/InputFormatBase.java

@@ -130,8 +130,7 @@ public abstract class InputFormatBase implements InputFormat {
       totalSize += fs.getLength(files[i]);
     }
 
-    long goalSize = totalSize / numSplits;   // start w/ desired num splits
-
+    long goalSize = totalSize / (numSplits == 0 ? 1 : numSplits);
     long minSize = Math.max(job.getLong("mapred.min.split.size", 1),
                             minSplitSize);
 
@@ -159,7 +158,7 @@ public abstract class InputFormatBase implements InputFormat {
         }
       }
     }
-    //LOG.info( "Total # of splits: " + splits.size() );
+    LOG.debug( "Total # of splits: " + splits.size() );
     return (FileSplit[])splits.toArray(new FileSplit[splits.size()]);
   }
 

+ 5 - 1
src/test/org/apache/hadoop/mapred/TestMiniMRWithDFS.java

@@ -174,7 +174,11 @@ public class TestMiniMRWithDFS extends TestCase {
           assertEquals("The\t1\nbrown\t1\nfox\t2\nhas\t1\nmany\t1\n" +
                        "quick\t1\nred\t1\nsilly\t1\nsox\t1\n", result);
           checkTaskDirectories(mr, new String[]{"job_0002"}, new String[]{"task_0002_m_000001_0"});
-          
+          // test with maps=0
+          jobConf = new JobConf();
+          result = launchWordCount(namenode, jobTrackerName, jobConf, 
+                                   "owen is oom", 0, 1);
+          assertEquals("is\t1\noom\t1\nowen\t1\n", result);
       } finally {
           if (fileSys != null) { fileSys.close(); }
           if (dfs != null) { dfs.shutdown(); }