Skip to content

fix: Transaction state is not changed correctly when returning error in commit statement #14824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 5, 2024
Merged
11 changes: 10 additions & 1 deletion src/query/service/src/interpreters/interpreter_txn_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::sync::Arc;

use databend_common_exception::Result;
use databend_common_storages_fuse::TableContext;
use databend_storages_common_txn::TxnManagerRef;

use crate::interpreters::Interpreter;
use crate::pipelines::PipelineBuildResult;
Expand Down Expand Up @@ -47,6 +48,7 @@ impl Interpreter for CommitInterpreter {

#[async_backtrace::framed]
async fn execute2(&self) -> Result<PipelineBuildResult> {
let _guard = ClearTxnManagerGuard(self.ctx.txn_mgr().clone());
let is_active = self.ctx.txn_mgr().lock().is_active();
if is_active {
let catalog = self.ctx.get_default_catalog()?;
Expand All @@ -57,7 +59,14 @@ impl Interpreter for CommitInterpreter {
PipelineBuilder::try_purge_files(self.ctx.clone(), &stage_info, &files).await;
}
}
self.ctx.txn_mgr().lock().clear();
Ok(PipelineBuildResult::create())
}
}

struct ClearTxnManagerGuard(TxnManagerRef);

impl Drop for ClearTxnManagerGuard {
fn drop(&mut self) {
self.0.lock().clear();
}
}