Skip to content

Commit

Permalink
*: fix staticcheck errors in folder bindinfo, config, infoschema, met…
Browse files Browse the repository at this point in the history
…a and privilege (pingcap#13702)
  • Loading branch information
hsqlu authored and tiancaiamao committed Nov 26, 2019
1 parent 3f95d16 commit 2de2baa
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 33 deletions.
2 changes: 0 additions & 2 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/store/mockstore/mocktikv"
"github.com/pingcap/tidb/util/logutil"
"github.com/pingcap/tidb/util/mock"
"github.com/pingcap/tidb/util/testkit"
"github.com/pingcap/tidb/util/testleak"
dto "github.com/prometheus/client_model/go"
Expand All @@ -53,7 +52,6 @@ type testSuite struct {
store kv.Storage
domain *domain.Domain
*parser.Parser
ctx *mock.Context
}

var mockTikv = flag.Bool("mockTikv", true, "use mock tikv store in bind test")
Expand Down
11 changes: 5 additions & 6 deletions bindinfo/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,10 @@ func copyBindRecordUpdateMap(oldMap map[string]*bindRecordUpdate) map[string]*bi

func (c cache) getBindRecord(hash, normdOrigSQL, db string) *BindRecord {
bindRecords := c[hash]
if bindRecords != nil {
for _, bindRecord := range bindRecords {
if bindRecord.OriginalSQL == normdOrigSQL && bindRecord.Db == db {
return bindRecord
}

for _, bindRecord := range bindRecords {
if bindRecord.OriginalSQL == normdOrigSQL && bindRecord.Db == db {
return bindRecord
}
}
return nil
Expand Down Expand Up @@ -534,7 +533,7 @@ func (h *BindHandle) logicalDeleteBindInfoSQL(originalSQL, db string, updateTs t
return sql
}
for i, sql := range bindingSQLs {
bindingSQLs[i] = fmt.Sprintf(`%s`, expression.Quote(sql))
bindingSQLs[i] = expression.Quote(sql)
}
return sql + fmt.Sprintf(` and bind_sql in (%s)`, strings.Join(bindingSQLs, ","))
}
Expand Down
9 changes: 4 additions & 5 deletions bindinfo/session_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ func (h *SessionHandle) DropBindRecord(sctx sessionctx.Context, is infoschema.In
func (h *SessionHandle) GetBindRecord(normdOrigSQL, db string) *BindRecord {
hash := parser.DigestHash(normdOrigSQL)
bindRecords := h.ch[hash]
if bindRecords != nil {
for _, bindRecord := range bindRecords {
if bindRecord.OriginalSQL == normdOrigSQL && bindRecord.Db == db {
return bindRecord
}

for _, bindRecord := range bindRecords {
if bindRecord.OriginalSQL == normdOrigSQL && bindRecord.Db == db {
return bindRecord
}
}
return nil
Expand Down
7 changes: 3 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ func (b *nullableBool) UnmarshalJSON(data []byte) error {
if err = json.Unmarshal(data, &v); err != nil {
return err
}
switch v.(type) {
switch raw := v.(type) {
case bool:
*b = nullableBool{true, v.(bool)}
*b = nullableBool{true, raw}
default:
*b = nbUnset
}
Expand Down Expand Up @@ -635,10 +635,9 @@ func collectsDiff(i1, i2 interface{}, fieldPath string) map[string][]interface{}
// Load loads config options from a toml file.
func (c *Config) Load(confFile string) error {
metaData, err := toml.DecodeFile(confFile, c)
if c.TokenLimit <= 0 {
if c.TokenLimit == 0 {
c.TokenLimit = 1000
}

// If any items in confFile file are not mapped into the Config struct, issue
// an error and stop the server from starting.
undecoded := metaData.Undecoded()
Expand Down
5 changes: 1 addition & 4 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -2125,9 +2125,7 @@ func dataForClusterConfig(ctx sessionctx.Context) ([][]types.Datum, error) {
}
sort.Slice(results, func(i, j int) bool { return results[i].idx < results[j].idx })
for _, result := range results {
for _, row := range result.rows {
finalRows = append(finalRows, row)
}
finalRows = append(finalRows, result.rows...)
}
return finalRows, nil
}
Expand Down Expand Up @@ -2211,7 +2209,6 @@ func createInfoSchemaTable(_ autoid.Allocator, meta *model.TableInfo) (table.Tab
type infoschemaTable struct {
meta *model.TableInfo
cols []*table.Column
rows [][]types.Datum
}

// schemasSorter implements the sort.Interface interface, sorts DBInfo by name.
Expand Down
12 changes: 4 additions & 8 deletions meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ var (
)

var (

// ErrDBExists is the error for db exists.
ErrDBExists = terror.ClassMeta.New(codeDatabaseExists, "database already exists")
// ErrDBNotExists is the error for db not exists.
Expand Down Expand Up @@ -820,13 +819,10 @@ func (m *Meta) SetSchemaDiff(diff *model.SchemaDiff) error {

// meta error codes.
const (
codeInvalidTableKey terror.ErrCode = 1
codeInvalidDBKey = 2

codeDatabaseExists = 1007
codeDatabaseNotExists = 1049
codeTableExists = 1050
codeTableNotExists = 1146
codeDatabaseExists terror.ErrCode = 1007
codeDatabaseNotExists terror.ErrCode = 1049
codeTableExists terror.ErrCode = 1050
codeTableNotExists terror.ErrCode = 1146
)

func init() {
Expand Down
4 changes: 1 addition & 3 deletions privilege/privileges/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ type MySQLPrivilege struct {
// FindAllRole is used to find all roles grant to this user.
func (p *MySQLPrivilege) FindAllRole(activeRoles []*auth.RoleIdentity) []*auth.RoleIdentity {
queue, head := make([]*auth.RoleIdentity, 0, len(activeRoles)), 0
for _, r := range activeRoles {
queue = append(queue, r)
}
queue = append(queue, activeRoles...)
// Using breadth first search to find all roles grant to this user.
visited, ret := make(map[string]bool), make([]*auth.RoleIdentity, 0)
for head < len(queue) {
Expand Down
1 change: 0 additions & 1 deletion privilege/privileges/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var _ = Suite(&testCacheSuite{})

type testCacheSuite struct {
store kv.Storage
dbName string
domain *domain.Domain
}

Expand Down

0 comments on commit 2de2baa

Please sign in to comment.