Skip to content

Commit

Permalink
ddl: fix incorrect truncate table's scheme_ids (#52591)
Browse files Browse the repository at this point in the history
close #52589
  • Loading branch information
wjhuang2016 authored Apr 17, 2024
1 parent 4ab889c commit ba0ebc5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
43 changes: 43 additions & 0 deletions pkg/ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,49 @@ func TestMDLTruncateTable(t *testing.T) {
require.True(t, timetk3.After(timeMain))
}

func TestTruncateTableAndSchemaDependence(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);")

var wg sync.WaitGroup

hook := &callback.TestDDLCallback{Do: dom}
wg.Add(2)
var timetk2 time.Time
var timetk3 time.Time

one := false
f := func(job *model.Job) {
if one {
return
}
one = true
go func() {
tk3.MustExec("drop database test")
timetk3 = time.Now()
wg.Done()
}()
time.Sleep(3 * time.Second)
}

hook.OnJobUpdatedExported.Store(&f)
dom.DDL().SetHook(hook)

go func() {
tk2.MustExec("truncate table test.t")
timetk2 = time.Now()
wg.Done()
}()

wg.Wait()
require.True(t, timetk3.After(timetk2))
}

func TestInsertIgnore(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)

Expand Down
3 changes: 3 additions & 0 deletions pkg/ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ func job2UniqueIDs(job *model.Job, schema bool) string {
slices.Sort(s)
return strings.Join(s, ",")
case model.ActionTruncateTable:
if schema {
return strconv.FormatInt(job.SchemaID, 10)
}
return strconv.FormatInt(job.TableID, 10) + "," + strconv.FormatInt(job.Args[0].(int64), 10)
}
if schema {
Expand Down

0 comments on commit ba0ebc5

Please sign in to comment.