diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java index bb29410e7d..f9e28b9bad 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnDbUtil.java @@ -51,7 +51,7 @@ */ public final class TxnDbUtil { - private static final Logger LOG = LoggerFactory.getLogger(TxnDbUtil.class.getName()); + private static final Logger LOG = LoggerFactory.getLogger(TxnDbUtil.class.getName()); private static final String TXN_MANAGER = "org.apache.hadoop.hive.ql.lockmgr.DbTxnManager"; private static final EnumMap DB_EPOCH_FN = @@ -621,6 +621,7 @@ static void closeResources(Connection conn, Statement stmt, ResultSet rs) { /** * Get database specific function which returns the milliseconds value after the epoch. + * @param dbProduct The type of the db which is used * @throws MetaException For unknown database type. */ static String getEpochFn(DatabaseProduct dbProduct) throws MetaException { @@ -634,6 +635,44 @@ static String getEpochFn(DatabaseProduct dbProduct) throws MetaException { } } + /** + * Calls queries in batch, but did not return affected row numbers. Same as executeQueriesInBatch, + * with the only difference when the db is Oracle. In this case it is called as an anonymous stored + * procedure instead of batching, since batching is not optimized. See: + * https://docs.oracle.com/cd/E11882_01/java.112/e16548/oraperf.htm#JJDBC28752 + * @param dbProduct The type of the db which is used + * @param stmt Statement which will be used for batching and execution. + * @param queries List of sql queries to execute in a Statement batch. + * @param batchSize maximum number of queries in a single batch + * @throws SQLException Thrown if an execution error occurs. + */ + static void executeQueriesInBatchNoCount(DatabaseProduct dbProduct, Statement stmt, List queries, int batchSize) throws SQLException { + if (dbProduct == ORACLE) { + int queryCounter = 0; + StringBuilder sb = new StringBuilder(); + sb.append("begin "); + for (String query : queries) { + LOG.debug("Adding query to batch: <" + query + ">"); + queryCounter++; + sb.append(query).append(";"); + if (queryCounter % batchSize == 0) { + sb.append("end;"); + String batch = sb.toString(); + LOG.debug("Going to execute queries in oracle anonymous statement. " + batch); + stmt.execute(batch); + } + } + if (queryCounter % batchSize != 0) { + sb.append("end;"); + String batch = sb.toString(); + LOG.debug("Going to execute queries in oracle anonymous statement. " + batch); + stmt.execute(batch); + } + } else { + executeQueriesInBatch(stmt, queries, batchSize); + } + } + /** * @param stmt Statement which will be used for batching and execution. * @param queries List of sql queries to execute in a Statement batch. diff --git standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java index d080df417b..96c8bebb8a 100644 --- standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java +++ standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnHandler.java @@ -94,6 +94,7 @@ import static org.apache.hadoop.hive.metastore.DatabaseProduct.MYSQL; import static org.apache.hadoop.hive.metastore.txn.TxnDbUtil.executeQueriesInBatch; +import static org.apache.hadoop.hive.metastore.txn.TxnDbUtil.executeQueriesInBatchNoCount; import static org.apache.hadoop.hive.metastore.utils.MetaStoreUtils.getDefaultCatalog; import static org.apache.hadoop.hive.metastore.utils.StringUtils.normalizeIdentifier; @@ -1345,7 +1346,7 @@ private void updateCommitIdAndCleanUpMetadata(Statement stmt, long txnid, TxnTyp queryBatch.add("DELETE FROM \"MATERIALIZATION_REBUILD_LOCKS\" WHERE \"MRL_TXN_ID\" = " + txnid); // execute all in one batch - executeQueriesInBatch(stmt, queryBatch, maxBatchSize); + executeQueriesInBatchNoCount(dbProduct, stmt, queryBatch, maxBatchSize); } private void updateKeyValueAssociatedWithTxn(CommitTxnRequest rqst, Statement stmt) throws SQLException {