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

expression: refactor expression pkg's warning and note generation logic #49686

Conversation

AilinKid
Copy link
Contributor

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 Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 21, 2023
Copy link

tiprow bot commented Dec 21, 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.

@AilinKid
Copy link
Contributor Author

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Dec 21, 2023
Copy link

codecov bot commented Dec 21, 2023

Codecov Report

Merging #49686 (80e6ec1) into master (d84df2b) will increase coverage by 0.4478%.
Report is 30 commits behind head on master.
The diff coverage is 37.0370%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49686        +/-   ##
================================================
+ Coverage   71.0024%   71.4503%   +0.4478%     
================================================
  Files          1368       1424        +56     
  Lines        399178     422789     +23611     
================================================
+ Hits         283426     302084     +18658     
- Misses        95967     101781      +5814     
+ Partials      19785      18924       -861     
Flag Coverage Δ
integration 43.6731% <37.0370%> (?)
unit 71.0025% <ø> (+0.0001%) ⬆️

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

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

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Dec 21, 2023
Copy link

ti-chi-bot bot commented Dec 22, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: 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 approved lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 22, 2023
Copy link

ti-chi-bot bot commented Dec 22, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-21 13:30:19.980468393 +0000 UTC m=+1140511.017695322: ☑️ agreed by qw4990.
  • 2023-12-22 06:07:53.527701519 +0000 UTC m=+1200364.564928449: ☑️ agreed by XuHuaiyu.

@ti-chi-bot ti-chi-bot bot merged commit 82a011f into pingcap:master Dec 22, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/M Denotes a PR that changes 30-99 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
3 participants