FAQ
Author: xuefu
Date: Fri Jun 6 18:02:29 2014
New Revision: 1600973

URL: http://svn.apache.org/r1600973
Log:
HIVE-7117: Partitions not inheriting table permissions after alter rename partition (Ashish via Xuefu)

Modified:
     hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java
     hive/trunk/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java
     hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
     hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java?rev=1600973&r1=1600972&r2=1600973&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/common/FileUtils.java Fri Jun 6 18:02:29 2014
@@ -576,4 +576,29 @@ public final class FileUtils {
      }
      return result;
    }
+
+ public static boolean renameWithPerms(FileSystem fs, Path sourcePath,
+ Path destPath, boolean inheritPerms,
+ Configuration conf) throws IOException {
+ LOG.info("Renaming " + sourcePath + " to " + destPath);
+ if (!inheritPerms) {
+ //just rename the directory
+ return fs.rename(sourcePath, destPath);
+ } else {
+ //rename the directory
+ if (fs.rename(sourcePath, destPath)) {
+ HadoopShims shims = ShimLoader.getHadoopShims();
+ HdfsFileStatus fullFileStatus = shims.getFullFileStatus(conf, fs, destPath.getParent());
+ try {
+ shims.setFullFileStatus(conf, fullFileStatus, fs, destPath);
+ } catch (Exception e) {
+ LOG.warn("Error setting permissions or group of " + destPath, e);
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+ }
  }

Modified: hive/trunk/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java
URL: http://svn.apache.org/viewvc/hive/trunk/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java?rev=1600973&r1=1600972&r2=1600973&view=diff
==============================================================================
--- hive/trunk/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java (original)
+++ hive/trunk/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/security/FolderPermissionBase.java Fri Jun 6 18:02:29 2014
@@ -185,17 +185,20 @@ public abstract class FolderPermissionBa
      ret = driver.run("insert into table " + tableName + " partition(part1='1',part2='1',part3='1') select key,value from mysrc");
      Assert.assertEquals(0,ret.getResponseCode());

+ assertExistence(warehouseDir + "/" + tableName);
+ setPermission(warehouseDir + "/" + tableName, 1);
+
      //alter partition
      ret = driver.run("alter table " + tableName + " partition (part1='1',part2='1',part3='1') rename to partition (part1='2',part2='2',part3='2')");
      Assert.assertEquals(0,ret.getResponseCode());

- verifyPermission(warehouseDir + "/" + tableName + "/part1=2");
- verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2");
- verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2");
+ verifyPermission(warehouseDir + "/" + tableName + "/part1=2", 1);
+ verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2", 1);
+ verifyPermission(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2", 1);

      Assert.assertTrue(listStatus(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2").size() > 0);
      for (String child : listStatus(warehouseDir + "/" + tableName + "/part1=2/part2=2/part3=2")) {
- verifyPermission(child);
+ verifyPermission(child, 1);
      }
    }


Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java?rev=1600973&r1=1600972&r2=1600973&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java Fri Jun 6 18:02:29 2014
@@ -398,7 +398,7 @@ public class HiveAlterHandler implements
              if (!wh.mkdirs(destParentPath, true)) {
                  throw new IOException("Unable to create path " + destParentPath);
              }
- srcFs.rename(srcPath, destPath);
+ wh.renameDir(srcPath, destPath, true);
              LOG.info("rename done!");
            }
          } catch (IOException e) {

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java?rev=1600973&r1=1600972&r2=1600973&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java Fri Jun 6 18:02:29 2014
@@ -44,7 +44,6 @@ import org.apache.hadoop.fs.FileStatus;
  import org.apache.hadoop.fs.FileSystem;
  import org.apache.hadoop.fs.Path;
  import org.apache.hadoop.fs.permission.FsAction;
-import org.apache.hadoop.fs.permission.FsPermission;
  import org.apache.hadoop.hive.common.FileUtils;
  import org.apache.hadoop.hive.common.HiveStatsUtils;
  import org.apache.hadoop.hive.common.JavaUtils;
@@ -52,8 +51,6 @@ import org.apache.hadoop.hive.conf.HiveC
  import org.apache.hadoop.hive.metastore.api.Database;
  import org.apache.hadoop.hive.metastore.api.FieldSchema;
  import org.apache.hadoop.hive.metastore.api.MetaException;
-import org.apache.hadoop.hive.metastore.api.Partition;
-import org.apache.hadoop.hive.metastore.api.SkewedInfo;
  import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
  import org.apache.hadoop.hive.metastore.api.Table;
  import org.apache.hadoop.hive.shims.ShimLoader;
@@ -198,11 +195,13 @@ public class Warehouse {
    }

    public boolean renameDir(Path sourcePath, Path destPath) throws MetaException {
- FileSystem fs = null;
+ return renameDir(sourcePath, destPath, false);
+ }
+
+ public boolean renameDir(Path sourcePath, Path destPath, boolean inheritPerms) throws MetaException {
      try {
- fs = getFs(sourcePath);
- fs.rename(sourcePath, destPath);
- return true;
+ FileSystem fs = getFs(sourcePath);
+ return FileUtils.renameWithPerms(fs, sourcePath, destPath, inheritPerms, conf);
      } catch (Exception ex) {
        MetaStoreUtils.logAndThrowMetaException(ex);
      }

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categorieshive, hadoop
postedJun 6, '14 at 6:02p
activeJun 6, '14 at 6:02p
posts1
users1
websitehive.apache.org

1 user in discussion

Xuefu: 1 post

People

Translate

site design / logo © 2021 Grokbase