You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by da...@apache.org on 2018/01/14 05:08:46 UTC

hive git commit: HIVE-18299: DbNotificationListener fail on mysql with "select for update" (Daniel Dai, reviewed by Anishek Agarwal)

Repository: hive
Updated Branches:
  refs/heads/master c0734ac91 -> 970d8c968


HIVE-18299: DbNotificationListener fail on mysql with "select for update" (Daniel Dai, reviewed by Anishek Agarwal)


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

Branch: refs/heads/master
Commit: 970d8c9680d89708c4007de214fdc72b77deb7da
Parents: c0734ac
Author: Daniel Dai <da...@hortonworks.com>
Authored: Sat Jan 13 21:08:20 2018 -0800
Committer: Daniel Dai <da...@hortonworks.com>
Committed: Sat Jan 13 21:08:20 2018 -0800

----------------------------------------------------------------------
 .../hadoop/hive/metastore/ObjectStore.java      | 21 +++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/970d8c96/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
----------------------------------------------------------------------
diff --git a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
index 5438b22..3a1bc13 100644
--- a/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
+++ b/standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/ObjectStore.java
@@ -29,6 +29,7 @@ import java.nio.ByteBuffer;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.SQLIntegrityConstraintViolationException;
+import java.sql.Statement;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
@@ -8866,10 +8867,28 @@ public class ObjectStore implements RawStore, Configurable {
     }
   }
 
+  private void prepareQuotes() throws SQLException {
+    if (dbType == DatabaseProduct.MYSQL) {
+      assert pm.currentTransaction().isActive();
+      JDOConnection jdoConn = pm.getDataStoreConnection();
+      Statement statement = null;
+      try {
+        statement = ((Connection)jdoConn.getNativeConnection()).createStatement();
+        statement.execute("SET @@session.sql_mode=ANSI_QUOTES");
+      } finally {
+        if(statement != null){
+          statement.close();
+        }
+        jdoConn.close();
+      }
+    }
+  }
+
   private void lockForUpdate() throws MetaException {
-    String selectQuery = "select \"NEXT_EVENT_ID\" from NOTIFICATION_SEQUENCE";
+    String selectQuery = "select \"NEXT_EVENT_ID\" from \"NOTIFICATION_SEQUENCE\"";
     String selectForUpdateQuery = sqlGenerator.addForUpdateClause(selectQuery);
     new RetryingExecutor(conf, () -> {
+      prepareQuotes();
       Query query = pm.newQuery("javax.jdo.query.SQL", selectForUpdateQuery);
       query.setUnique(true);
       // only need to execute it to get db Lock