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 288E4200BD3 for ; Tue, 6 Dec 2016 21:58:25 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 25984160B1B; Tue, 6 Dec 2016 20:58:25 +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 47705160B17 for ; Tue, 6 Dec 2016 21:58:24 +0100 (CET) Received: (qmail 94799 invoked by uid 500); 6 Dec 2016 20:58:23 -0000 Mailing-List: contact commits-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: hive-dev@hive.apache.org Delivered-To: mailing list commits@hive.apache.org Received: (qmail 94788 invoked by uid 99); 6 Dec 2016 20:58:23 -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; Tue, 06 Dec 2016 20:58:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5521EDFFAB; Tue, 6 Dec 2016 20:58:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: spena@apache.org To: commits@hive.apache.org Message-Id: <9599fae2ad284fc2bd6d5d16cc60e4a1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hive git commit: HIVE-15355: Concurrency issues during parallel moveFile due to HDFSUtils.setFullFileStatus (Vihang Karajgaonkar, reviewed by Sergio Pena and Sahil Takiar) Date: Tue, 6 Dec 2016 20:58:23 +0000 (UTC) archived-at: Tue, 06 Dec 2016 20:58:25 -0000 Repository: hive Updated Branches: refs/heads/master fa995bae4 -> 2f1015365 HIVE-15355: Concurrency issues during parallel moveFile due to HDFSUtils.setFullFileStatus (Vihang Karajgaonkar, reviewed by Sergio Pena and Sahil Takiar) Project: http://git-wip-us.apache.org/repos/asf/hive/repo Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/2f101536 Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/2f101536 Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/2f101536 Branch: refs/heads/master Commit: 2f1015365b3015e6fd17ce894140f61427b94ffb Parents: fa995ba Author: Vihang Karajgaonkar Authored: Tue Dec 6 14:57:51 2016 -0600 Committer: Sergio Pena Committed: Tue Dec 6 14:57:51 2016 -0600 ---------------------------------------------------------------------- .../hadoop/hive/io/TestHadoopFileStatus.java | 92 ++++++++++++++++++++ .../org/apache/hadoop/hive/io/HdfsUtils.java | 15 ++-- 2 files changed, 100 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hive/blob/2f101536/itests/hive-unit/src/test/java/org/apache/hadoop/hive/io/TestHadoopFileStatus.java ---------------------------------------------------------------------- diff --git a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/io/TestHadoopFileStatus.java b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/io/TestHadoopFileStatus.java new file mode 100644 index 0000000..b9fc09b --- /dev/null +++ b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/io/TestHadoopFileStatus.java @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hive.io; + +import java.io.IOException; +import java.util.List; + +import org.apache.hadoop.fs.FileStatus; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.permission.AclEntry; +import org.apache.hadoop.fs.permission.AclEntryScope; +import org.apache.hadoop.fs.permission.AclEntryType; +import org.apache.hadoop.fs.permission.AclStatus; +import org.apache.hadoop.fs.permission.FsAction; +import org.apache.hadoop.hdfs.DistributedFileSystem; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.io.HdfsUtils.HadoopFileStatus; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + +public class TestHadoopFileStatus { + private static HiveConf hiveConf; + private static HadoopFileStatus sourceStatus; + + @BeforeClass + public static void setUp() throws IOException { + hiveConf = new HiveConf(TestHadoopFileStatus.class); + hiveConf.set("dfs.namenode.acls.enabled", "true"); + } + + private static AclEntry newAclEntry(AclEntryScope scope, AclEntryType type, FsAction permission) { + return new AclEntry.Builder().setScope(scope).setType(type).setPermission(permission).build(); + } + + /* + * HdfsUtils.setFullFileStatus(..) is called from multiple parallel threads. If AclEntries + * is modifiable the method will not be thread safe and could cause random concurrency issues + * This test case checks if the aclEntries returned from HadoopFileStatus is thread-safe or not + */ + @Test(expected = UnsupportedOperationException.class) + public void testHadoopFileStatusAclEntries() throws IOException { + FileSystem mockDfs = Mockito.mock(DistributedFileSystem.class); + Path mockPath = Mockito.mock(Path.class); + + List aclEntries = Lists.newArrayList(); + aclEntries.add(newAclEntry(AclEntryScope.ACCESS, AclEntryType.USER, FsAction.ALL)); + aclEntries.add(newAclEntry(AclEntryScope.ACCESS, AclEntryType.GROUP, FsAction.READ_EXECUTE)); + aclEntries.add(newAclEntry(AclEntryScope.ACCESS, AclEntryType.OTHER, FsAction.NONE)); + AclStatus aclStatus = new AclStatus.Builder().owner("dummyOwner").group("dummyGroup") + .stickyBit(true).addEntries(aclEntries).build(); + + FileStatus mockFileStatus = Mockito.mock(FileStatus.class); + Mockito.when(mockDfs.getAclStatus(mockPath)).thenReturn(aclStatus); + Mockito.when(mockDfs.getFileStatus(mockPath)).thenReturn(mockFileStatus); + sourceStatus = new HadoopFileStatus(hiveConf, mockDfs, mockPath); + Assert.assertNotNull(sourceStatus.getAclEntries()); + Assert.assertTrue(sourceStatus.getAclEntries().size() == 3); + Iterables.removeIf(sourceStatus.getAclEntries(), new Predicate() { + @Override + public boolean apply(AclEntry input) { + if (input.getName() == null) { + return true; + } + return false; + } + }); + } + +} http://git-wip-us.apache.org/repos/asf/hive/blob/2f101536/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java ---------------------------------------------------------------------- diff --git a/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java b/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java index 70a6857..7b6a9bd 100644 --- a/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java +++ b/shims/common/src/main/java/org/apache/hadoop/hive/io/HdfsUtils.java @@ -19,6 +19,8 @@ package org.apache.hadoop.hive.io; import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.apache.commons.lang.ArrayUtils; @@ -68,12 +70,10 @@ public class HdfsUtils { boolean aclEnabled = Objects.equal(conf.get("dfs.namenode.acls.enabled"), "true"); FsPermission sourcePerm = fStatus.getPermission(); List aclEntries = null; - AclStatus aclStatus; if (aclEnabled) { - aclStatus = sourceStatus.getAclStatus(); - if (aclStatus != null) { - LOG.trace(aclStatus.toString()); - aclEntries = aclStatus.getEntries(); + if (sourceStatus.getAclEntries() != null) { + LOG.trace(sourceStatus.aclStatus.toString()); + aclEntries = new ArrayList<>(sourceStatus.getAclEntries()); removeBaseAclEntries(aclEntries); //the ACL api's also expect the tradition user/group/other permission in the form of ACL @@ -193,8 +193,9 @@ public static class HadoopFileStatus { public FileStatus getFileStatus() { return fileStatus; } - public AclStatus getAclStatus() { - return aclStatus; + + public List getAclEntries() { + return aclStatus == null ? null : Collections.unmodifiableList(aclStatus.getEntries()); } } }