Skip to content
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

txn: check MDL when starting and committing pipelined txns #51794

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/session/session.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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