From 7c5e7ea85118ded506705f129a2cb883dbeb454b Mon Sep 17 00:00:00 2001 From: Weizhen Wang Date: Wed, 26 Apr 2023 13:53:52 +0800 Subject: [PATCH] linter: enable revive for session (#43420) ref pingcap/tidb#40786 --- build/nogo_config.json | 1 + session/bootstrap.go | 2 +- session/session.go | 17 +++++++++-------- session/tidb.go | 2 +- session/txn.go | 3 +-- session/txninfo/summary.go | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/build/nogo_config.json b/build/nogo_config.json index 7b8b318e00aa2..4eca1b2433d33 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -500,6 +500,7 @@ "dumpling/export": "dumpling/export code", "lock/": "lock file", "errno/": "errno code", + "session/": "session code", "structure/": "structure code", "telemetry/": "telemetry code", "parser/": "parser code", diff --git a/session/bootstrap.go b/session/bootstrap.go index 454719f0241c2..769425e4f6c76 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -2430,7 +2430,7 @@ func upgradeToVer136(s Session, ver int64) { doReentrantDDL(s, fmt.Sprintf("ALTER TABLE mysql.%s ADD INDEX idx_task_key(task_key)", ddl.BackgroundSubtaskTable), dbterror.ErrDupKeyName) } -func upgradeToVer137(s Session, ver int64) { +func upgradeToVer137(_ Session, _ int64) { // NOOP, we don't depend on ddl to init the default group due to backward compatible issue. } diff --git a/session/session.go b/session/session.go index 4bb1f2525c955..8f69d33e60468 100644 --- a/session/session.go +++ b/session/session.go @@ -720,7 +720,7 @@ func (c *cachedTableRenewLease) start(ctx context.Context) error { return err } -func (c *cachedTableRenewLease) stop(ctx context.Context) { +func (c *cachedTableRenewLease) stop(_ context.Context) { close(c.exit) } @@ -1152,7 +1152,7 @@ func (s *session) isInternal() bool { return s.sessionVars.InRestrictedSQL } -func (s *session) isTxnRetryableError(err error) bool { +func (*session) isTxnRetryableError(err error) bool { if atomic.LoadUint32(&SchemaChangedWithoutRetry) == 1 { return kv.IsTxnRetryableError(err) } @@ -2395,7 +2395,7 @@ func runStmt(ctx context.Context, se *session, s sqlexec.Statement) (rs sqlexec. type ExecStmtVarKeyType int // String defines a Stringer function for debugging and pretty printing. -func (k ExecStmtVarKeyType) String() string { +func (ExecStmtVarKeyType) String() string { return "exec_stmt_var_key" } @@ -2977,7 +2977,7 @@ func (s *session) AuthWithoutVerification(user *auth.UserIdentity) bool { } // RefreshVars implements the sessionctx.Context interface. -func (s *session) RefreshVars(ctx context.Context) error { +func (s *session) RefreshVars(_ context.Context) error { pruneMode, err := s.GetSessionVars().GlobalVarsAccessor.GetGlobalSysVar(variable.TiDBPartitionPruneMode) if err != nil { return err @@ -3800,8 +3800,7 @@ func (s *session) ShowProcess() *util.ProcessInfo { } // GetStartTSFromSession returns the startTS in the session `se` -func GetStartTSFromSession(se interface{}) (uint64, uint64) { - var startTS, processInfoID uint64 +func GetStartTSFromSession(se interface{}) (startTS, processInfoID uint64) { tmp, ok := se.(*session) if !ok { logutil.BgLogger().Error("GetStartTSFromSession failed, can't transform to session struct") @@ -4174,7 +4173,8 @@ func (s *session) SetMemoryFootprintChangeHook() { } // EncodeSessionStates implements SessionStatesHandler.EncodeSessionStates interface. -func (s *session) EncodeSessionStates(ctx context.Context, sctx sessionctx.Context, sessionStates *sessionstates.SessionStates) error { +func (s *session) EncodeSessionStates(ctx context.Context, + _ sessionctx.Context, sessionStates *sessionstates.SessionStates) error { // Transaction status is hard to encode, so we do not support it. s.txn.mu.Lock() valid := s.txn.Valid() @@ -4242,7 +4242,8 @@ func (s *session) EncodeSessionStates(ctx context.Context, sctx sessionctx.Conte } // DecodeSessionStates implements SessionStatesHandler.DecodeSessionStates interface. -func (s *session) DecodeSessionStates(ctx context.Context, sctx sessionctx.Context, sessionStates *sessionstates.SessionStates) error { +func (s *session) DecodeSessionStates(ctx context.Context, + _ sessionctx.Context, sessionStates *sessionstates.SessionStates) error { // Decode prepared statements and sql bindings. for _, handler := range s.sessionStatesHandlers { if err := handler.DecodeSessionStates(ctx, s, sessionStates); err != nil { diff --git a/session/tidb.go b/session/tidb.go index 310d76e007e5a..40ff4d647d2e6 100644 --- a/session/tidb.go +++ b/session/tidb.go @@ -339,7 +339,7 @@ func GetHistory(ctx sessionctx.Context) *StmtHistory { } // GetRows4Test gets all the rows from a RecordSet, only used for test. -func GetRows4Test(ctx context.Context, sctx sessionctx.Context, rs sqlexec.RecordSet) ([]chunk.Row, error) { +func GetRows4Test(ctx context.Context, _ sessionctx.Context, rs sqlexec.RecordSet) ([]chunk.Row, error) { if rs == nil { return nil, nil } diff --git a/session/txn.go b/session/txn.go index 768fc3d376c8a..5f2a427fb89fe 100644 --- a/session/txn.go +++ b/session/txn.go @@ -258,8 +258,7 @@ func (txn *LazyTxn) GoString() string { // GetOption implements the GetOption func (txn *LazyTxn) GetOption(opt int) interface{} { if txn.Transaction == nil { - switch opt { - case kv.TxnScope: + if opt == kv.TxnScope { return "" } return nil diff --git a/session/txninfo/summary.go b/session/txninfo/summary.go index f1ddec8457e78..30058c1d87e88 100644 --- a/session/txninfo/summary.go +++ b/session/txninfo/summary.go @@ -159,4 +159,4 @@ func (recorder *TrxHistoryRecorder) ResizeSummaries(capacity uint) { } // Recorder is the recorder instance. -var Recorder TrxHistoryRecorder = newTrxHistoryRecorder(0) +var Recorder = newTrxHistoryRecorder(0)