Skip to content

Commit

Permalink
ddl: enable linter revive (#44380)
Browse files Browse the repository at this point in the history
ref #40786
  • Loading branch information
tangenta authored Jun 3, 2023
1 parent 6605403 commit ffea45b
Show file tree
Hide file tree
Showing 27 changed files with 183 additions and 210 deletions.
2 changes: 1 addition & 1 deletion br/pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ func WriteBackupDDLJobs(metaWriter *metautil.MetaWriter, g glue.Glue, store kv.S
newestMeta := meta.NewSnapshotMeta(store.GetSnapshot(kv.NewVersion(version.Ver)))
allJobs := make([]*model.Job, 0)
err = g.UseOneShotSession(store, !needDomain, func(se glue.Session) error {
allJobs, err = ddl.GetAllDDLJobs(se.GetSessionCtx(), newestMeta)
allJobs, err = ddl.GetAllDDLJobs(se.GetSessionCtx())
if err != nil {
return errors.Trace(err)
}
Expand Down
10 changes: 1 addition & 9 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -525,15 +525,7 @@
"executor/internal/": "executor/internal/",
"types/json_binary_functions.go": "types/json_binary_functions.go",
"types/json_binary_test.go": "types/json_binary_test.go",
"ddl/backfilling.go": "ddl/backfilling.go",
"ddl/column.go": "ddl/column.go",
"ddl/index.go": "ddl/index.go",
"ddl/ttl.go": "ddl/ttl.go",
"ddl/ttl_test.go": "ddl/ttl_test.go",
"ddl/job_table.go": "ddl/job_table.go",
"ddl/ingest/": "ddl/ingest/",
"ddl/internal/": "ddl/internal/",
"ddl/syncer/": "ddl/syncer/",
"ddl/": "ddl",
"expression/builtin_cast.go": "expression/builtin_cast code",
"server/conn.go": "server/conn.go",
"server/conn_stmt.go": "server/conn_stmt.go",
Expand Down
6 changes: 3 additions & 3 deletions ddl/backfilling_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func initSessCtx(sessCtx sessionctx.Context, sqlMode mysql.SQLMode, tzLocation *
return nil
}

func (b *txnBackfillScheduler) expectedWorkerSize() (size int) {
func (*txnBackfillScheduler) expectedWorkerSize() (size int) {
workerCnt := int(variable.GetDDLReorgWorkerCounter())
return mathutil.Min(workerCnt, maxBackfillWorkerSize)
}
Expand Down Expand Up @@ -438,7 +438,7 @@ func (b *ingestBackfillScheduler) createCopReqSenderPool() (*copReqSenderPool, e
return newCopReqSenderPool(b.ctx, copCtx, sessCtx.GetStore(), b.taskCh, b.sessPool, b.checkpointMgr), nil
}

func (b *ingestBackfillScheduler) expectedWorkerSize() (readerSize int, writerSize int) {
func (*ingestBackfillScheduler) expectedWorkerSize() (readerSize int, writerSize int) {
workerCnt := int(variable.GetDDLReorgWorkerCounter())
readerSize = mathutil.Min(workerCnt/2, maxBackfillWorkerSize)
readerSize = mathutil.Max(readerSize, 1)
Expand Down Expand Up @@ -495,7 +495,7 @@ func (w *addIndexIngestWorker) HandleTask(rs idxRecResult) {
w.resultCh <- result
}

func (w *addIndexIngestWorker) Close() {}
func (*addIndexIngestWorker) Close() {}

type taskIDAllocator struct {
id int
Expand Down
14 changes: 7 additions & 7 deletions ddl/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func (*BaseCallback) OnChanged(err error) error {
}

// OnSchemaStateChanged implements Callback interface.
func (*BaseCallback) OnSchemaStateChanged(schemaVer int64) {
func (*BaseCallback) OnSchemaStateChanged(_ int64) {
// Nothing to do.
}

Expand All @@ -88,22 +88,22 @@ func (*BaseCallback) OnJobRunAfter(_ *model.Job) {
}

// OnJobUpdated implements Callback.OnJobUpdated interface.
func (*BaseCallback) OnJobUpdated(job *model.Job) {
func (*BaseCallback) OnJobUpdated(_ *model.Job) {
// Nothing to do.
}

// OnWatched implements Callback.OnWatched interface.
func (*BaseCallback) OnWatched(ctx context.Context) {
func (*BaseCallback) OnWatched(_ context.Context) {
// Nothing to do.
}

// OnGetJobBefore implements Callback.OnGetJobBefore interface.
func (c *BaseCallback) OnGetJobBefore(jobType string) {
func (*BaseCallback) OnGetJobBefore(_ string) {
// Nothing to do.
}

// OnGetJobAfter implements Callback.OnGetJobAfter interface.
func (c *BaseCallback) OnGetJobAfter(jobType string, job *model.Job) {
func (*BaseCallback) OnGetJobAfter(_ string, _ *model.Job) {
// Nothing to do.
}

Expand Down Expand Up @@ -136,7 +136,7 @@ func (c *DefaultCallback) OnChanged(err error) error {
}

// OnSchemaStateChanged overrides the ddl Callback interface.
func (c *DefaultCallback) OnSchemaStateChanged(schemaVer int64) {
func (c *DefaultCallback) OnSchemaStateChanged(_ int64) {
err := c.do.Reload()
if err != nil {
logutil.BgLogger().Error("domain callback failed on schema state changed", zap.Error(err))
Expand Down Expand Up @@ -173,7 +173,7 @@ func (c *ctcCallback) OnChanged(err error) error {
}

// OnSchemaStateChanged overrides the ddl Callback interface.
func (c *ctcCallback) OnSchemaStateChanged(retVer int64) {
func (c *ctcCallback) OnSchemaStateChanged(_ int64) {
err := c.do.Reload()
if err != nil {
logutil.BgLogger().Error("domain callback failed on schema state changed", zap.Error(err))
Expand Down
9 changes: 4 additions & 5 deletions ddl/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func ValidateFlashbackTS(ctx context.Context, sctx sessionctx.Context, flashBack
select {
case <-ticker.C:
minSafeTime = getStoreGlobalMinSafeTS(sctx.GetStore())
break
case <-ctx.Done():
return ctx.Err()
}
Expand Down Expand Up @@ -209,11 +208,11 @@ func checkSystemSchemaID(t *meta.Meta, schemaID int64, flashbackTSString string)
if schemaID <= 0 {
return nil
}
DBInfo, err := t.GetDatabase(schemaID)
if err != nil || DBInfo == nil {
dbInfo, err := t.GetDatabase(schemaID)
if err != nil || dbInfo == nil {
return errors.Trace(err)
}
if filter.IsSystemSchema(DBInfo.Name.L) {
if filter.IsSystemSchema(dbInfo.Name.L) {
return errors.Errorf("Detected modified system table during [%s, now), can't do flashback", flashbackTSString)
}
return nil
Expand Down Expand Up @@ -296,7 +295,7 @@ func checkAndSetFlashbackClusterInfo(se sessionctx.Context, d *ddlCtx, t *meta.M
}
}

jobs, err := GetAllDDLJobs(se, t)
jobs, err := GetAllDDLJobs(se)
if err != nil {
return errors.Trace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion ddl/column.go
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ func doReorgWorkForModifyColumn(w *worker, d *ddlCtx, t *meta.Meta, job *model.J
// enable: curl -X PUT -d "pause" "http://127.0.0.1:10080/fail/github.com/pingcap/tidb/ddl/mockDelayInModifyColumnTypeWithData".
// disable: curl -X DELETE "http://127.0.0.1:10080/fail/github.com/pingcap/tidb/ddl/mockDelayInModifyColumnTypeWithData"
failpoint.Inject("mockDelayInModifyColumnTypeWithData", func() {})
err = w.runReorgJob(rh, reorgInfo, tbl.Meta(), d.lease, func() (addIndexErr error) {
err = w.runReorgJob(reorgInfo, tbl.Meta(), d.lease, func() (addIndexErr error) {
defer util.Recover(metrics.LabelDDL, "onModifyColumn",
func() {
addIndexErr = dbterror.ErrCancelledDDLJob.GenWithStack("modify table `%v` column `%v` panic", tbl.Meta().Name, oldCol.Name)
Expand Down
9 changes: 2 additions & 7 deletions ddl/db_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/parser"
"github.com/pingcap/tidb/parser/ast"
"github.com/pingcap/tidb/parser/model"
Expand Down Expand Up @@ -1337,9 +1336,7 @@ func prepareTestControlParallelExecSQL(t *testing.T, store kv.Storage, dom *doma
sess := testkit.NewTestKit(t, store).Session()
err := sessiontxn.NewTxn(context.Background(), sess)
require.NoError(t, err)
txn, err := sess.Txn(true)
require.NoError(t, err)
jobs, err := ddl.GetAllDDLJobs(sess, meta.NewMeta(txn))
jobs, err := ddl.GetAllDDLJobs(sess)
require.NoError(t, err)
qLen = len(jobs)
if qLen == 2 {
Expand All @@ -1366,9 +1363,7 @@ func prepareTestControlParallelExecSQL(t *testing.T, store kv.Storage, dom *doma
sess := testkit.NewTestKit(t, store).Session()
err := sessiontxn.NewTxn(context.Background(), sess)
require.NoError(t, err)
txn, err := sess.Txn(true)
require.NoError(t, err)
jobs, err := ddl.GetAllDDLJobs(sess, meta.NewMeta(txn))
jobs, err := ddl.GetAllDDLJobs(sess)
require.NoError(t, err)
qLen = len(jobs)
if qLen == 1 {
Expand Down
20 changes: 10 additions & 10 deletions ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ type DDL interface {
UnlockTables(ctx sessionctx.Context, lockedTables []model.TableLockTpInfo) error
CleanupTableLock(ctx sessionctx.Context, tables []*ast.TableName) error
UpdateTableReplicaInfo(ctx sessionctx.Context, physicalID int64, available bool) error
RepairTable(ctx sessionctx.Context, table *ast.TableName, createStmt *ast.CreateTableStmt) error
RepairTable(ctx sessionctx.Context, createStmt *ast.CreateTableStmt) error
CreateSequence(ctx sessionctx.Context, stmt *ast.CreateSequenceStmt) error
DropSequence(ctx sessionctx.Context, stmt *ast.DropSequenceStmt) (err error)
AlterSequence(ctx sessionctx.Context, stmt *ast.AlterSequenceStmt) error
Expand Down Expand Up @@ -1440,7 +1440,7 @@ func get2JobsFromTable(sess *sess.Session) (*model.Job, *model.Job, error) {
}

// cancelRunningJob cancel a DDL job that is in the concurrent state.
func cancelRunningJob(sess *sess.Session, job *model.Job,
func cancelRunningJob(_ *sess.Session, job *model.Job,
byWho model.AdminCommandOperator) (err error) {
// These states can't be cancelled.
if job.IsDone() || job.IsSynced() {
Expand All @@ -1461,7 +1461,7 @@ func cancelRunningJob(sess *sess.Session, job *model.Job,
}

// pauseRunningJob check and pause the running Job
func pauseRunningJob(sess *sess.Session, job *model.Job,
func pauseRunningJob(_ *sess.Session, job *model.Job,
byWho model.AdminCommandOperator) (err error) {
if job.IsPausing() || job.IsPaused() {
return dbterror.ErrPausedDDLJob.GenWithStackByArgs(job.ID)
Expand All @@ -1480,7 +1480,7 @@ func pauseRunningJob(sess *sess.Session, job *model.Job,
}

// resumePausedJob check and resume the Paused Job
func resumePausedJob(se *sess.Session, job *model.Job,
func resumePausedJob(_ *sess.Session, job *model.Job,
byWho model.AdminCommandOperator) (err error) {
if !job.IsResumable() {
errMsg := fmt.Sprintf("job has not been paused, job state:%s, schema state:%s",
Expand Down Expand Up @@ -1516,7 +1516,7 @@ func processJobs(process func(*sess.Session, *model.Job, model.AdminCommandOpera

ns := sess.NewSession(sessCtx)
// We should process (and try) all the jobs in one Transaction.
for tryN := uint(0); tryN < 3; tryN += 1 {
for tryN := uint(0); tryN < 3; tryN++ {
jobErrs = make([]error, len(ids))
// Need to figure out which one could not be paused
jobMap := make(map[int64]int, len(ids))
Expand Down Expand Up @@ -1622,9 +1622,9 @@ func processAllJobs(process func(*sess.Session, *model.Job, model.AdminCommandOp
return nil, err
}

var jobID int64 = 0
var jobIDMax int64 = 0
var limit int = 100
var jobID int64
var jobIDMax int64
var limit = 100
for {
var jobs []*model.Job
jobs, err = getJobsBySQL(ns, JobTable,
Expand Down Expand Up @@ -1681,7 +1681,7 @@ func ResumeAllJobsBySystem(se sessionctx.Context) (map[int64]error, error) {
}

// GetAllDDLJobs get all DDL jobs and sorts jobs by job.ID.
func GetAllDDLJobs(se sessionctx.Context, t *meta.Meta) ([]*model.Job, error) {
func GetAllDDLJobs(se sessionctx.Context) ([]*model.Job, error) {
return getJobsBySQL(sess.NewSession(se), JobTable, "1 order by job_id")
}

Expand Down Expand Up @@ -1723,7 +1723,7 @@ func IterHistoryDDLJobs(txn kv.Transaction, finishFn func([]*model.Job) (bool, e
// IterAllDDLJobs will iterates running DDL jobs first, return directly if `finishFn` return true or error,
// then iterates history DDL jobs until the `finishFn` return true or error.
func IterAllDDLJobs(ctx sessionctx.Context, txn kv.Transaction, finishFn func([]*model.Job) (bool, error)) error {
jobs, err := GetAllDDLJobs(ctx, meta.NewMeta(txn))
jobs, err := GetAllDDLJobs(ctx)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit ffea45b

Please sign in to comment.