diff --git a/ddl/db_test.go b/ddl/db_test.go index 3380af7e0a2c5..629316af251a4 100644 --- a/ddl/db_test.go +++ b/ddl/db_test.go @@ -1577,3 +1577,52 @@ func TestSetInvalidDefaultValueAfterModifyColumn(t *testing.T) { wg.Wait() require.EqualError(t, checkErr, "[ddl:1101]BLOB/TEXT/JSON column 'a' can't have a default value") } + +func TestMDLTruncateTable(t *testing.T) { + store, dom := testkit.CreateMockStoreAndDomain(t) + + tk := testkit.NewTestKit(t, store) + tk2 := testkit.NewTestKit(t, store) + tk3 := testkit.NewTestKit(t, store) + tk.MustExec("use test") + tk.MustExec("create table t(a int);") + tk.MustExec("begin") + tk.MustExec("select * from t for update") + + var wg sync.WaitGroup + + hook := &ddl.TestDDLCallback{Do: dom} + wg.Add(2) + var timetk2 time.Time + var timetk3 time.Time + + one := false + f := func(job *model.Job) { + if !one { + one = true + } else { + return + } + go func() { + tk3.MustExec("truncate table test.t") + timetk3 = time.Now() + wg.Done() + }() + } + + hook.OnJobUpdatedExported.Store(&f) + dom.DDL().SetHook(hook) + + go func() { + tk2.MustExec("truncate table test.t") + timetk2 = time.Now() + wg.Done() + }() + + time.Sleep(2 * time.Second) + timeMain := time.Now() + tk.MustExec("commit") + wg.Wait() + require.True(t, timetk2.After(timeMain)) + require.True(t, timetk3.After(timeMain)) +} diff --git a/ddl/job_table.go b/ddl/job_table.go index 740bb5c0b7da1..16dd6fa45f1e3 100644 --- a/ddl/job_table.go +++ b/ddl/job_table.go @@ -370,6 +370,8 @@ func job2UniqueIDs(job *model.Job, schema bool) string { } slices.Sort(s) return strings.Join(s, ",") + case model.ActionTruncateTable: + return strconv.FormatInt(job.TableID, 10) + "," + strconv.FormatInt(job.Args[0].(int64), 10) } if schema { return strconv.FormatInt(job.SchemaID, 10) diff --git a/ddl/metadatalocktest/mdl_test.go b/ddl/metadatalocktest/mdl_test.go index fd307968cad73..d7c05fa334508 100644 --- a/ddl/metadatalocktest/mdl_test.go +++ b/ddl/metadatalocktest/mdl_test.go @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -//go:build !featuretag - package metadatalocktest import (