From 072f64c80088750c996b8056b0d7c459cdaa5669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Fri, 24 Jun 2022 16:54:47 +0200 Subject: [PATCH] Improvements based on review --- src/Interpreters/executeQuery.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/Interpreters/executeQuery.cpp b/src/Interpreters/executeQuery.cpp index ae622e5e1f0..4b328f0466e 100644 --- a/src/Interpreters/executeQuery.cpp +++ b/src/Interpreters/executeQuery.cpp @@ -626,8 +626,10 @@ static std::tuple executeQueryImpl( if (!table_id.empty()) context->setInsertionTable(table_id); - if (context->getCurrentTransaction() && context->getSettingsRef().throw_on_unsupported_query_inside_transaction) + if (context->getCurrentTransaction() && settings.throw_on_unsupported_query_inside_transaction) throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Async inserts inside transactions are not supported"); + if (settings.implicit_transaction && settings.throw_on_unsupported_query_inside_transaction) + throw Exception(ErrorCodes::NOT_IMPLEMENTED, "Async inserts with 'implicit_transaction' are not supported"); } else { @@ -636,6 +638,9 @@ static std::tuple executeQueryImpl( { try { + if (context->isGlobalContext()) + throw Exception(ErrorCodes::LOGICAL_ERROR, "Global context cannot create transactions"); + /// If there is no session (which is the default for the HTTP Handler), set up one just for this as it is necessary /// to control the transaction lifetime if (!context->hasSessionContext()) @@ -972,8 +977,18 @@ static std::tuple executeQueryImpl( if (implicit_txn_control) { - implicit_txn_control->executeCommit(context->getSessionContext()); - implicit_txn_control.reset(); + try + { + implicit_txn_control->executeCommit(context->getSessionContext()); + implicit_txn_control.reset(); + } + catch (const Exception &) + { + /// An exception might happen when trying to commit the transaction. For example we might get an immediate exception + /// because ZK is down and wait_changes_become_visible_after_commit_mode == WAIT_UNKNOWN + implicit_txn_control.reset(); + throw; + } } };