Skip to content

Commit

Permalink
ddl: let concurrent truncate on the same table depend on the previous…
Browse files Browse the repository at this point in the history
… one (#40501)

* done

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>

* refine test

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>

Signed-off-by: wjhuang2016 <huangwenjun1997@gmail.com>
Co-authored-by: Ti Chi Robot <ti-community-prow-bot@tidb.io>
  • Loading branch information
wjhuang2016 and ti-chi-bot authored Jan 11, 2023
1 parent e3f8d98 commit 2cf328b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
49 changes: 49 additions & 0 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
2 changes: 2 additions & 0 deletions ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions ddl/metadatalocktest/mdl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build !featuretag

package metadatalocktest

import (
Expand Down

0 comments on commit 2cf328b

Please sign in to comment.