Skip to content

Commit

Permalink
txn: check MDL when starting and committing pipelined txns (#51794)
Browse files Browse the repository at this point in the history
ref #50215
  • Loading branch information
ekexium committed Mar 15, 2024
1 parent 932ff72 commit 1bac1d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/session/session.go
Expand Up @@ -570,6 +570,9 @@ func (s *session) doCommit(ctx context.Context) error {
if s.GetSessionVars().TxnCtx != nil {
needCheckSchema = !s.GetSessionVars().TxnCtx.EnableMDL
}
if s.txn.IsPipelined() && !s.GetSessionVars().TxnCtx.EnableMDL {
return errors.New("cannot commit pipelined transaction without Metadata Lock: MDL is OFF")
}
s.txn.SetOption(kv.SchemaChecker, domain.NewSchemaChecker(domain.GetDomain(s), s.GetInfoSchema().SchemaMetaVersion(), physicalTableIDs, needCheckSchema))
s.txn.SetOption(kv.InfoSchema, s.sessionVars.TxnCtx.InfoSchema)
s.txn.SetOption(kv.CommitHook, func(info string, _ error) { s.sessionVars.LastTxnInfo = info })
Expand Down Expand Up @@ -4303,6 +4306,14 @@ func (s *session) usePipelinedDmlOrWarn() bool {
return false
}
vars := s.GetSessionVars()
if !vars.TxnCtx.EnableMDL {
stmtCtx.AppendWarning(
errors.New(
"Pipelined DML can not be used without Metadata Lock. Fallback to standard mode",
),
)
return false
}
if (vars.BatchCommit || vars.BatchInsert || vars.BatchDelete) && vars.DMLBatchSize > 0 && variable.EnableBatchDML.Load() {
stmtCtx.AppendWarning(errors.New("Pipelined DML can not be used with the deprecated Batch DML. Fallback to standard mode"))
return false
Expand Down
6 changes: 6 additions & 0 deletions tests/realtikvtest/pipelineddmltest/pipelineddml_test.go
Expand Up @@ -189,6 +189,12 @@ func TestPipelinedDMLNegative(t *testing.T) {
tk.MustExec("explain analyze insert into t values(9, 9)")
tk.MustQuery("show warnings").CheckContain("Pipelined DML can not be used with Binlog: BinlogClient != nil. Fallback to standard mode")
tk.Session().GetSessionVars().BinlogClient = nil

// disable MDL
tk.MustExec("set global tidb_enable_metadata_lock = off")
tk.MustExec("insert into t values(10, 10)")
tk.MustQuery("show warnings").CheckContain("Pipelined DML can not be used without Metadata Lock. Fallback to standard mode")
tk.MustExec("set global tidb_enable_metadata_lock = on")
}

func compareTables(t *testing.T, tk *testkit.TestKit, t1, t2 string) {
Expand Down

0 comments on commit 1bac1d4

Please sign in to comment.