You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by dd...@apache.org on 2009/03/13 06:02:22 UTC
svn commit: r753113 - in /hadoop/core/trunk/src:
mapred/org/apache/hadoop/mapred/JobHistory.java
test/org/apache/hadoop/mapred/TestJobHistory.java
Author: ddas
Date: Fri Mar 13 05:02:21 2009
New Revision: 753113
URL: http://svn.apache.org/viewvc?rev=753113&view=rev
Log:
HADOOP-5449. Fixes the history cleaner thread. Contributed by Amareshwari Sriramadasu.
Modified:
hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/JobHistory.java
hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestJobHistory.java
Modified: hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/JobHistory.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/JobHistory.java?rev=753113&r1=753112&r2=753113&view=diff
==============================================================================
--- hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/JobHistory.java (original)
+++ hadoop/core/trunk/src/mapred/org/apache/hadoop/mapred/JobHistory.java Fri Mar 13 05:02:21 2009
@@ -98,6 +98,7 @@
private static final String SECONDARY_FILE_SUFFIX = ".recover";
private static long jobHistoryBlockSize = 0;
private static String jobtrackerHostname;
+ private static JobConf jtConf;
/**
* Record types are identifiers for each line of log in history files.
* A record type appears as the first token in a single line of log.
@@ -160,6 +161,7 @@
jobHistoryBlockSize =
conf.getLong("mapred.jobtracker.job.history.block.size",
3 * 1024 * 1024);
+ jtConf = conf;
} catch(IOException e) {
LOG.error("Failed to initialize JobHistory log file", e);
disableHistory = true;
@@ -1676,7 +1678,7 @@
static final long THIRTY_DAYS_IN_MS = 30 * ONE_DAY_IN_MS;
private long now;
private static boolean isRunning = false;
- private static long lastRan;
+ private static long lastRan = 0;
/**
* Cleans up history data.
@@ -1687,26 +1689,34 @@
}
now = System.currentTimeMillis();
// clean history only once a day at max
- if (lastRan ==0 || (now - lastRan) < ONE_DAY_IN_MS){
+ if (lastRan != 0 && (now - lastRan) < ONE_DAY_IN_MS) {
return;
}
lastRan = now;
isRunning = true;
- File[] oldFiles = new File(LOG_DIR).listFiles(new FileFilter(){
- public boolean accept(File file){
- // delete if older than 30 days
- if (now - file.lastModified() > THIRTY_DAYS_IN_MS){
- return true;
+ try {
+ Path logDir = new Path(LOG_DIR);
+ FileSystem fs = logDir.getFileSystem(jtConf);
+ FileStatus[] historyFiles = fs.listStatus(logDir);
+ // delete if older than 30 days
+ if (historyFiles != null) {
+ for (FileStatus f : historyFiles) {
+ if (now - f.getModificationTime() > THIRTY_DAYS_IN_MS) {
+ fs.delete(f.getPath(), true);
+ LOG.info("Deleting old history file : " + f.getPath());
}
- return false;
}
- });
- for(File f : oldFiles){
- f.delete();
- LOG.info("Deleting old history file : " + f.getName());
+ }
+ } catch (IOException ie) {
+ LOG.info("Error cleaning up history directory" +
+ StringUtils.stringifyException(ie));
}
isRunning = false;
}
+
+ static long getLastRan() {
+ return lastRan;
+ }
}
/**
Modified: hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestJobHistory.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestJobHistory.java?rev=753113&r1=753112&r2=753113&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestJobHistory.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/mapred/TestJobHistory.java Fri Mar 13 05:02:21 2009
@@ -970,16 +970,20 @@
// existing in history file
RunningJob job = UtilsForTests.runJobSucceed(conf, inDir, outDir);
validateJobHistoryJobStatus(job.getID(), conf, "SUCCESS");
+ long historyCleanerRanAt = JobHistory.HistoryCleaner.getLastRan();
+ assertTrue(historyCleanerRanAt != 0);
// Run a job that will be failed and validate its job status
// existing in history file
job = UtilsForTests.runJobFail(conf, inDir, outDir);
validateJobHistoryJobStatus(job.getID(), conf, "FAILED");
+ assertTrue(historyCleanerRanAt == JobHistory.HistoryCleaner.getLastRan());
// Run a job that will be killed and validate its job status
// existing in history file
job = UtilsForTests.runJobKill(conf, inDir, outDir);
validateJobHistoryJobStatus(job.getID(), conf, "KILLED");
+ assertTrue(historyCleanerRanAt == JobHistory.HistoryCleaner.getLastRan());
} finally {
if (mr != null) {