Index: shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java =================================================================== --- shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java (revision 1374691) +++ shims/src/common/java/org/apache/hadoop/hive/shims/HadoopShims.java (working copy) @@ -183,6 +183,9 @@ * In secure versions of Hadoop, this simply returns the current * access control context's user, ignoring the configuration. */ + + public void closeAllForUGI(UserGroupInformation ugi); + public UserGroupInformation getUGIForConf(Configuration conf) throws LoginException, IOException; /** Index: shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java =================================================================== --- shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java (revision 1374691) +++ shims/src/common-secure/java/org/apache/hadoop/hive/shims/HadoopShimsSecure.java (working copy) @@ -25,6 +25,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileStatus; import org.apache.hadoop.fs.FileSystem; @@ -64,6 +66,9 @@ * Base implemention for shims against secure Hadoop 0.20.3/0.23. */ public abstract class HadoopShimsSecure implements HadoopShims { + + static final Log LOG = LogFactory.getLog(HadoopShimsSecure.class); + public boolean usesJobShell() { return false; } @@ -526,6 +531,15 @@ } @Override + public void closeAllForUGI(UserGroupInformation ugi) { + try { + FileSystem.closeAllForUGI(ugi); + } catch (IOException e) { + LOG.error("Could not clean up file-system handles for UGI: " + ugi, e); + } + } + + @Override abstract public JobTrackerState getJobTrackerState(ClusterStatus clusterStatus) throws Exception; @Override Index: shims/src/common-secure/java/org/apache/hadoop/hive/thrift/HadoopThriftAuthBridge20S.java =================================================================== --- shims/src/common-secure/java/org/apache/hadoop/hive/thrift/HadoopThriftAuthBridge20S.java (revision 1374691) +++ shims/src/common-secure/java/org/apache/hadoop/hive/thrift/HadoopThriftAuthBridge20S.java (working copy) @@ -39,6 +39,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.hive.thrift.client.TUGIAssumingTransport; import org.apache.hadoop.security.SaslRpcServer; import org.apache.hadoop.security.SaslRpcServer.AuthMethod; @@ -510,8 +511,9 @@ } Socket socket = ((TSocket)(saslTrans.getUnderlyingTransport())).getSocket(); remoteAddress.set(socket.getInetAddress()); + UserGroupInformation clientUgi = null; try { - UserGroupInformation clientUgi = UserGroupInformation.createProxyUser( + clientUgi = UserGroupInformation.createProxyUser( endUser, UserGroupInformation.getLoginUser()); return clientUgi.doAs(new PrivilegedExceptionAction() { public Boolean run() { @@ -532,6 +534,14 @@ } catch (IOException ioe) { throw new RuntimeException(ioe); // unexpected! } + finally { + if (clientUgi != null) { + try { FileSystem.closeAllForUGI(clientUgi); } + catch(IOException exception) { + LOG.error("Could not clean up file-system handles for UGI: " + clientUgi, exception); + } + } + } } } Index: shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java =================================================================== --- shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java (revision 1374691) +++ shims/src/0.20/java/org/apache/hadoop/hive/shims/Hadoop20Shims.java (working copy) @@ -578,4 +578,10 @@ public org.apache.hadoop.mapreduce.JobContext newJobContext(Job job) { return new org.apache.hadoop.mapreduce.JobContext(job.getConfiguration(), job.getJobID()); } + + @Override + public void closeAllForUGI(UserGroupInformation ugi) { + // No such functionality in ancient hadoop + return; + } } Index: metastore/src/java/org/apache/hadoop/hive/metastore/TUGIBasedProcessor.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/TUGIBasedProcessor.java (revision 1374691) +++ metastore/src/java/org/apache/hadoop/hive/metastore/TUGIBasedProcessor.java (working copy) @@ -131,6 +131,8 @@ throw new RuntimeException(ie); // unexpected! } catch (IOException ioe) { throw new RuntimeException(ioe); // unexpected! + } finally { + shim.closeAllForUGI(clientUgi); } } }