Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java (revision 6306) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveAlterHandler.java (working copy) @@ -143,6 +143,8 @@ + " already exists : " + destPath); } } catch (IOException e) { + Warehouse.closeFs(srcFs); + Warehouse.closeFs(destFs); throw new InvalidOperationException("Unable to access new location " + destPath + " for table " + newt.getDbName() + "." + newt.getTableName()); Index: metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (revision 6306) +++ metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (working copy) @@ -61,7 +61,7 @@ } /** - * Helper function to convert IOException to MetaException + * Helper functions to convert IOException to MetaException */ public FileSystem getFs(Path f) throws MetaException { try { @@ -72,6 +72,17 @@ return null; } + public static void closeFs(FileSystem fs) throws MetaException { + try { + if (fs != null) { + fs.close(); + } + } catch (IOException e) { + MetaStoreUtils.logAndThrowMetaException(e); + } + } + + /** * Hadoop File System reverse lookups paths with raw ip addresses The File * System URI always contains the canonical DNS name of the Namenode. @@ -118,11 +129,13 @@ } public boolean mkdirs(Path f) throws MetaException { + FileSystem fs = null; try { - FileSystem fs = getFs(f); + fs = getFs(f); LOG.debug("Creating directory if it doesn't exist: " + f); return (fs.mkdirs(f) || fs.getFileStatus(f).isDir()); } catch (IOException e) { + closeFs(fs); MetaStoreUtils.logAndThrowMetaException(e); } return false; @@ -130,8 +143,9 @@ public boolean deleteDir(Path f, boolean recursive) throws MetaException { LOG.info("deleting " + f); + FileSystem fs = null; try { - FileSystem fs = getFs(f); + fs = getFs(f); if (!fs.exists(f)) { return false; } @@ -157,6 +171,7 @@ } catch (FileNotFoundException e) { return true; // ok even if there is not data } catch (IOException e) { + closeFs(fs); MetaStoreUtils.logAndThrowMetaException(e); } return false; @@ -286,8 +301,9 @@ } public boolean isDir(Path f) throws MetaException { + FileSystem fs = null; try { - FileSystem fs = getFs(f); + fs = getFs(f); FileStatus fstatus = fs.getFileStatus(f); if (!fstatus.isDir()) { return false; @@ -295,6 +311,7 @@ } catch (FileNotFoundException e) { return false; } catch (IOException e) { + closeFs(fs); MetaStoreUtils.logAndThrowMetaException(e); } return true;