You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ha...@apache.org on 2013/09/12 14:11:14 UTC

svn commit: r1522542 - /hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java

Author: hashutosh
Date: Thu Sep 12 12:11:14 2013
New Revision: 1522542

URL: http://svn.apache.org/r1522542
Log:
HIVE-5265 : Direct SQL fallback broken on Postgres (Sergey Shelukhin via Ashutosh Chauhan)

Modified:
    hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java

Modified: hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java
URL: http://svn.apache.org/viewvc/hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java?rev=1522542&r1=1522541&r2=1522542&view=diff
==============================================================================
--- hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java (original)
+++ hive/trunk/metastore/src/java/org/apache/hadoop/hive/metastore/ObjectStore.java Thu Sep 12 12:11:14 2013
@@ -1389,11 +1389,10 @@ public class ObjectStore implements RawS
       int maxParts, boolean allowSql, boolean allowJdo) throws MetaException {
     assert allowSql || allowJdo;
     boolean doTrace = LOG.isDebugEnabled();
-    List<Partition> parts = null;
-    boolean doUseDirectSql = allowSql
-        && HiveConf.getBoolVar(getConf(), ConfVars.METASTORE_TRY_DIRECT_SQL);
+    boolean doUseDirectSql = canUseDirectSql(allowSql);
 
     boolean success = false;
+    List<Partition> parts = null;
     try {
       long start = doTrace ? System.nanoTime() : 0;
       openTransaction();
@@ -1703,11 +1702,10 @@ public class ObjectStore implements RawS
           throws MetaException, NoSuchObjectException {
     assert allowSql || allowJdo;
     boolean doTrace = LOG.isDebugEnabled();
-    List<Partition> results = null;
-    boolean doUseDirectSql = allowSql
-        && HiveConf.getBoolVar(getConf(), ConfVars.METASTORE_TRY_DIRECT_SQL);
+    boolean doUseDirectSql = canUseDirectSql(allowSql);
 
     boolean success = false;
+    List<Partition> results = null;
     try {
       long start = doTrace ? System.nanoTime() : 0;
       openTransaction();
@@ -1745,6 +1743,8 @@ public class ObjectStore implements RawS
       }
       throw new MetaException(ex.getMessage());
     }
+    rollbackTransaction();
+    openTransaction();
   }
 
   private List<Partition> getPartitionsViaOrm(
@@ -1794,9 +1794,7 @@ public class ObjectStore implements RawS
       throws MetaException, NoSuchObjectException {
     assert allowSql || allowJdo;
     boolean doTrace = LOG.isDebugEnabled();
-    // There's no portable SQL limit. It doesn't make a lot of sense w/o offset anyway.
-    boolean doUseDirectSql = allowSql
-      && HiveConf.getBoolVar(getConf(), ConfVars.METASTORE_TRY_DIRECT_SQL);
+    boolean doUseDirectSql = canUseDirectSql(allowSql);
     dbName = dbName.toLowerCase();
     tblName = tblName.toLowerCase();
     List<Partition> results = null;
@@ -1820,6 +1818,7 @@ public class ObjectStore implements RawS
           handleDirectSqlError(allowJdo, ex);
           doUseDirectSql = false;
           start = doTrace ? System.nanoTime() : 0;
+          mtable = ensureGetMTable(dbName, tblName); // detached on rollback, get again
         }
       }
       if (!doUseDirectSql) {
@@ -1837,6 +1836,16 @@ public class ObjectStore implements RawS
     }
   }
 
+  private boolean canUseDirectSql(boolean allowSql) {
+    // We don't allow direct SQL usage if we are inside a larger transaction (e.g. droptable).
+    // That is because some databases (e.g. Postgres) abort the entire transaction when
+    // any query fails, so the fallback from failed SQL to JDO is not possible.
+    // TODO: Drop table can be very slow on large tables, we might want to address this.
+    return allowSql
+      && HiveConf.getBoolVar(getConf(), ConfVars.METASTORE_TRY_DIRECT_SQL)
+      && !isActiveTransaction();
+  }
+
   private MTable ensureGetMTable(String dbName, String tblName) throws NoSuchObjectException {
     MTable mtable = getMTable(dbName, tblName);
     if (mtable == null) {