Kaynağa Gözat

Merge -r644998:644999 from trunk. Fixes: HADOOP-3152.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.17@645000 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 17 yıl önce
ebeveyn
işleme
4a29badb0d

+ 3 - 0
CHANGES.txt

@@ -209,6 +209,9 @@ Release 0.17.0 - Unreleased
     HADOOP-2841. Unwrap AccessControlException and FileNotFoundException
     from RemoteException for DFSClient. (shv)
 
+    HADOOP-3152.  Make index interval configuable when using
+    MapFileOutputFormat for map-reduce job.  (Rong-En Fan via cutting)
+
   OPTIMIZATIONS
 
     HADOOP-2790.  Fixed inefficient method hasSpeculativeTask by removing

+ 10 - 0
src/java/org/apache/hadoop/io/MapFile.java

@@ -62,6 +62,7 @@ public class MapFile {
     private SequenceFile.Writer data;
     private SequenceFile.Writer index;
 
+    final private static String INDEX_INTERVAL = "io.map.index.interval";
     private int indexInterval = 128;
 
     private long size;
@@ -139,6 +140,8 @@ public class MapFile {
                   Progressable progress)
       throws IOException {
 
+      this.indexInterval = conf.getInt(INDEX_INTERVAL, this.indexInterval);
+
       this.comparator = comparator;
       this.lastKey = comparator.newKey();
 
@@ -167,6 +170,13 @@ public class MapFile {
      */
     public void setIndexInterval(int interval) { indexInterval = interval; }
 
+    /** Sets the index interval and stores it in conf
+     * @see #getIndexInterval()
+     */
+    public static void setIndexInterval(Configuration conf, int interval) {
+      conf.setInt(INDEX_INTERVAL, interval);
+    }
+
     /** Close the map. */
     public synchronized void close() throws IOException {
       data.close();

+ 5 - 3
src/test/org/apache/hadoop/io/TestMapFile.java

@@ -38,10 +38,12 @@ public class TestMapFile extends TestCase {
       getName() + ".mapfile"); 
     FileSystem fs = FileSystem.getLocal(conf);
     Path qualifiedDirName = fs.makeQualified(dirName);
+    // Make an index entry for each insertion.
+    MapFile.Writer.setIndexInterval(conf, 1);
     MapFile.Writer writer = new MapFile.Writer(conf, fs,
       qualifiedDirName.toString(), Text.class, Text.class);
-    // Make an index entry for each insertion.
-    writer.setIndexInterval(1);
+    // Assert that the index interval is 1
+    assertEquals(1, writer.getIndexInterval());
     // Add entries up to 100 in intervals of ten.
     final int FIRST_KEY = 10;
     for (int i = FIRST_KEY; i < 100; i += 10) {
@@ -81,4 +83,4 @@ public class TestMapFile extends TestCase {
     closest = (Text)reader.getClosest(key, value, true);
     assertNull(closest);
   }
-}
+}