Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: refactor executor pkg's warning and note generation #49600

Conversation

AilinKid
Copy link
Contributor

@AilinKid AilinKid commented Dec 20, 2023

What problem does this PR solve?

Issue Number: close #49291

Problem Summary:

What changed and how does it work?

  • if a error is only generated and used like warning and note, don't bind unnecessary stack info with it. Because showExec (show warning logic) only fetch errCode and errMsg to show.
  • if a error is generated in deep call chain, by now, always generating it with stack, because you couldn't know whether it will be used like error/warning/note later and outer.
  • if a error is treated several ways according sqlMode/var/hint/ticker and some thing, eg: like the code below, the error can be possibly treated like an error, we couldn't control generating logic with it.
  • if this error is generated in current level, like the second case below, generating it without stack info, and wrapping stack with it when warn is returned like error, because of stack info is quite same.
if err != nil {
    // deep call chain for generation of ERROR here.
    stmtCtx.IsSyncStatsFailed = true
    if variable.StatsLoadPseudoTimeout.Load() {
	logutil.BgLogger().Warn("SyncWaitStatsLoad failed", zap.Error(err))
        // treated like warning
	stmtCtx.AppendWarning(err)
	return nil
    }
    logutil.BgLogger().Error("SyncWaitStatsLoad failed", zap.Error(err))
    // treated like user error
    return err
}


if exists {
    err := infoschema.ErrTableExists.FastGenByArgs(ast.Ident{Schema: s.Table.Schema, Name: s.Table.Name})
    if s.IfNotExists {
  	e.Ctx().GetSessionVars().StmtCtx.AppendNote(err)
	return nil
    }
    return errors.Trace(err)
}
  • error's stack info will be useful, because it can be used to quickly locate where the error comes from.
func (cc *clientConn) Run(ctx context.Context) {
    // ...
    logutil.Logger(ctx).Info("command dispatched failed",
	zap.String("connInfo", cc.String()),
	zap.String("command", mysql.Command2Str[data[0]]),
	zap.String("status", cc.SessionStatusToString()),
	zap.Stringer("sql", getLastStmtInConn{cc}),
	zap.String("txn_mode", txnMode),
	zap.Uint64("timestamp", startTS),
	zap.String("err", errStrForLog(err, cc.ctx.GetSessionVars().EnableRedactLog)),  // fetch stack info here
}

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: AilinKid <314806019@qq.com>
@ti-chi-bot ti-chi-bot bot added release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 20, 2023
Copy link

tiprow bot commented Dec 20, 2023

Hi @AilinKid. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

codecov bot commented Dec 20, 2023

Codecov Report

Merging #49600 (aafa08f) into master (d84df2b) will increase coverage by 0.5371%.
Report is 20 commits behind head on master.
The diff coverage is 28.3333%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49600        +/-   ##
================================================
+ Coverage   71.0024%   71.5395%   +0.5371%     
================================================
  Files          1368       1423        +55     
  Lines        399178     418307     +19129     
================================================
+ Hits         283426     299255     +15829     
- Misses        95967     100243      +4276     
+ Partials      19785      18809       -976     
Flag Coverage Δ
integration 43.6026% <28.3333%> (?)
unit 71.0016% <ø> (-0.0008%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9663% <ø> (ø)
parser ∅ <ø> (∅)
br 47.3644% <ø> (-5.5178%) ⬇️

task.parentExec.Ctx().GetSessionVars().StmtCtx.AppendWarning(warn)
newErr := errors.Trace(warn)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference

Copy link
Contributor Author

@AilinKid AilinKid Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppendWarning(warn) will be stack free,and the returned error is still stack-bounded

Copy link
Contributor Author

@AilinKid AilinKid Dec 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from the stack info itself, the only difference is the come-out line number of deepest frame (change from L260 to L262 here)

Copy link

ti-chi-bot bot commented Dec 20, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-20 08:12:27.757502796 +0000 UTC m=+1035038.794729723: ☑️ agreed by qw4990.
  • 2023-12-20 09:00:21.382286872 +0000 UTC m=+1037912.419513784: ☑️ agreed by hawkingrei.

Copy link
Collaborator

@Benjamin2037 Benjamin2037 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

ti-chi-bot bot commented Dec 21, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Benjamin2037, hawkingrei, qw4990, XuHuaiyu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added the approved label Dec 21, 2023
@ti-chi-bot ti-chi-bot bot merged commit 7f9559c into pingcap:master Dec 21, 2023
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

planner: care to use errors.new and errors.errorf as your warnings and notes
5 participants