Repository: pingcap/tidb
File: pkg/ddl/executor.go (Go)

Code before:
	switch action {
	case model.ActionAddIndex, model.ActionAddPrimaryKey, model.ActionModifyColumn,
		model.ActionReorganizePartition,
		model.ActionRemovePartitioning,
		model.ActionAlterTablePartitioning:
		return getIntervalFromPolicy(slowDDLIntervalPolicy, i)
	case model.ActionCreateTable, model.ActionCreateSchema:
		return getIntervalFromPolicy(fastDDLIntervalPolicy, i)
	default:
		return getIntervalFromPolicy(normalDDLIntervalPolicy, i)
	}
}

// NewDDLReorgMeta create a DDL ReorgMeta.
func NewDDLReorgMeta(ctx sessionctx.Context) *model.DDLReorgMeta {
	tzName, tzOffset := ddlutil.GetTimeZone(ctx)
	return &model.DDLReorgMeta{
		SQLMode:           ctx.GetSessionVars().SQLMode,
		Warnings:          make(map[errors.ErrorID]*terror.Error),
		WarningsCount:     make(map[errors.ErrorID]int64),
		Location:          &model.TimeZoneLocation{Name: tzName, Offset: tzOffset},
		ResourceGroupName: ctx.GetSessionVars().StmtCtx.ResourceGroupName,
		Version:           model.CurrentReorgMetaVersion,
		EnablePaging:      ctx.GetSessionVars().EnablePaging,
		MinPagingSize:     ctx.GetSessionVars().MinPagingSize,
		MaxPagingSize:     ctx.GetSessionVars().MaxPagingSize,
	}
}

// RefreshMeta is a internal DDL job. In some cases, BR log restore will EXCHANGE
// PARTITION\DROP TABLE by write meta kv directly, and table info in meta kv
// is inconsistent with info schema. So when BR call AlterTableMode for new table
// will failure. RefreshMeta will reload schema diff to update info schema by
// schema ID and table ID to make sure data in meta kv and info schema is consistent.
func (e *executor) RefreshMeta(sctx sessionctx.Context, args *model.RefreshMetaArgs) error {
	job := &model.Job{
		Version:        model.JobVersion2,
		SchemaID:       args.SchemaID,
		TableID:        args.TableID,
		SchemaName:     args.InvolvedDB,
		Type:           model.ActionRefreshMeta,
		BinlogInfo:     &model.HistoryInfo{},
		CDCWriteSource: sctx.GetSessionVars().CDCWriteSource,
		SQLMode:        sctx.GetSessionVars().SQLMode,
		InvolvingSchemaInfo: []model.InvolvingSchemaInfo{
			{
				Database: args.InvolvedDB,
				Table:    args.InvolvedTable,
			},
		},
	}

Review comment (suggestion):
for a temporary verifying fix, it's ok to get the value from session vars, but if we want to merge to master, we should calculate those params based on the allocated resource

Code after:
	switch action {
	case model.ActionAddIndex, model.ActionAddPrimaryKey, model.ActionModifyColumn,
		model.ActionReorganizePartition,
		model.ActionRemovePartitioning,
		model.ActionAlterTablePartitioning:
		return getIntervalFromPolicy(slowDDLIntervalPolicy, i)
	case model.ActionCreateTable, model.ActionCreateSchema:
		return getIntervalFromPolicy(fastDDLIntervalPolicy, i)
	default:
		return getIntervalFromPolicy(normalDDLIntervalPolicy, i)
	}
}

// NewDDLReorgMeta create a DDL ReorgMeta.
func NewDDLReorgMeta(ctx sessionctx.Context) *model.DDLReorgMeta {
	tzName, tzOffset := ddlutil.GetTimeZone(ctx)
	return &model.DDLReorgMeta{
		SQLMode:           ctx.GetSessionVars().SQLMode,
		Warnings:          make(map[errors.ErrorID]*terror.Error),
		WarningsCount:     make(map[errors.ErrorID]int64),
		Location:          &model.TimeZoneLocation{Name: tzName, Offset: tzOffset},
		ResourceGroupName: ctx.GetSessionVars().StmtCtx.ResourceGroupName,
		Version:           model.CurrentReorgMetaVersion,
	}
}

// RefreshMeta is a internal DDL job. In some cases, BR log restore will EXCHANGE
// PARTITION\DROP TABLE by write meta kv directly, and table info in meta kv
// is inconsistent with info schema. So when BR call AlterTableMode for new table
// will failure. RefreshMeta will reload schema diff to update info schema by
// schema ID and table ID to make sure data in meta kv and info schema is consistent.
func (e *executor) RefreshMeta(sctx sessionctx.Context, args *model.RefreshMetaArgs) error {
	job := &model.Job{
		Version:        model.JobVersion2,
		SchemaID:       args.SchemaID,
		TableID:        args.TableID,
		SchemaName:     args.InvolvedDB,
		Type:           model.ActionRefreshMeta,
		BinlogInfo:     &model.HistoryInfo{},
		CDCWriteSource: sctx.GetSessionVars().CDCWriteSource,
		SQLMode:        sctx.GetSessionVars().SQLMode,
		InvolvingSchemaInfo: []model.InvolvingSchemaInfo{
			{
				Database: args.InvolvedDB,
				Table:    args.InvolvedTable,
			},
		},
	}
	sctx.SetValue(sessionctx.QueryString, "skip")
	err := e.doDDLJob2(sctx, job, args)
	return errors.Trace(err)