Skip to content

Commit

Permalink
ddl: split add index realtikv tests (pingcap#48093) (pingcap#48143)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Oct 31, 2023
1 parent 93996da commit 3e7cfc1
Show file tree
Hide file tree
Showing 15 changed files with 249 additions and 292 deletions.
29 changes: 0 additions & 29 deletions tests/realtikvtest/addindextest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,15 @@ go_test(
"add_index_test.go",
"concurrent_ddl_test.go",
"failpoints_test.go",
"global_sort_test.go",
"integration_test.go",
"main_test.go",
"multi_schema_change_test.go",
"operator_test.go",
"pitr_test.go",
],
embed = [":addindextest"],
deps = [
"//br/pkg/lightning/backend/external",
"//br/pkg/lightning/backend/local",
"//br/pkg/storage",
"//pkg/config",
"//pkg/ddl",
"//pkg/ddl/copr",
"//pkg/ddl/ingest",
"//pkg/ddl/testutil",
"//pkg/ddl/util/callback",
"//pkg/disttask/framework/dispatcher",
"//pkg/disttask/framework/proto",
"//pkg/disttask/operator",
"//pkg/domain",
"//pkg/errno",
"//pkg/kv",
"//pkg/parser/model",
"//pkg/sessionctx",
"//pkg/sessionctx/variable",
"//pkg/table",
"//pkg/table/tables",
"//pkg/testkit",
"//pkg/util/chunk",
"//tests/realtikvtest",
"@com_github_fsouza_fake_gcs_server//fakestorage",
"@com_github_ngaut_pools//:pools",
"@com_github_phayes_freeport//:freeport",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@org_golang_x_sync//errgroup",
],
)
156 changes: 0 additions & 156 deletions tests/realtikvtest/addindextest/add_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,9 @@ package addindextest
import (
"testing"

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/config"
"github.com/pingcap/tidb/pkg/ddl"
"github.com/pingcap/tidb/pkg/ddl/util/callback"
"github.com/pingcap/tidb/pkg/disttask/framework/dispatcher"
"github.com/pingcap/tidb/pkg/disttask/framework/proto"
"github.com/pingcap/tidb/pkg/parser/model"
"github.com/pingcap/tidb/pkg/testkit"
"github.com/pingcap/tidb/tests/realtikvtest"
"github.com/stretchr/testify/require"
)

func init() {
Expand Down Expand Up @@ -133,152 +126,3 @@ func TestAddForeignKeyWithAutoCreateIndex(t *testing.T) {
tk.MustExec("update employee set pid=id-1 where id>1 and pid is null")
tk.MustExec("alter table employee add foreign key fk_1(pid) references employee(id)")
}

func TestAddIndexDistBasic(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
if store.Name() != "TiKV" {
t.Skip("TiKV store only")
}

tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists test;")
tk.MustExec("create database test;")
tk.MustExec("use test;")
tk.MustExec(`set global tidb_enable_dist_task=1;`)

tk.MustExec("create table t(a bigint auto_random primary key) partition by hash(a) partitions 20;")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("split table t between (3) and (8646911284551352360) regions 50;")
tk.MustExec("alter table t add index idx(a);")
tk.MustExec("admin check index t idx;")

tk.MustExec("create table t1(a bigint auto_random primary key);")
tk.MustExec("insert into t1 values (), (), (), (), (), ()")
tk.MustExec("insert into t1 values (), (), (), (), (), ()")
tk.MustExec("insert into t1 values (), (), (), (), (), ()")
tk.MustExec("insert into t1 values (), (), (), (), (), ()")
tk.MustExec("split table t1 between (3) and (8646911284551352360) regions 50;")
tk.MustExec("alter table t1 add index idx(a);")
tk.MustExec("admin check index t1 idx;")

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/disttask/framework/scheduler/MockRunSubtaskContextCanceled", "1*return(true)"))
tk.MustExec("alter table t1 add index idx1(a);")
tk.MustExec("admin check index t1 idx1;")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/disttask/framework/scheduler/MockRunSubtaskContextCanceled"))
tk.MustExec(`set global tidb_enable_dist_task=0;`)
}

func TestAddIndexDistCancel(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
if store.Name() != "TiKV" {
t.Skip("TiKV store only")
}

tk := testkit.NewTestKit(t, store)
tk1 := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists test;")
tk.MustExec("create database test;")
tk.MustExec("use test;")
tk.MustExec(`set global tidb_enable_dist_task=1;`)

tk.MustExec("create table t(a bigint auto_random primary key) partition by hash(a) partitions 8;")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("split table t between (3) and (8646911284551352360) regions 50;")

ddl.MockDMLExecutionAddIndexSubTaskFinish = func() {
row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
require.Equal(t, 1, len(row))
jobID := row[0][0].(string)
tk1.MustExec("admin cancel ddl jobs " + jobID)
}

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionAddIndexSubTaskFinish", "1*return(true)"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionAddIndexSubTaskFinish"))
}()

