From b9ab23d56fce0c5e508a806b7920d8999eee5e66 Mon Sep 17 00:00:00 2001 From: davis zhen Date: Mon, 12 Aug 2024 00:06:41 +0800 Subject: [PATCH] fix txn opt (#17982) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:一个请求中,有多个语句。当第一个语句为begin时,下一条语句会提交事务。 原因:begin语句时,设置的option,执行完后没有立即清理。导致下一条语句执行时,创建了新事务。 修改:option每次复位。 Approved by: @qingxinhome, @sukki37 --- pkg/frontend/back_exec.go | 2 +- pkg/frontend/mysql_cmd_executor.go | 5 ++++- pkg/frontend/txn.go | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/frontend/back_exec.go b/pkg/frontend/back_exec.go index 63de190c2daf1..be9c01b399302 100644 --- a/pkg/frontend/back_exec.go +++ b/pkg/frontend/back_exec.go @@ -332,7 +332,7 @@ func doComQueryInBack(backSes *backSession, execCtx *ExecCtx, return err } } - + execCtx.txnOpt.Close() execCtx.stmt = stmt execCtx.isLastStmt = i >= len(cws)-1 execCtx.tenant = tenant diff --git a/pkg/frontend/mysql_cmd_executor.go b/pkg/frontend/mysql_cmd_executor.go index 562aa63dfcbf7..488ccb08ee93c 100644 --- a/pkg/frontend/mysql_cmd_executor.go +++ b/pkg/frontend/mysql_cmd_executor.go @@ -34,10 +34,11 @@ import ( "github.com/confluentinc/confluent-kafka-go/v2/kafka" "github.com/fagongzi/goetty/v2" "github.com/google/uuid" - "github.com/matrixorigin/matrixone/pkg/catalog" "go.uber.org/zap" "go.uber.org/zap/zapcore" + "github.com/matrixorigin/matrixone/pkg/catalog" + "github.com/matrixorigin/matrixone/pkg/clusterservice" "github.com/matrixorigin/matrixone/pkg/common/moerr" "github.com/matrixorigin/matrixone/pkg/common/runtime" @@ -2291,6 +2292,7 @@ func executeStmtWithWorkspace(ses FeSession, //1. start txn //special BEGIN,COMMIT,ROLLBACK beginStmt := false + execCtx.txnOpt.Close() switch execCtx.stmt.(type) { case *tree.BeginTransaction: execCtx.txnOpt.byBegin = true @@ -2806,6 +2808,7 @@ func doComQuery(ses *Session, execCtx *ExecCtx, input *UserInput) (retErr error) if ses.proc != nil { ses.proc.UnixTime = proc.UnixTime } + execCtx.txnOpt.Close() execCtx.stmt = stmt execCtx.isLastStmt = i >= len(cws)-1 execCtx.tenant = tenant diff --git a/pkg/frontend/txn.go b/pkg/frontend/txn.go index 3bd5b8fcd1712..4d24ba997e47f 100644 --- a/pkg/frontend/txn.go +++ b/pkg/frontend/txn.go @@ -142,6 +142,13 @@ type FeTxnOption struct { byRollback bool } +func (opt *FeTxnOption) Close() { + opt.byBegin = false + opt.autoCommit = true + opt.byCommit = false + opt.byRollback = false +} + const ( defaultServerStatus uint32 = uint32(SERVER_STATUS_AUTOCOMMIT) defaultOptionBits uint32 = OPTION_AUTOCOMMIT