Index: metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (revision 1001302) +++ metastore/src/java/org/apache/hadoop/hive/metastore/Warehouse.java (working copy) @@ -30,6 +30,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.security.auth.login.LoginException; + import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -42,6 +44,7 @@ import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.api.FieldSchema; import org.apache.hadoop.hive.metastore.api.MetaException; +import org.apache.hadoop.security.UserGroupInformation; /** * This class represents a warehouse where data of Hive tables is stored @@ -137,7 +140,18 @@ try { fs = getFs(f); LOG.debug("Creating directory if it doesn't exist: " + f); - return (fs.mkdirs(f) || fs.getFileStatus(f).isDir()); + boolean status = (fs.mkdirs(f) || fs.getFileStatus(f).isDir()); + UserGroupInformation ugi = getUGI(); + // 1. ugi contains an array of group-names. Shall we assume first of those + // is primary group name? + + // 2. FileSystem api as of 0.20 doesnt have an api which accepts UGI at the time of calling + // mkdirs() so we are forced to do it as two step process. First, do mkdirs() + // and then set that Info. Obviously things can go wrong in between these two + // calls and whole rollback semantics comes into the picture. + + fs.setOwner(f, ugi.getUserName(), ugi.getGroupNames()[0]); + return status; } catch (IOException e) { closeFs(fs); MetaStoreUtils.logAndThrowMetaException(e); @@ -145,6 +159,20 @@ return false; } + // 3. There are better ways to get UGI and also places where to put this code then doing this way and + // putting it here. Probably, HiveConf. Or through method introduced in Todd's patch of Hive-1264. + private UserGroupInformation getUGI() throws IOException{ + try { + UserGroupInformation ugi = UserGroupInformation.readFrom(conf); + if (ugi == null) { + ugi = UserGroupInformation.login(conf); + } + return ugi; + } catch (LoginException e) { + throw (IOException) new IOException().initCause(e); + } + } + public boolean deleteDir(Path f, boolean recursive) throws MetaException { LOG.info("deleting " + f); FileSystem fs = null;