Browse Source

commit 95b712ea53d706cee2450155f670bef9848ec9f9
Author: Lee Tucker <ltucker@yahoo-inc.com>
Date: Thu Jul 30 17:40:44 2009 -0700

Applying patch 2871577.mr693.patch


git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.20-security-patches@1076957 13f79535-47bb-0310-9956-ffa450edef68

Owen O'Malley 14 years ago
parent
commit
a7649defff

+ 22 - 0
src/mapred/org/apache/hadoop/mapred/JobHistory.java

@@ -103,6 +103,15 @@ public class JobHistory {
     FsPermission.createImmutable((short) 0740); // rwxr-----
   private static JobConf jtConf;
   private static Path DONE = null; // folder for completed jobs
+  /**
+   * A filter for conf files
+   */  
+  private static final PathFilter CONF_FILTER = new PathFilter() {
+    public boolean accept(Path path) {
+      return path.getName().endsWith("_conf.xml");
+    }
+  };
+
   /**
    * A class that manages all the files related to a job. For now 
    *   - writers : list of open files
@@ -937,6 +946,19 @@ public class JobHistory {
       }
     }
 
+    /**
+     * Delete job conf from the history folder.
+     */
+    static void deleteConfFiles() throws IOException {
+      LOG.info("Cleaning up config files from the job history folder");
+      FileSystem fs = new Path(LOG_DIR).getFileSystem(jtConf);
+      FileStatus[] status = fs.listStatus(new Path(LOG_DIR), CONF_FILTER);
+      for (FileStatus s : status) {
+        LOG.info("Deleting conf file " + s.getPath());
+        fs.delete(s.getPath(), false);
+      }
+    }
+
     /**
      * Move the completed job into the completed folder.
      * This assumes that the jobhistory file is closed and all operations on the

+ 8 - 0
src/mapred/org/apache/hadoop/mapred/JobTracker.java

@@ -1430,6 +1430,14 @@ public class JobTracker implements MRConstants, InterTrackerProtocol,
       Iterator<JobID> idIter = jobsToRecover.iterator();
       JobInProgress job = null;
       File jobIdFile = null;
+
+      // 0. Cleanup
+      try {
+        JobHistory.JobInfo.deleteConfFiles();
+      } catch (IOException ioe) {
+        LOG.info("Error in cleaning up job history folder", ioe);
+      }
+
       while (idIter.hasNext()) {
         JobID id = idIter.next();
         LOG.info("Trying to recover details of job " + id);

+ 9 - 0
src/test/org/apache/hadoop/mapred/TestJobTrackerRestart.java

@@ -487,6 +487,11 @@ public class TestJobTrackerRestart extends TestCase {
     String history = 
       JobHistory.JobInfo.getJobHistoryFileName(jip.getJobConf(), id);
     Path historyPath = JobHistory.JobInfo.getJobHistoryLogLocation(history);
+    // get the conf file name
+    String parts[] = history.split("_");
+    // jobtracker-hostname_jobtracker-identifier_conf.xml
+    String jobUniqueString = parts[0] + "_" + parts[1] + "_" +  id;
+    Path confPath = new Path(historyPath.getParent(), jobUniqueString + "_conf.xml");
     
     //  make sure that setup is launched
     while (jip.runningMaps() == 0) {
@@ -521,6 +526,10 @@ public class TestJobTrackerRestart extends TestCase {
     
     job1.waitForCompletion();
     job2.waitForCompletion();
+
+    // check if the old files are deleted
+    assertFalse("Old jobhistory file is not deleted", historyFS.exists(historyPath));
+    assertFalse("Old jobconf file is not deleted", historyFS.exists(confPath));
   }
   
   public void testJobTrackerRestart() throws IOException {