Skip to content

Commit

Permalink
*: tiny update
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Sep 4, 2024
1 parent b4380ee commit 3f94ed4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
4 changes: 2 additions & 2 deletions pkg/ddl/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func cancelSuccess(rs *testkit.Result) bool {
return strings.Contains(rs.Rows()[0][1].(string), "success")
}

func TestCancel(t *testing.T) {
func TestCancelVariousJobs(t *testing.T) {
var enterCnt, exitCnt atomic.Int32
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/beforeDeliveryJob", func(job *model.Job) { enterCnt.Add(1) })
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/afterDeliveryJob", func(job *model.Job) { exitCnt.Add(1) })
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestCancel(t *testing.T) {
tk.MustExec(`create table t (
c1 int, c2 int, c3 int, c11 tinyint, v2 vector(3), index fk_c1(c1)
);`)
tk.MustExec("alter table t set tiflash replica 3 location labels 'a','b';")
tk.MustExec("alter table t set tiflash replica 2 location labels 'a','b';")

// Prepare data.
for i := 0; i <= 2048; i++ {
Expand Down
12 changes: 5 additions & 7 deletions pkg/ddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4625,15 +4625,13 @@ func (e *executor) createVectorIndex(ctx sessionctx.Context, ti ast.Ident, index
return errors.Trace(err)
}

finalColumns := make([]*model.ColumnInfo, len(tblInfo.Columns), len(tblInfo.Columns))
copy(finalColumns, tblInfo.Columns)
// Check before the job is put to the queue.
// This check is redundant, but useful. If DDL check fail before the job is put
// to job queue, the fail path logic is particularly fast.
// After DDL job is put to the queue, and if the check fail, TiDB will run the DDL cancel logic.
// The recover step causes DDL wait a few seconds, makes the unit test painfully slow.
// For same reason, decide whether index is global here.
_, _, err = buildIndexColumns(ctx, finalColumns, indexPartSpecifications, true)
_, _, err = buildIndexColumns(ctx, tblInfo.Columns, indexPartSpecifications, true)
if err != nil {
return errors.Trace(err)
}
Expand All @@ -4644,13 +4642,13 @@ func (e *executor) createVectorIndex(ctx sessionctx.Context, ti ast.Ident, index
return errors.Trace(err)
}

job, err := e.buildAddIndexJobWithoutTypeAndArgs(ctx, schema, t)
job, err := buildAddIndexJobWithoutTypeAndArgs(ctx, schema, t)
if err != nil {
return errors.Trace(err)
}
job.Type = model.ActionAddVectorIndex
indexPartSpecifications[0].Expr = nil
job.Args = []any{indexName, indexOption, indexPartSpecifications[0], funcExpr}
job.Args = []any{indexName, indexPartSpecifications[0], indexOption, funcExpr}
// TODO: support CDCWriteSource

err = e.DoDDLJob(ctx, job)
Expand All @@ -4662,7 +4660,7 @@ func (e *executor) createVectorIndex(ctx sessionctx.Context, ti ast.Ident, index
return errors.Trace(err)
}

func (e *executor) buildAddIndexJobWithoutTypeAndArgs(ctx sessionctx.Context, schema *model.DBInfo, t table.Table) (*model.Job, error) {
func buildAddIndexJobWithoutTypeAndArgs(ctx sessionctx.Context, schema *model.DBInfo, t table.Table) (*model.Job, error) {
tzName, tzOffset := ddlutil.GetTimeZone(ctx)
charset, collate := ctx.GetSessionVars().GetCharsetInfo()
job := &model.Job{
Expand Down Expand Up @@ -4841,7 +4839,7 @@ func (e *executor) createIndex(ctx sessionctx.Context, ti ast.Ident, keyType ast
// global is set to 'false' is just there to be backwards compatible,
// to avoid unmarshal issues, it is now part of indexOption.
global := false
job, err := e.buildAddIndexJobWithoutTypeAndArgs(ctx, schema, t)
job, err := buildAddIndexJobWithoutTypeAndArgs(ctx, schema, t)
if err != nil {
return errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ func (w *worker) onCreateVectorIndex(jobCtx *jobContext, t *meta.Meta, job *mode
indexPartSpecification *ast.IndexPartSpecification
funcExpr string
)
err = job.DecodeArgs(&indexName, &indexOption, &indexPartSpecification, &funcExpr)
err = job.DecodeArgs(&indexName, &indexPartSpecification, &indexOption, &funcExpr)
if err != nil {
job.State = model.JobStateCancelled
return ver, errors.Trace(err)
Expand Down
9 changes: 5 additions & 4 deletions pkg/ddl/rollingback.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,19 @@ func convertNotReorgAddIdxJob2RollbackJob(jobCtx *jobContext, t *meta.Meta, job
}

var funcExpr string
var indexPartSpecification *ast.IndexPartSpecification
unique := make([]bool, 1)
indexName := make([]model.CIStr, 1)
indexPartSpecifications := make([][]*ast.IndexPartSpecification, 1)
indexOption := make([]*ast.IndexOption, 1)

if !isVector {
err = job.DecodeArgs(&unique[0], &indexName[0], &indexPartSpecifications[0], &indexOption[0])
if err != nil {
err = job.DecodeArgs(&unique, &indexName, &indexPartSpecifications, &indexOption)
}
} else {
err = job.DecodeArgs(&indexName, &indexOption[0], &indexPartSpecifications[0], &funcExpr)
}
if err != nil {
err = job.DecodeArgs(&unique, &indexName, &indexPartSpecifications, &indexOption)
err = job.DecodeArgs(&indexName[0], &indexPartSpecification, &indexOption[0], &funcExpr)
}
if err != nil {
job.State = model.JobStateCancelled
Expand Down
2 changes: 1 addition & 1 deletion pkg/domain/infosync/tiflash_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ func (tiflash *MockTiFlash) SetNetworkError(e bool) {
}

// SyncTiFlashTableSchema syncs the table's schema to TiFlash.
func (m *mockTiFlashReplicaManagerCtx) SyncTiFlashTableSchema(_ int64, _ *pd.StoresInfo) error {
func (*mockTiFlashReplicaManagerCtx) SyncTiFlashTableSchema(_ int64, _ *pd.StoresInfo) error {
return nil
}

Expand Down

0 comments on commit 3f94ed4

Please sign in to comment.