diff --git metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 920e762..0da0841 100644 --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -1576,26 +1576,20 @@ private void checkTrashPurgeCombination(Path pathToData, String objectName, bool return; } - boolean trashEnabled = false; try { - trashEnabled = 0 < hiveConf.getFloat("fs.trash.interval", -1); - } catch(NumberFormatException ex) { - // nothing to do - } - - if (trashEnabled) { - try { - HadoopShims.HdfsEncryptionShim shim = - ShimLoader.getHadoopShims().createHdfsEncryptionShim(FileSystem.get(hiveConf), hiveConf); + HadoopShims hs = ShimLoader.getHadoopShims(); + FileSystem fs = pathToData.getFileSystem(hiveConf); + if(hs.isTrashEnabled(fs, pathToData, hiveConf)) { + HadoopShims.HdfsEncryptionShim shim = hs.createHdfsEncryptionShim(fs, hiveConf); if (shim.isPathEncrypted(pathToData)) { throw new MetaException("Unable to drop " + objectName + " because it is in an encryption zone" + " and trash is enabled. Use PURGE option to skip trash."); } - } catch (IOException ex) { - MetaException e = new MetaException(ex.getMessage()); - e.initCause(ex); - throw e; } + } catch (IOException ex) { + MetaException e = new MetaException(ex.getMessage()); + e.initCause(ex); + throw e; } } diff --git shims/0.20S/src/main/java/org/apache/hadoop/hive/shims/Hadoop20SShims.java shims/0.20S/src/main/java/org/apache/hadoop/hive/shims/Hadoop20SShims.java index ffffcb7..6d80baa 100644 --- shims/0.20S/src/main/java/org/apache/hadoop/hive/shims/Hadoop20SShims.java +++ shims/0.20S/src/main/java/org/apache/hadoop/hive/shims/Hadoop20SShims.java @@ -191,6 +191,10 @@ public boolean moveToAppropriateTrash(FileSystem fs, Path path, Configuration co return trash.moveToTrash(path); } @Override + public boolean isTrashEnabled(FileSystem fs, Path path, Configuration conf) throws IOException { + return conf.getFloat("fs.trash.interval", 0) > 0; + } + @Override public long getDefaultBlockSize(FileSystem fs, Path path) { return fs.getDefaultBlockSize(); } diff --git shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java index 9eae0ac..df24dfa 100644 --- shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java +++ shims/0.23/src/main/java/org/apache/hadoop/hive/shims/Hadoop23Shims.java @@ -258,6 +258,17 @@ public boolean moveToAppropriateTrash(FileSystem fs, Path path, Configuration co throws IOException { return Trash.moveToAppropriateTrash(fs, path, conf); } + @Override + public boolean isTrashEnabled(FileSystem fs, Path path, Configuration conf) + throws IOException { + //see Hadoop2 impl of Trash.moveToAppropriateTrash(FileSystem, Path, Configuration) + Path fullyResolvedPath = fs.resolvePath(path); + FileSystem fullyResolvedFs = + FileSystem.get(fullyResolvedPath.toUri(), conf); + // If the trash interval is configured server side then clobber this + // configuration so that we always respect the server configuration. + return fullyResolvedFs.getServerDefaults(fullyResolvedPath).getTrashInterval() > 0; + } @Override public void setTotalOrderPartitionFile(JobConf jobConf, Path partitionFile){ diff --git shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java index 74785e5..1a9d055 100644 --- shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java +++ shims/common/src/main/java/org/apache/hadoop/hive/shims/HadoopShims.java @@ -190,6 +190,12 @@ public boolean moveToAppropriateTrash(FileSystem fs, Path path, Configuration co throws IOException; /** + * This method implements the check in way consistent with how {@link #moveToAppropriateTrash(org.apache.hadoop.fs.FileSystem, org.apache.hadoop.fs.Path, org.apache.hadoop.conf.Configuration)} does. + * @throws IOException + */ + public boolean isTrashEnabled(FileSystem fs, Path path, Configuration conf) + throws IOException; + /** * Get the default block size for the path. FileSystem alone is not sufficient to * determine the same, as in case of CSMT the underlying file system determines that. * @param fs