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

*: wip #57457

Closed
Closed

*: wip #57457

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
67 changes: 66 additions & 1 deletion tests/realtikvtest/addindextest1/disttask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ package addindextest
import (
"context"
"fmt"
"strings"
"sync"
"sync/atomic"
"testing"
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/config"
Expand Down Expand Up @@ -109,7 +111,7 @@ func TestAddIndexDistBasic(t *testing.T) {
tk.MustExec(`set global tidb_enable_dist_task=0;`)
}

func TestAddIndexDistCancel(t *testing.T) {
func TestAddIndexDistCancelWithPartition(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
if store.Name() != "TiKV" {
t.Skip("TiKV store only")
Expand Down Expand Up @@ -150,6 +152,69 @@ func TestAddIndexDistCancel(t *testing.T) {
tk.MustExec(`set global tidb_enable_dist_task=0;`)
}

func TestAddIndexDistCancel(t *testing.T) {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists addindexlit;")
tk.MustExec("create database addindexlit;")
tk.MustExec("use addindexlit;")
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`)
tk.MustExec("create table t (a int, b int);")
tk.MustExec("insert into t values (1, 1), (2, 2), (3, 3);")

tk2 := testkit.NewTestKit(t, store)
tk2.MustExec("use addindexlit;")
tk2.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`)
tk2.MustExec("create table t2 (a int, b int);")
tk2.MustExec("insert into t2 values (1, 1), (2, 2), (3, 3);")

wg := &sync.WaitGroup{}
wg.Add(2)
go func() {
tk.MustExec("alter table t add index idx(a);")
wg.Done()
}()
go func() {
tk2.MustExec("alter table t2 add index idx_b(b);")
wg.Done()
}()
wg.Wait()
rows := tk.MustQuery("admin show ddl jobs 2;").Rows()
require.Len(t, rows, 2)
require.True(t, strings.Contains(rows[0][3].(string) /* job_type */, "ingest"))
require.True(t, strings.Contains(rows[1][3].(string) /* job_type */, "ingest"))
require.Equal(t, rows[0][7].(string) /* row_count */, "3")
require.Equal(t, rows[1][7].(string) /* row_count */, "3")

tk.MustExec("set @@global.tidb_enable_dist_task = 1;")

// test cancel is timely
enter := make(chan struct{})
testfailpoint.EnableCall(
t,
"github.com/pingcap/tidb/pkg/lightning/backend/local/beforeExecuteRegionJob",
func(ctx context.Context) {
close(enter)
select {
case <-time.After(time.Second * 20):
case <-ctx.Done():
}
})
wg.Add(1)
go func() {
defer wg.Done()
err := tk2.ExecToErr("alter table t add index idx_ba(b, a);")
require.ErrorContains(t, err, "Cancelled DDL job")
}()
<-enter
jobID := tk.MustQuery("admin show ddl jobs 1;").Rows()[0][0].(string)
now := time.Now()
tk.MustExec("admin cancel ddl jobs " + jobID)
wg.Wait()
// cancel should be timely
require.Less(t, time.Since(now).Seconds(), 10.0)
}

func TestAddIndexDistPauseAndResume(t *testing.T) {
t.Skip("unstable") // TODO(tangenta): fix this unstable test
store := realtikvtest.CreateMockStoreAndSetup(t)
Expand Down