Skip to content

Commit

Permalink
fix txn opt (#17982)
Browse files Browse the repository at this point in the history
问题:一个请求中,有多个语句。当第一个语句为begin时,下一条语句会提交事务。
原因:begin语句时,设置的option,执行完后没有立即清理。导致下一条语句执行时,创建了新事务。
修改:option每次复位。

Approved by: @qingxinhome, @sukki37
  • Loading branch information
daviszhen authored Aug 11, 2024
1 parent d860a3f commit b9ab23d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/frontend/back_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion pkg/frontend/mysql_cmd_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pkg/frontend/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b9ab23d

Please sign in to comment.