require.Error(t, tk.ExecToErr("alter table t add index idx(a);"))
tk.MustExec("admin check table t;")
tk.MustExec("alter table t add index idx2(a);")
tk.MustExec("admin check table t;")

tk.MustExec(`set global tidb_enable_dist_task=0;`)
}

func TestAddIndexDistPauseAndResume(t *testing.T) {
store, dom := realtikvtest.CreateMockStoreAndDomainAndSetup(t)
if store.Name() != "TiKV" {
t.Skip("TiKV store only")
}

tk := testkit.NewTestKit(t, store)
tk1 := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists test;")
tk.MustExec("create database test;")
tk.MustExec("use test;")

tk.MustExec("create table t(a bigint auto_random primary key) partition by hash(a) partitions 8;")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("insert into t values (), (), (), (), (), ()")
tk.MustExec("split table t between (3) and (8646911284551352360) regions 50;")

ddl.MockDMLExecutionAddIndexSubTaskFinish = func() {
row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
require.Equal(t, 1, len(row))
jobID := row[0][0].(string)
tk1.MustExec("admin pause ddl jobs " + jobID)
<-ddl.TestSyncChan
}

dispatcher.MockDMLExecutionOnPausedState = func(task *proto.Task) {
row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
require.Equal(t, 1, len(row))
jobID := row[0][0].(string)
tk1.MustExec("admin resume ddl jobs " + jobID)
}

ddl.MockDMLExecutionOnTaskFinished = func() {
row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
require.Equal(t, 1, len(row))
jobID := row[0][0].(string)
tk1.MustExec("admin pause ddl jobs " + jobID)
}

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionAddIndexSubTaskFinish", "3*return(true)"))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/disttask/framework/dispatcher/mockDMLExecutionOnPausedState", "return(true)"))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/syncDDLTaskPause", "return()"))
tk.MustExec(`set global tidb_enable_dist_task=1;`)
tk.MustExec("alter table t add index idx1(a);")
tk.MustExec("admin check table t;")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/mockDMLExecutionAddIndexSubTaskFinish"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/disttask/framework/dispatcher/mockDMLExecutionOnPausedState"))

// dist task succeed, job paused and resumed.
var hook = &callback.TestDDLCallback{Do: dom}
var resumeFunc = func(job *model.Job) {
if job.IsPaused() {
row := tk1.MustQuery("select job_id from mysql.tidb_ddl_job").Rows()
require.Equal(t, 1, len(row))
jobID := row[0][0].(string)
tk1.MustExec("admin resume ddl jobs " + jobID)
}
}
hook.OnJobUpdatedExported.Store(&resumeFunc)
dom.DDL().SetHook(hook.Clone())
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/pauseAfterDistTaskFinished", "1*return(true)"))
tk.MustExec("alter table t add index idx3(a);")
tk.MustExec("admin check table t;")
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/pauseAfterDistTaskFinished"))
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/ddl/syncDDLTaskPause"))

tk.MustExec(`set global tidb_enable_dist_task=0;`)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022 PingCAP, Inc.
// Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
5 changes: 4 additions & 1 deletion tests/realtikvtest/addindextest1/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ go_test(
name = "addindextest1_test",
timeout = "short",
srcs = [
"dummy_test.go",
"disttask_test.go",
"main_test.go",
],
flaky = True,
deps = [
"//pkg/config",
"//pkg/ddl",
"//pkg/testkit",
"//tests/realtikvtest",
"@com_github_pingcap_failpoint//:failpoint",
"@com_github_stretchr_testify//require",
],
)
Loading

0 comments on commit 3e7cfc1

Please sign in to comment.