diff --git ql/src/java/org/apache/hadoop/hive/ql/Driver.java ql/src/java/org/apache/hadoop/hive/ql/Driver.java index ff5086ac3b..57f71a824c 100644 --- ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -543,7 +543,8 @@ void compile(String command, boolean resetTaskIds, boolean deferClose) throws Co LockedDriverState.setLockedDriverState(lDrvState); - String queryId = queryState.getQueryId(); + final String queryId = Strings.isNullOrEmpty(queryState.getQueryId()) ? + QueryPlan.makeQueryId() : queryState.getQueryId(); SparkSession ss = SessionState.get().getSparkSession(); if (ss != null) { @@ -1484,7 +1485,7 @@ private ValidTxnWriteIdList recordValidWriteIds(HiveTxnManager txnMgr) throws Lo throw new LockException("Unexpected tables in compaction: " + txnTables); } String fullTableName = txnTables.get(0); - txnWriteIds = new ValidTxnWriteIdList(0L); // No transaction for the compaction for now. + txnWriteIds = new ValidTxnWriteIdList(0L); // No transaction for the compaction for now. todo: Since MM compaction is a query, a txn has been opened at this point txnWriteIds.addTableValidWriteIdList(compactionWriteIds); } else { txnWriteIds = txnMgr.getValidWriteIds(txnTables, txnString); @@ -1672,8 +1673,10 @@ private void acquireLocks() throws CommandProcessorResponse { queryTxnMgr.acquireLocks(plan, ctx, userFromUGI, lDrvState); // This check is for controlling the correctness of the current state if (queryTxnMgr.recordSnapshot(plan) && !validTxnListsGenerated) { - throw new IllegalStateException("calling recordValidTxn() more than once in the same " + - JavaUtils.txnIdToString(queryTxnMgr.getCurrentTxnId())); + throw new IllegalStateException( + "Need to record valid WriteID list but there is no valid TxnID list (" + + JavaUtils.txnIdToString(queryTxnMgr.getCurrentTxnId()) + + ", queryId:" + plan.getQueryId() + ")"); } if (plan.hasAcidResourcesInQuery() || hasAcidDdl) { @@ -2230,7 +2233,7 @@ private void execute() throws CommandProcessorResponse { } Metrics metrics = MetricsFactory.getInstance(); - String queryId = queryState.getQueryId(); + String queryId = plan.getQueryId(); // Get the query string from the conf file as the compileInternal() method might // hide sensitive information during query redaction. String queryStr = conf.getQueryString(); diff --git ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveTxnManager.java ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveTxnManager.java index ba1f1ffe88..12c10273a9 100644 --- ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveTxnManager.java +++ ql/src/java/org/apache/hadoop/hive/ql/lockmgr/HiveTxnManager.java @@ -262,7 +262,7 @@ void replTableWriteIdState(String validWriteIdList, String dbName, String tableN /** * For resources that support MVCC, the state of the DB must be recorded for the duration of the - * operation/transaction. Returns {@code true} if current statment needs to do this. + * operation/transaction. Returns {@code true} if current statement needs to do this. */ boolean recordSnapshot(QueryPlan queryPlan); diff --git ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java index ee7c940d2b..455ffc3887 100644 --- ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java +++ ql/src/java/org/apache/hadoop/hive/ql/session/SessionState.java @@ -501,6 +501,7 @@ public HiveTxnManager getTxnMgr() { * it's not coupled to the executing thread. Since tests run against Derby which often wedges * under concurrent access, tests must use a single thead and simulate concurrent access. * For example, {@code TestDbTxnManager2} + * @return previous {@link HiveTxnManager} or null */ @VisibleForTesting public HiveTxnManager setTxnMgr(HiveTxnManager mgr) { diff --git standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnCommonUtils.java standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnCommonUtils.java index 94cb18dccc..c61a997612 100644 --- standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnCommonUtils.java +++ standalone-metastore/metastore-common/src/main/java/org/apache/hadoop/hive/metastore/txn/TxnCommonUtils.java @@ -41,6 +41,7 @@ * @return a valid txn list. */ public static ValidTxnList createValidReadTxnList(GetOpenTxnsResponse txns, long currentTxn) { + assert currentTxn <= txns.getTxn_high_water_mark(); /* * The highWaterMark should be min(currentTxn,txns.getTxn_high_water_mark()) assuming currentTxn>0 * otherwise if currentTxn=7 and 8 commits before 7, then 7 will see result of 8 which