Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 67E4B200BAE for ; Fri, 28 Oct 2016 17:50:41 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 665B8160AE4; Fri, 28 Oct 2016 15:50:41 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id AE0D5160ACA for ; Fri, 28 Oct 2016 17:50:40 +0200 (CEST) Received: (qmail 26379 invoked by uid 500); 28 Oct 2016 15:50:39 -0000 Mailing-List: contact common-commits-help@hadoop.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list common-commits@hadoop.apache.org Received: (qmail 26370 invoked by uid 99); 28 Oct 2016 15:50:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Oct 2016 15:50:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B5A50E38B7; Fri, 28 Oct 2016 15:50:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jlowe@apache.org To: common-commits@hadoop.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: hadoop git commit: YARN-5027. NM should clean up app log dirs after NM restart. Contributed by sandflee (cherry picked from commit 7146359bfd436a76585fb1f3ea93716795308cec) Date: Fri, 28 Oct 2016 15:50:39 +0000 (UTC) archived-at: Fri, 28 Oct 2016 15:50:41 -0000 Repository: hadoop Updated Branches: refs/heads/branch-2.8 558e53b10 -> 83bb428e6 YARN-5027. NM should clean up app log dirs after NM restart. Contributed by sandflee (cherry picked from commit 7146359bfd436a76585fb1f3ea93716795308cec) Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/83bb428e Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/83bb428e Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/83bb428e Branch: refs/heads/branch-2.8 Commit: 83bb428e6c04385c9c6ab1ec29dd2bc3a6d84360 Parents: 558e53b Author: Jason Lowe Authored: Fri Oct 28 15:48:58 2016 +0000 Committer: Jason Lowe Committed: Fri Oct 28 15:50:22 2016 +0000 ---------------------------------------------------------------------- .../localizer/ResourceLocalizationService.java | 56 +++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/83bb428e/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java ---------------------------------------------------------------------- diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java index 30d5191..7cd38a4 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceLocalizationService.java @@ -239,6 +239,7 @@ public class ResourceLocalizationService extends CompositeService if (!stateStore.canRecover()|| stateStore.isNewlyCreated()) { cleanUpLocalDirs(lfs, delService); + cleanupLogDirs(lfs, delService); initializeLocalDirs(lfs); initializeLogDirs(lfs); } @@ -1343,9 +1344,9 @@ public class ResourceLocalizationService extends CompositeService } } - private void initializeLogDir(FileContext lfs, String logDir) { + private void initializeLogDir(FileContext fs, String logDir) { try { - lfs.mkdir(new Path(logDir), null, true); + fs.mkdir(new Path(logDir), null, true); } catch (FileAlreadyExistsException fe) { // do nothing } catch (IOException e) { @@ -1355,6 +1356,57 @@ public class ResourceLocalizationService extends CompositeService } } + private void cleanupLogDirs(FileContext fs, DeletionService del) { + for (String logDir : dirsHandler.getLogDirsForCleanup()) { + try { + cleanupLogDir(fs, del, logDir); + } catch (IOException e) { + LOG.warn("failed to cleanup app log dir " + logDir, e); + } + } + } + + private void cleanupLogDir(FileContext fs, DeletionService del, + String logDir) throws IOException { + if (!fs.util().exists(new Path(logDir))){ + return; + } + renameAppLogDir(logDir); + deleteAppLogDir(fs, del, logDir); + } + + private void renameAppLogDir(String logDir) throws IOException { + long currentTimeStamp = System.currentTimeMillis(); + RemoteIterator fileStatuses = + lfs.listStatus(new Path(logDir)); + if (fileStatuses != null) { + while (fileStatuses.hasNext()) { + FileStatus fileStatus = fileStatuses.next(); + String appName = fileStatus.getPath().getName(); + if (appName.matches("^application_\\d+_\\d+$")) { + lfs.rename(new Path(logDir, appName), + new Path(logDir, appName + "_DEL_" + currentTimeStamp)); + } + } + } + } + + private void deleteAppLogDir(FileContext fs, DeletionService del, + String logDir) throws IOException { + RemoteIterator fileStatuses = + fs.listStatus(new Path(logDir)); + if (fileStatuses != null) { + while (fileStatuses.hasNext()) { + FileStatus fileStatus = fileStatuses.next(); + String appName = fileStatus.getPath().getName(); + if (appName.matches("^application_\\d+_\\d+_DEL_\\d+$")) { + LOG.info("delete app log dir," + appName); + del.delete(null, fileStatus.getPath()); + } + } + } + } + private void cleanUpLocalDirs(FileContext lfs, DeletionService del) { for (String localDir : dirsHandler.getLocalDirsForCleanup()) { cleanUpLocalDir(lfs, del, localDir); --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org For additional commands, e-mail: common-commits-help@hadoop.apache.org