Skip to content

Commit

Permalink
*: support predeclared golangci-lint linter (pingcap#32066)
Browse files Browse the repository at this point in the history
  • Loading branch information
wangggong authored Feb 14, 2022
1 parent aa24b9a commit 7c56706
Show file tree
Hide file tree
Showing 32 changed files with 197 additions and 197 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ linters:
- makezero
- durationcheck
- prealloc
- predeclared

linters-settings:
staticcheck:
Expand Down
6 changes: 3 additions & 3 deletions br/pkg/backup/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func (r responseAndStore) GetStore() *metapb.Store {
}

// newPushDown creates a push down backup.
func newPushDown(mgr ClientMgr, cap int) *pushDown {
func newPushDown(mgr ClientMgr, capacity int) *pushDown {
return &pushDown{
mgr: mgr,
respCh: make(chan responseAndStore, cap),
errCh: make(chan error, cap),
respCh: make(chan responseAndStore, capacity),
errCh: make(chan error, capacity),
}
}

Expand Down
6 changes: 3 additions & 3 deletions br/pkg/conn/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ func (p *Pool) Get(ctx context.Context) (*grpc.ClientConn, error) {
}

// NewConnPool creates a new Pool by the specified conn factory function and capacity.
func NewConnPool(cap int, newConn func(ctx context.Context) (*grpc.ClientConn, error)) *Pool {
func NewConnPool(capacity int, newConn func(ctx context.Context) (*grpc.ClientConn, error)) *Pool {
return &Pool{
cap: cap,
conns: make([]*grpc.ClientConn, 0, cap),
cap: capacity,
conns: make([]*grpc.ClientConn, 0, capacity),
newConn: newConn,

mu: sync.Mutex{},
Expand Down
4 changes: 2 additions & 2 deletions br/pkg/lightning/backend/kv/sql2kv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func BenchmarkSQL2KV(b *testing.B) {
for i := 0; i < b.N; i++ {
rows, err := s.encoder.Encode(s.logger, s.row, 1, s.colPerm, "", 0)
require.NoError(b, err)
len := reflect.ValueOf(rows).Elem().Field(0).Len()
require.Equal(b, len, 2)
l := reflect.ValueOf(rows).Elem().Field(0).Len()
require.Equal(b, l, 2)
}
}
10 changes: 5 additions & 5 deletions br/pkg/lightning/backend/local/duplicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ type pendingIndexHandles struct {

// makePendingIndexHandlesWithCapacity makes the pendingIndexHandles struct-of-arrays with the given
// capacity for every internal array.
func makePendingIndexHandlesWithCapacity(cap int) pendingIndexHandles {
func makePendingIndexHandlesWithCapacity(capacity int) pendingIndexHandles {
return pendingIndexHandles{
dataConflictInfos: make([]errormanager.DataConflictInfo, 0, cap),
indexNames: make([]string, 0, cap),
handles: make([]tidbkv.Handle, 0, cap),
rawHandles: make([][]byte, 0, cap),
dataConflictInfos: make([]errormanager.DataConflictInfo, 0, capacity),
indexNames: make([]string, 0, capacity),
handles: make([]tidbkv.Handle, 0, capacity),
rawHandles: make([][]byte, 0, capacity),
}
}

Expand Down
6 changes: 3 additions & 3 deletions br/pkg/lightning/common/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ func (p *ConnPool) get(ctx context.Context) (*grpc.ClientConn, error) {
}

// NewConnPool creates a new connPool by the specified conn factory function and capacity.
func NewConnPool(cap int, newConn func(ctx context.Context) (*grpc.ClientConn, error)) *ConnPool {
func NewConnPool(capacity int, newConn func(ctx context.Context) (*grpc.ClientConn, error)) *ConnPool {
return &ConnPool{
cap: cap,
conns: make([]*grpc.ClientConn, 0, cap),
cap: capacity,
conns: make([]*grpc.ClientConn, 0, capacity),
newConn: newConn,

mu: sync.Mutex{},
Expand Down
8 changes: 4 additions & 4 deletions br/pkg/restore/split_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,10 @@ func (c *pdClient) getPDAPIAddr() string {
return strings.TrimRight(addr, "/")
}

func checkRegionEpoch(new, old *RegionInfo) bool {
return new.Region.GetId() == old.Region.GetId() &&
new.Region.GetRegionEpoch().GetVersion() == old.Region.GetRegionEpoch().GetVersion() &&
new.Region.GetRegionEpoch().GetConfVer() == old.Region.GetRegionEpoch().GetConfVer()
func checkRegionEpoch(_new, _old *RegionInfo) bool {
return _new.Region.GetId() == _old.Region.GetId() &&
_new.Region.GetRegionEpoch().GetVersion() == _old.Region.GetRegionEpoch().GetVersion() &&
_new.Region.GetRegionEpoch().GetConfVer() == _old.Region.GetRegionEpoch().GetConfVer()
}

// exponentialBackoffer trivially retry any errors it meets.
Expand Down
8 changes: 4 additions & 4 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1628,19 +1628,19 @@ func buildTableInfo(
return
}

func indexColumnsLen(cols []*model.ColumnInfo, idxCols []*model.IndexColumn) (len int, err error) {
func indexColumnsLen(cols []*model.ColumnInfo, idxCols []*model.IndexColumn) (colLen int, err error) {
for _, idxCol := range idxCols {
col := model.FindColumnInfo(cols, idxCol.Name.L)
if col == nil {
err = errKeyColumnDoesNotExits.GenWithStack("column does not exist: %s", idxCol.Name.L)
return
}
var colLen int
colLen, err = getIndexColumnLength(col, idxCol.Length)
var l int
l, err = getIndexColumnLength(col, idxCol.Length)
if err != nil {
return
}
len += colLen
colLen += l
}
return
}
Expand Down
8 changes: 4 additions & 4 deletions ddl/placement_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ func TestCreateSchemaWithPlacement(t *testing.T) {
}

func TestAlterDBPlacement(t *testing.T) {
store, close := testkit.CreateMockStore(t)
defer close()
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists TestAlterDB;")
tk.MustExec("create database TestAlterDB;")
Expand Down Expand Up @@ -650,8 +650,8 @@ func TestPlacementMode(t *testing.T) {
}

func TestPlacementTiflashCheck(t *testing.T) {
store, close := testkit.CreateMockStore(t)
defer close()
store, clean := testkit.CreateMockStore(t)
defer clean()
tk := testkit.NewTestKit(t, store)
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/infoschema/mockTiFlashStoreCount", `return(true)`))
defer func() {
Expand Down
4 changes: 2 additions & 2 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,9 @@ type sessionPool struct {
}
}

func newSessionPool(cap int, factory pools.Factory) *sessionPool {
func newSessionPool(capacity int, factory pools.Factory) *sessionPool {
return &sessionPool{
resources: make(chan pools.Resource, cap),
resources: make(chan pools.Resource, capacity),
factory: factory,
}
}
Expand Down
20 changes: 10 additions & 10 deletions executor/cte_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import (
)

func TestBasicCTE(t *testing.T) {
store, close := testkit.CreateMockStore(t)
defer close()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
Expand Down Expand Up @@ -76,8 +76,8 @@ func TestBasicCTE(t *testing.T) {
}

func TestUnionDistinct(t *testing.T) {
store, close := testkit.CreateMockStore(t)
defer close()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
Expand All @@ -103,8 +103,8 @@ func TestUnionDistinct(t *testing.T) {
}

func TestCTEMaxRecursionDepth(t *testing.T) {
store, close := testkit.CreateMockStore(t)
defer close()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
Expand Down Expand Up @@ -144,8 +144,8 @@ func TestCTEMaxRecursionDepth(t *testing.T) {
}

func TestCTEWithLimit(t *testing.T) {
store, close := testkit.CreateMockStore(t)
defer close()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
Expand Down Expand Up @@ -357,8 +357,8 @@ func TestSpillToDisk(t *testing.T) {
conf.OOMUseTmpStorage = true
})

store, close := testkit.CreateMockStore(t)
defer close()
store, clean := testkit.CreateMockStore(t)
defer clean()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test;")
Expand Down
11 changes: 5 additions & 6 deletions expression/builtin_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,17 +573,17 @@ func (b *builtinRandomBytesSig) Clone() builtinFunc {
// evalString evals RANDOM_BYTES(len).
// See https://dev.mysql.com/doc/refman/5.7/en/encryption-functions.html#function_random-bytes
func (b *builtinRandomBytesSig) evalString(row chunk.Row) (string, bool, error) {
len, isNull, err := b.args[0].EvalInt(b.ctx, row)
val, isNull, err := b.args[0].EvalInt(b.ctx, row)
if isNull || err != nil {
return "", true, err
}
if len < 1 || len > 1024 {
if val < 1 || val > 1024 {
return "", false, types.ErrOverflow.GenWithStackByArgs("length", "random_bytes")
}
buf := make([]byte, len)
buf := make([]byte, val)
if n, err := rand.Read(buf); err != nil {
return "", true, err
} else if int64(n) != len {
} else if int64(n) != val {
return "", false, errors.New("fail to generate random bytes")
}
return string(buf), false, nil
Expand Down Expand Up @@ -949,8 +949,7 @@ func (b *builtinUncompressedLengthSig) evalInt(row chunk.Row) (int64, bool, erro
sc.AppendWarning(errZlibZData)
return 0, false, nil
}
len := binary.LittleEndian.Uint32([]byte(payload)[0:4])
return int64(len), false, nil
return int64(binary.LittleEndian.Uint32([]byte(payload)[0:4])), false, nil
}

type validatePasswordStrengthFunctionClass struct {
Expand Down
10 changes: 5 additions & 5 deletions metrics/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ type CTEUsageCounter struct {

// Sub returns the difference of two counters.
func (c CTEUsageCounter) Sub(rhs CTEUsageCounter) CTEUsageCounter {
new := CTEUsageCounter{}
new.NonRecursiveCTEUsed = c.NonRecursiveCTEUsed - rhs.NonRecursiveCTEUsed
new.RecursiveUsed = c.RecursiveUsed - rhs.RecursiveUsed
new.NonCTEUsed = c.NonCTEUsed - rhs.NonCTEUsed
return new
return CTEUsageCounter{
NonRecursiveCTEUsed: c.NonRecursiveCTEUsed - rhs.NonRecursiveCTEUsed,
RecursiveUsed: c.RecursiveUsed - rhs.RecursiveUsed,
NonCTEUsed: c.NonCTEUsed - rhs.NonCTEUsed,
}
}

// GetCTECounter gets the TxnCommitCounter.
Expand Down
40 changes: 20 additions & 20 deletions planner/core/logical_plan_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -5025,9 +5025,9 @@ func IsDefaultExprSameColumn(names types.NameSlice, node ast.ExprNode) bool {
return false
}

func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (Plan, error) {
func (b *PlanBuilder) buildDelete(ctx context.Context, ds *ast.DeleteStmt) (Plan, error) {
b.pushSelectOffset(0)
b.pushTableHints(delete.TableHints, 0)
b.pushTableHints(ds.TableHints, 0)
defer func() {
b.popSelectOffset()
// table hints are only visible in the current DELETE statement.
Expand All @@ -5037,33 +5037,33 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (
b.inDeleteStmt = true
b.isForUpdateRead = true

if delete.With != nil {
if ds.With != nil {
l := len(b.outerCTEs)
defer func() {
b.outerCTEs = b.outerCTEs[:l]
}()
err := b.buildWith(ctx, delete.With)
err := b.buildWith(ctx, ds.With)
if err != nil {
return nil, err
}
}

p, err := b.buildResultSetNode(ctx, delete.TableRefs.TableRefs)
p, err := b.buildResultSetNode(ctx, ds.TableRefs.TableRefs)
if err != nil {
return nil, err
}
oldSchema := p.Schema()
oldLen := oldSchema.Len()

// For explicit column usage, should use the all-public columns.
if delete.Where != nil {
p, err = b.buildSelection(ctx, p, delete.Where, nil)
if ds.Where != nil {
p, err = b.buildSelection(ctx, p, ds.Where, nil)
if err != nil {
return nil, err
}
}
if b.ctx.GetSessionVars().TxnCtx.IsPessimistic {
if !delete.IsMultiTable {
if !ds.IsMultiTable {
p, err = b.buildSelectLock(p, &ast.SelectLockInfo{
LockType: ast.SelectLockForUpdate,
})
Expand All @@ -5073,22 +5073,22 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (
}
}

if delete.Order != nil {
p, err = b.buildSort(ctx, p, delete.Order.Items, nil, nil)
if ds.Order != nil {
p, err = b.buildSort(ctx, p, ds.Order.Items, nil, nil)
if err != nil {
return nil, err
}
}

if delete.Limit != nil {
p, err = b.buildLimit(p, delete.Limit)
if ds.Limit != nil {
p, err = b.buildLimit(p, ds.Limit)
if err != nil {
return nil, err
}
}

// If the delete is non-qualified it does not require Select Priv
if delete.Where == nil && delete.Order == nil {
if ds.Where == nil && ds.Order == nil {
b.popVisitInfo()
}
var authErr error
Expand Down Expand Up @@ -5116,7 +5116,7 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (
}

del := Delete{
IsMultiTable: delete.IsMultiTable,
IsMultiTable: ds.IsMultiTable,
}.Init(b.ctx)

del.names = p.OutputNames()
Expand All @@ -5131,12 +5131,12 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (
}

// Collect visitInfo.
if delete.Tables != nil {
if ds.Tables != nil {
// Delete a, b from a, b, c, d... add a and b.
updatableList := make(map[string]bool)
tbInfoList := make(map[string]*ast.TableName)
collectTableName(delete.TableRefs.TableRefs, &updatableList, &tbInfoList)
for _, tn := range delete.Tables.Tables {
collectTableName(ds.TableRefs.TableRefs, &updatableList, &tbInfoList)
for _, tn := range ds.Tables.Tables {
var canUpdate, foundMatch = false, false
name := tn.Name.L
if tn.Schema.L == "" {
Expand Down Expand Up @@ -5176,7 +5176,7 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (
} else {
// Delete from a, b, c, d.
var tableList []*ast.TableName
tableList = extractTableList(delete.TableRefs.TableRefs, tableList, false)
tableList = extractTableList(ds.TableRefs.TableRefs, tableList, false)
for _, v := range tableList {
if isCTE(v) {
return nil, ErrNonUpdatableTable.GenWithStackByArgs(v.Name.O, "DELETE")
Expand All @@ -5202,8 +5202,8 @@ func (b *PlanBuilder) buildDelete(ctx context.Context, delete *ast.DeleteStmt) (
// Table ID may not be unique for deleting multiple tables, for statements like
// `delete from t as t1, t as t2`, the same table has two alias, we have to identify a table
// by its alias instead of ID.
tblID2TableName := make(map[int64][]*ast.TableName, len(delete.Tables.Tables))
for _, tn := range delete.Tables.Tables {
tblID2TableName := make(map[int64][]*ast.TableName, len(ds.Tables.Tables))
for _, tn := range ds.Tables.Tables {
tblID2TableName[tn.TableInfo.ID] = append(tblID2TableName[tn.TableInfo.ID], tn)
}
tblID2Handle = del.cleanTblID2HandleMap(tblID2TableName, tblID2Handle, del.names)
Expand Down
2 changes: 1 addition & 1 deletion planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2811,7 +2811,7 @@ type columnsWithNames struct {
names types.NameSlice
}

func newColumnsWithNames(cap int) *columnsWithNames {
func newColumnsWithNames(c int) *columnsWithNames {
return &columnsWithNames{
cols: make([]*expression.Column, 0, 2),
names: make(types.NameSlice, 0, 2),
Expand Down
Loading

0 comments on commit 7c56706

Please sign in to comment.