diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 60e462f..b62da90 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -125,6 +125,7 @@ import java.net.InetSocketAddress; import java.net.UnknownHostException; import java.nio.ByteBuffer; +import java.security.PrivilegedExceptionAction; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.AbstractMap; @@ -2315,21 +2316,32 @@ public boolean equals(Object obj) { continue; } - - partFutures.add(threadPool.submit(new Callable() { - @Override - public Partition call() throws Exception { - boolean madeDir = createLocationForAddedPartition(table, part); - if (addedPartitions.put(new PartValEqWrapper(part), madeDir) != null) { - // Technically, for ifNotExists case, we could insert one and discard the other - // because the first one now "exists", but it seems better to report the problem - // upstream as such a command doesn't make sense. - throw new MetaException("Duplicate partitions in the list: " + part); + try { + final String userName = UserGroupInformation.getCurrentUser().getShortUserName(); + partFutures.add(threadPool.submit(new Callable() { + @Override + public Partition call() throws Exception { + UserGroupInformation ugi = UserGroupInformation.createRemoteUser(userName); + ugi.doAs(new PrivilegedExceptionAction() { + @Override + public Object run() throws Exception { + boolean madeDir = createLocationForAddedPartition(table, part); + if (addedPartitions.put(new PartValEqWrapper(part), madeDir) != null) { + // Technically, for ifNotExists case, we could insert one and discard the other + // because the first one now "exists", but it seems better to report the problem + // upstream as such a command doesn't make sense. + throw new MetaException("Duplicate partitions in the list: " + part); + } + initializeAddedPartition(table, part, madeDir); + return null; + } + }); + return part; } - initializeAddedPartition(table, part, madeDir); - return part; - } - })); + })); + } catch (IOException e) { + throw new RuntimeException(e); + } } try { for (Future partFuture : partFutures) { @@ -2478,19 +2490,31 @@ private int add_partitions_pspec_core( LOG.info("Not adding partition " + part + " as it already exists"); continue; } - partFutures.add(threadPool.submit(new Callable() { - @Override public Object call() throws Exception { - boolean madeDir = createLocationForAddedPartition(table, part); - if (addedPartitions.put(new PartValEqWrapperLite(part), madeDir) != null) { - // Technically, for ifNotExists case, we could insert one and discard the other - // because the first one now "exists", but it seems better to report the problem - // upstream as such a command doesn't make sense. - throw new MetaException("Duplicate partitions in the list: " + part); + try { + final String userName = UserGroupInformation.getCurrentUser().getShortUserName(); + partFutures.add(threadPool.submit(new Callable() { + @Override public Object call() throws Exception { + UserGroupInformation ugi = UserGroupInformation.createRemoteUser(userName); + ugi.doAs(new PrivilegedExceptionAction() { + @Override + public Object run() throws Exception { + boolean madeDir = createLocationForAddedPartition(table, part); + if (addedPartitions.put(new PartValEqWrapperLite(part), madeDir) != null) { + // Technically, for ifNotExists case, we could insert one and discard the other + // because the first one now "exists", but it seems better to report the problem + // upstream as such a command doesn't make sense. + throw new MetaException("Duplicate partitions in the list: " + part); + } + initializeAddedPartition(table, part, madeDir); + return null; + } + }); + return part; } - initializeAddedPartition(table, part, madeDir); - return part; - } - })); + })); + } catch (IOException e) { + throw new RuntimeException(e); + } partitionIterator.next(); }