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 2CFB5200D56 for ; Mon, 27 Nov 2017 21:24:16 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 2BC06160C21; Mon, 27 Nov 2017 20:24:16 +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 2CC3B160C1E for ; Mon, 27 Nov 2017 21:24:15 +0100 (CET) Received: (qmail 31206 invoked by uid 500); 27 Nov 2017 20:24:13 -0000 Mailing-List: contact commits-help@ambari.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ambari-dev@ambari.apache.org Delivered-To: mailing list commits@ambari.apache.org Received: (qmail 30402 invoked by uid 99); 27 Nov 2017 20:24:13 -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; Mon, 27 Nov 2017 20:24:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BB8D1DFE4B; Mon, 27 Nov 2017 20:24:12 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rlevas@apache.org To: commits@ambari.apache.org Date: Mon, 27 Nov 2017 20:24:45 -0000 Message-Id: <109c18da85844e1da21c8aab92368c54@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [35/49] ambari git commit: AMBARI-21569.Users randomly getting "HDFS020 Could not write file" exceptions while running query from Hive View(Venkata Sairam) archived-at: Mon, 27 Nov 2017 20:24:16 -0000 AMBARI-21569.Users randomly getting "HDFS020 Could not write file" exceptions while running query from Hive View(Venkata Sairam) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8e36662a Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8e36662a Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8e36662a Branch: refs/heads/branch-feature-AMBARI-20859 Commit: 8e36662ae1dffe7cb637b3d1edb38278f0111012 Parents: 5136021 Author: Venkata Sairam Authored: Thu Nov 23 15:48:52 2017 +0530 Committer: Venkata Sairam Committed: Thu Nov 23 15:48:52 2017 +0530 ---------------------------------------------------------------------- .../org/apache/ambari/view/utils/hdfs/HdfsApi.java | 16 +++++++++++++++- .../apache/ambari/view/utils/hdfs/HdfsUtil.java | 17 ++++++++++++----- 2 files changed, 27 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/8e36662a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsApi.java ---------------------------------------------------------------------- diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsApi.java b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsApi.java index 3db2081..812cd54 100644 --- a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsApi.java +++ b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsApi.java @@ -485,7 +485,20 @@ public class HdfsApi { * @throws IOException * @throws InterruptedException */ - public T execute(PrivilegedExceptionAction action) + public T execute(PrivilegedExceptionAction action) throws IOException, InterruptedException { + return this.execute(action, false); + } + + + /** + * Executes action on HDFS using doAs + * @param action strategy object + * @param result type + * @return result of operation + * @throws IOException + * @throws InterruptedException + */ + public T execute(PrivilegedExceptionAction action, boolean alwaysRetry) throws IOException, InterruptedException { T result = null; @@ -508,6 +521,7 @@ public class HdfsApi { } LOG.info("HDFS threw 'IOException: Cannot obtain block length' exception. " + "Retrying... Try #" + (tryNumber + 1)); + LOG.error("Retrying: " + ex.getMessage(),ex); Thread.sleep(1000); //retry after 1 second } } while (!succeeded); http://git-wip-us.apache.org/repos/asf/ambari/blob/8e36662a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsUtil.java ---------------------------------------------------------------------- diff --git a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsUtil.java b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsUtil.java index 0670f1a..810129b 100644 --- a/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsUtil.java +++ b/contrib/views/utils/src/main/java/org/apache/ambari/view/utils/hdfs/HdfsUtil.java @@ -27,6 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.IOException; +import java.security.PrivilegedExceptionAction; import java.util.Map; public class HdfsUtil { @@ -38,13 +39,19 @@ public class HdfsUtil { * @param filePath path to file * @param content new content of file */ - public static void putStringToFile(HdfsApi hdfs, String filePath, String content) throws HdfsApiException { - FSDataOutputStream stream; + public static void putStringToFile(final HdfsApi hdfs,final String filePath, final String content) throws HdfsApiException { + try { synchronized (hdfs) { - stream = hdfs.create(filePath, true); - stream.write(content.getBytes()); - stream.close(); + hdfs.execute(new PrivilegedExceptionAction() { + @Override + public Void run() throws Exception { + final FSDataOutputStream stream = hdfs.create(filePath, true); + stream.write(content.getBytes()); + stream.close(); + return null; + } + }, true); } } catch (IOException e) { throw new HdfsApiException("HDFS020 Could not write file " + filePath, e);