deniskuzZ commented on code in PR #5216:
URL: https://github.com/apache/hive/pull/5216#discussion_r1624164090
##########
ql/src/java/org/apache/hadoop/hive/ql/Compiler.java:
##########
@@ -257,97 +256,111 @@ private BaseSemanticAnalyzer analyze() throws Exception {
private void setLastReplIdForDump(HiveConf conf) throws HiveException,
TException {
// Last logged notification event id would be the last repl Id for the
current REPl DUMP.
Hive hiveDb = Hive.get();
- Long lastReplId =
hiveDb.getMSC().getCurrentNotificationEventId().getEventId();
+ long lastReplId =
hiveDb.getMSC().getCurrentNotificationEventId().getEventId();
conf.setLong(ReplUtils.LAST_REPL_ID_KEY, lastReplId);
LOG.debug("Setting " + ReplUtils.LAST_REPL_ID_KEY + " = " + lastReplId);
}
- private void openTransaction(TxnType txnType) throws LockException,
CommandProcessorException {
- if (DriverUtils.checkConcurrency(driverContext) &&
startImplicitTxn(driverContext.getTxnManager()) &&
- !driverContext.getTxnManager().isTxnOpen() &&
!MetaStoreServerUtils.isCompactionTxn(txnType)) {
- String userFromUGI = DriverUtils.getUserFromUGI(driverContext);
- if
(HiveOperation.REPLDUMP.equals(driverContext.getQueryState().getHiveOperation())
- ||
HiveOperation.REPLLOAD.equals(driverContext.getQueryState().getHiveOperation()))
{
-
context.setReplPolicy(PlanUtils.stripQuotes(tree.getChild(0).getText()));
+ private String openTxnAndGetValidTxnList() {
+ String txnString =
driverContext.getConf().get(ValidTxnList.VALID_TXNS_KEY);
+ if (SessionState.get().isCompaction()) {
+ return txnString;
+ }
+ HiveTxnManager txnMgr = driverContext.getTxnManager();
+ try {
+ openTransaction(txnMgr);
+ if (txnMgr.isTxnOpen() && Strings.isEmpty(txnString)) {
+ txnString = generateValidTxnList(txnMgr);
}
- driverContext.getTxnManager().openTxn(context, userFromUGI, txnType);
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to open a new transaction", e);
}
+ return txnString;
}
- private boolean startImplicitTxn(HiveTxnManager txnManager) throws
LockException {
+ private void openTransaction(HiveTxnManager txnMgr) throws LockException,
CommandProcessorException {
+ if (txnMgr.isTxnOpen() || !DriverUtils.checkConcurrency(driverContext)
+ || !startImplicitTxn()) {
+ return;
+ }
+ TxnType txnType = AcidUtils.getTxnType(driverContext.getConf(), tree);
+ driverContext.setTxnType(txnType);
+
+ HiveOperation hiveOperation = queryState.getHiveOperation();
+ if ((HiveOperation.REPLDUMP == hiveOperation || HiveOperation.REPLLOAD ==
hiveOperation)
+ && !context.isExplainPlan()) {
+ context.setReplPolicy(PlanUtils.stripQuotes(tree.getChild(0).getText()));
+ }
+ String userFromUGI = DriverUtils.getUserFromUGI(driverContext);
+ txnMgr.openTxn(context, userFromUGI, txnType);
+ }
+
+ private boolean startImplicitTxn() {
//this is dumb. HiveOperation is not always set. see HIVE-16447/HIVE-16443
- HiveOperation hiveOperation =
driverContext.getQueryState().getHiveOperation();
+ HiveOperation hiveOperation = queryState.getHiveOperation();
switch (hiveOperation == null ? HiveOperation.QUERY : hiveOperation) {
- case COMMIT:
- case ROLLBACK:
- if (!txnManager.isTxnOpen()) {
- throw new LockException(null, ErrorMsg.OP_NOT_ALLOWED_WITHOUT_TXN,
hiveOperation.getOperationName());
- }
Review Comment:
this code was moved to `verifyTxnState` is now more generic
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]