|
@@ -85,49 +85,67 @@ public class AggregatedLogDeletionService extends AbstractService {
|
|
|
deleteOldLogDirsFrom(userDirPath, cutoffMillis, fs, rmClient);
|
|
|
}
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- logIOException("Error reading root log dir this deletion " +
|
|
|
- "attempt is being aborted", e);
|
|
|
+ } catch (Throwable t) {
|
|
|
+ logException("Error reading root log dir this deletion " +
|
|
|
+ "attempt is being aborted", t);
|
|
|
}
|
|
|
LOG.info("aggregated log deletion finished.");
|
|
|
}
|
|
|
|
|
|
private static void deleteOldLogDirsFrom(Path dir, long cutoffMillis,
|
|
|
FileSystem fs, ApplicationClientProtocol rmClient) {
|
|
|
+ FileStatus[] appDirs;
|
|
|
try {
|
|
|
- for(FileStatus appDir : fs.listStatus(dir)) {
|
|
|
- if(appDir.isDirectory() &&
|
|
|
- appDir.getModificationTime() < cutoffMillis) {
|
|
|
- boolean appTerminated =
|
|
|
- isApplicationTerminated(ApplicationId.fromString(appDir
|
|
|
- .getPath().getName()), rmClient);
|
|
|
- if(appTerminated && shouldDeleteLogDir(appDir, cutoffMillis, fs)) {
|
|
|
- try {
|
|
|
- LOG.info("Deleting aggregated logs in "+appDir.getPath());
|
|
|
- fs.delete(appDir.getPath(), true);
|
|
|
- } catch (IOException e) {
|
|
|
- logIOException("Could not delete "+appDir.getPath(), e);
|
|
|
- }
|
|
|
- } else if (!appTerminated){
|
|
|
- try {
|
|
|
- for(FileStatus node: fs.listStatus(appDir.getPath())) {
|
|
|
- if(node.getModificationTime() < cutoffMillis) {
|
|
|
- try {
|
|
|
- fs.delete(node.getPath(), true);
|
|
|
- } catch (IOException ex) {
|
|
|
- logIOException("Could not delete "+appDir.getPath(), ex);
|
|
|
- }
|
|
|
- }
|
|
|
+ appDirs = fs.listStatus(dir);
|
|
|
+ } catch (IOException e) {
|
|
|
+ logException("Could not read the contents of " + dir, e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (FileStatus appDir : appDirs) {
|
|
|
+ deleteAppDirLogs(cutoffMillis, fs, rmClient, appDir);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void deleteAppDirLogs(long cutoffMillis, FileSystem fs,
|
|
|
+ ApplicationClientProtocol rmClient,
|
|
|
+ FileStatus appDir) {
|
|
|
+ try {
|
|
|
+ if (appDir.isDirectory() &&
|
|
|
+ appDir.getModificationTime() < cutoffMillis) {
|
|
|
+ ApplicationId appId = ApplicationId.fromString(
|
|
|
+ appDir.getPath().getName());
|
|
|
+ boolean appTerminated = isApplicationTerminated(appId, rmClient);
|
|
|
+ if (!appTerminated) {
|
|
|
+ // Application is still running
|
|
|
+ FileStatus[] logFiles;
|
|
|
+ try {
|
|
|
+ logFiles = fs.listStatus(appDir.getPath());
|
|
|
+ } catch (IOException e) {
|
|
|
+ logException("Error reading the contents of "
|
|
|
+ + appDir.getPath(), e);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (FileStatus node : logFiles) {
|
|
|
+ if (node.getModificationTime() < cutoffMillis) {
|
|
|
+ try {
|
|
|
+ fs.delete(node.getPath(), true);
|
|
|
+ } catch (IOException ex) {
|
|
|
+ logException("Could not delete " + appDir.getPath(), ex);
|
|
|
}
|
|
|
- } catch(IOException e) {
|
|
|
- logIOException(
|
|
|
- "Error reading the contents of " + appDir.getPath(), e);
|
|
|
}
|
|
|
}
|
|
|
+ } else if (shouldDeleteLogDir(appDir, cutoffMillis, fs)) {
|
|
|
+ // Application is no longer running
|
|
|
+ try {
|
|
|
+ LOG.info("Deleting aggregated logs in " + appDir.getPath());
|
|
|
+ fs.delete(appDir.getPath(), true);
|
|
|
+ } catch (IOException e) {
|
|
|
+ logException("Could not delete " + appDir.getPath(), e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- } catch (IOException e) {
|
|
|
- logIOException("Could not read the contents of " + dir, e);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logException("Could not delete " + appDir.getPath(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -142,7 +160,7 @@ public class AggregatedLogDeletionService extends AbstractService {
|
|
|
}
|
|
|
}
|
|
|
} catch(IOException e) {
|
|
|
- logIOException("Error reading the contents of " + dir.getPath(), e);
|
|
|
+ logException("Error reading the contents of " + dir.getPath(), e);
|
|
|
shouldDelete = false;
|
|
|
}
|
|
|
return shouldDelete;
|
|
@@ -172,14 +190,14 @@ public class AggregatedLogDeletionService extends AbstractService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static void logIOException(String comment, IOException e) {
|
|
|
- if(e instanceof AccessControlException) {
|
|
|
- String message = e.getMessage();
|
|
|
+ private static void logException(String comment, Throwable t) {
|
|
|
+ if(t instanceof AccessControlException) {
|
|
|
+ String message = t.getMessage();
|
|
|
//TODO fix this after HADOOP-8661
|
|
|
message = message.split("\n")[0];
|
|
|
LOG.warn(comment + " " + message);
|
|
|
} else {
|
|
|
- LOG.error(comment, e);
|
|
|
+ LOG.error(comment, t);
|
|
|
}
|
|
|
}
|
|
|
|