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 bd0915c8a1..5b74f428cb 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -115,6 +115,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.jdo.JDODataStoreException; import javax.jdo.JDOException; import java.io.IOException; @@ -2674,7 +2675,19 @@ private Partition add_partition_core(final RawStore ms, try { initializeAddedPartition(tbl, part, madeDir); success = ms.addPartition(part); - } finally { + }catch (JDODataStoreException e) { + // another user may have successfully added this partition since last check in startAddPartition, + // see HIVE-20725 + boolean doesExist = ms.doesPartitionExist( + part.getDbName(), part.getTableName(), part.getValues()); + if(doesExist) { + madeDir = false; + throw new AlreadyExistsException("Partition already exists: " + part); + } else { + throw e; + } + } + finally { if (!success && madeDir) { wh.deleteDir(new Path(part.getSd().getLocation()), true); }