HIVE-16839 : Unbalanced calls to openTransaction/commitTransaction when alter 
the same partition concurrently (Guang Yang, reviewed by Karthik Manamcheri and 
Vihang Karajgaonkar)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/9bfff301
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/9bfff301
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/9bfff301

Branch: refs/heads/master
Commit: 9bfff30128b3c1e7c14daca2f5e9b573cfede22f
Parents: fc18e4a
Author: Vihang Karajgaonkar <vihan...@apache.org>
Authored: Thu Nov 8 10:49:27 2018 -0800
Committer: Vihang Karajgaonkar <vihan...@apache.org>
Committed: Thu Nov 8 10:49:27 2018 -0800

----------------------------------------------------------------------
 .../hadoop/hive/metastore/ObjectStore.java      |    51 +-
 .../hadoop/hive/metastore/ObjectStore.java.orig | 12818 +++++++++++++++++
 .../hadoop/hive/metastore/TestObjectStore.java  |    67 +
 3 files changed, 12914 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/9bfff301/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
----------------------------------------------------------------------
diff --git 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
index ba3acf9..570281b 100644
--- 
a/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
+++ 
b/standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
@@ -2445,34 +2445,41 @@ public class ObjectStore implements RawStore, 
Configurable {
                                 List<String> part_vals,
                                 String validWriteIds)
       throws NoSuchObjectException, MetaException {
-    openTransaction();
-    MTable table = this.getMTable(catName, dbName, tableName);
-    MPartition mpart = getMPartition(catName, dbName, tableName, part_vals);
-    Partition part = convertToPart(mpart);
-    commitTransaction();
-    if(part == null) {
-      throw new NoSuchObjectException("partition values="
+    Partition part = null;
+    boolean committed = false;
+    try {
+      openTransaction();
+      MTable table = this.getMTable(catName, dbName, tableName);
+      MPartition mpart = getMPartition(catName, dbName, tableName, part_vals);
+      part = convertToPart(mpart);
+      committed = commitTransaction();
+      if (part == null) {
+        throw new NoSuchObjectException("partition values="
           + part_vals.toString());
-    }
-    part.setValues(part_vals);
-    // If transactional table partition, check whether the current version 
partition
-    // statistics in the metastore comply with the client query's snapshot 
isolation.
-    long statsWriteId = mpart.getWriteId();
-    if (TxnUtils.isTransactionalTable(table.getParameters())) {
-      if (!areTxnStatsSupported) {
-        // Do not make persistent the following state since it is query 
specific (not global).
-        StatsSetupConst.setBasicStatsState(part.getParameters(), 
StatsSetupConst.FALSE);
-        LOG.info("Removed COLUMN_STATS_ACCURATE from Partition object's 
parameters.");
-      } else if (validWriteIds != null) {
-        if (isCurrentStatsValidForTheQuery(part, statsWriteId, validWriteIds, 
false)) {
-          part.setIsStatsCompliant(true);
-        } else {
-          part.setIsStatsCompliant(false);
+      }
+
+      part.setValues(part_vals);
+      // If transactional table partition, check whether the current version 
partition
+      // statistics in the metastore comply with the client query's snapshot 
isolation.
+      long statsWriteId = mpart.getWriteId();
+      if (TxnUtils.isTransactionalTable(table.getParameters())) {
+        if (!areTxnStatsSupported) {
           // Do not make persistent the following state since it is query 
specific (not global).
           StatsSetupConst.setBasicStatsState(part.getParameters(), 
StatsSetupConst.FALSE);
           LOG.info("Removed COLUMN_STATS_ACCURATE from Partition object's 
parameters.");
+        } else if (validWriteIds != null) {
+          if (isCurrentStatsValidForTheQuery(part, statsWriteId, 
validWriteIds, false)) {
+            part.setIsStatsCompliant(true);
+          } else {
+            part.setIsStatsCompliant(false);
+            // Do not make persistent the following state since it is query 
specific (not global).
+            StatsSetupConst.setBasicStatsState(part.getParameters(), 
StatsSetupConst.FALSE);
+            LOG.info("Removed COLUMN_STATS_ACCURATE from Partition object's 
parameters.");
+          }
         }
       }
+    } finally {
+      rollbackAndCleanup(committed, (Query)null);
     }
     return part;
   }

Reply via email to