diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogDeletionService.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogDeletionService.java index a80f9d7629e..b2f67e7b4c1 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogDeletionService.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/logaggregation/AggregatedLogDeletionService.java @@ -85,9 +85,9 @@ public void run() { 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."); } @@ -96,38 +96,43 @@ private static void deleteOldLogDirsFrom(Path dir, long cutoffMillis, FileSystem fs, ApplicationClientProtocol rmClient) { 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); + try { + 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) { + logException("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) { + logException("Could not delete "+appDir.getPath(), ex); + } } } + } catch(IOException e) { + logException("Error reading the contents of " + + appDir.getPath(), e); } - } catch(IOException e) { - logIOException( - "Error reading the contents of " + appDir.getPath(), e); } } + } catch (Exception e) { + logException("Could not delete " + appDir.getPath(), e); } } } catch (IOException e) { - logIOException("Could not read the contents of " + dir, e); + logException("Could not read the contents of " + dir, e); } } @@ -142,7 +147,7 @@ private static boolean shouldDeleteLogDir(FileStatus dir, long cutoffMillis, } } } 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 +177,14 @@ public ApplicationClientProtocol getRMClient() { } } - 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); } }