Skip to content

Commit c67ea6e

Browse files
Backport #97835 to 26.2: Fix txn->getState() != MergeTreeTransaction::COMMITTED for server fuzzer with implicit_transaction
1 parent c57ff5f commit c67ea6e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Interpreters/executeQuery.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,8 +1382,10 @@ static BlockIO executeQueryImpl(
13821382
{
13831383
if (auto txn = context->getCurrentTransaction())
13841384
{
1385-
chassert(txn->getState() != MergeTreeTransaction::COMMITTING);
1386-
chassert(txn->getState() != MergeTreeTransaction::COMMITTED);
1385+
if (txn->getState() == MergeTreeTransaction::COMMITTING)
1386+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Transaction {} is in a committing state", txn->tid);
1387+
if (txn->getState() == MergeTreeTransaction::COMMITTED)
1388+
throw Exception(ErrorCodes::LOGICAL_ERROR, "Transaction {} has been already committed", txn->tid);
13871389
bool is_special_query = out_ast && (out_ast->as<ASTTransactionControl>() || out_ast->as<ASTExplainQuery>());
13881390
if (txn->getState() == MergeTreeTransaction::ROLLED_BACK && !is_special_query)
13891391
throw Exception(
@@ -2020,6 +2022,10 @@ static void executeASTFuzzerQueries(const ASTPtr & ast, const ContextMutablePtr
20202022

20212023
try
20222024
{
2025+
/// Reset the transaction (if any), it is stored in session and local context (see InterpreterTransactionControlQuery::executeBegin())
2026+
context->getQueryContext()->getSessionContext()->setCurrentTransaction(NO_TRANSACTION_PTR);
2027+
context->setCurrentTransaction(NO_TRANSACTION_PTR);
2028+
20232029
auto fuzz_context = Context::createCopy(context);
20242030
fuzz_context->setSetting("ast_fuzzer_runs", Field(Float64(0)));
20252031
fuzz_context->setCurrentQueryId("");

0 commit comments

Comments
 (0)