diff --git a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java index 94999fed93..31143ab7ab 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -191,6 +191,10 @@ // either initTxnMgr or from the SessionState, in that order. private HiveTxnManager queryTxnMgr; + // Boolean to store information about whether valid txn list was generated + // for current query. + private boolean validTxnListsGenerated; + private CacheUsage cacheUsage; private CacheEntry usedCacheEntry; @@ -595,6 +599,22 @@ public void run() { long txnid = queryTxnMgr.openTxn(ctx, userFromUGI); } } + + // Record current valid txn list that will be used throughout the query + // compilation and processing. We only do this if it has not been + // recorded yet. + validTxnListsGenerated = false; + try { + String currentTxnString = conf.get(ValidTxnList.VALID_TXNS_KEY); + if (currentTxnString == null || currentTxnString.isEmpty()) { + recordValidTxns(queryTxnMgr); + validTxnListsGenerated = true; + } + } catch (Exception e) { + LOG.error("Exception while acquiring valid txn list", e); + throw e; + } + // Do semantic analysis and plan generation if (hookRunner.hasPreAnalyzeHooks()) { HiveSemanticAnalyzerHookContext hookCtx = new HiveSemanticAnalyzerHookContextImpl(); @@ -1335,8 +1355,10 @@ private void acquireLocks() throws CommandProcessorResponse { /*It's imperative that {@code acquireLocks()} is called for all commands so that HiveTxnManager can transition its state machine correctly*/ queryTxnMgr.acquireLocks(plan, ctx, userFromUGI, lDrvState); - if (queryTxnMgr.recordSnapshot(plan)) { - recordValidTxns(queryTxnMgr); + // 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())); } if (plan.hasAcidResourcesInQuery()) { recordValidWriteIds(queryTxnMgr); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java b/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java index 683aa954cf..ec15699c4a 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/lockmgr/DbTxnManager.java @@ -839,13 +839,11 @@ public boolean recordSnapshot(QueryPlan queryPlan) { } else if(!isExplicitTransaction) { assert numStatements == 1 : "numStatements=" + numStatements + " in implicit txn"; - if (queryPlan.hasAcidResourcesInQuery()) { - //1st and only stmt in implicit txn and uses acid resource - return true; - } + return true; } return false; } + @Override public boolean isImplicitTransactionOpen() { if(!isTxnOpen()) {