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

planner: refactor planner module's warning and note generation logic (get rid of unnecessary stack info) #49390

Merged

Conversation

AilinKid
Copy link
Contributor

@AilinKid AilinKid commented Dec 12, 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.
  • 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, always generating stack info with it.
if err != nil {
    // generate 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
}
  • 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.

planner: refactor planner module's warning and note generation logic (get rid of unnecessary stack info)

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 12, 2023
Copy link

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

/retest-required

Copy link

tiprow bot commented Dec 12, 2023

@AilinKid: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/retest-required

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 12, 2023
@hawkingrei
Copy link
Member

/test all

Copy link

codecov bot commented Dec 12, 2023

Codecov Report

Merging #49390 (aba5dd1) into master (d076bc1) will increase coverage by 0.5874%.
The diff coverage is 54.0540%.

Additional details and impacted files
@@               Coverage Diff                @@
##             master     #49390        +/-   ##
================================================
+ Coverage   70.9870%   71.5744%   +0.5874%     
================================================
  Files          1368       1417        +49     
  Lines        399790     415257     +15467     
================================================
+ Hits         283799     297218     +13419     
- Misses        96179      99247      +3068     
+ Partials      19812      18792      -1020     
Flag Coverage Δ
integration 43.6103% <54.0540%> (?)
unit 70.9887% <ø> (+0.0016%) ⬆️

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

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

Copy link
Contributor

@fixdb fixdb left a comment

Choose a reason for hiding this comment

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

+1

@ti-chi-bot ti-chi-bot bot added approved needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 13, 2023
Copy link

ti-chi-bot bot commented Dec 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: fixdb, hawkingrei

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Dec 13, 2023
Copy link

ti-chi-bot bot commented Dec 13, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-12-13 01:48:32.692597241 +0000 UTC m=+407203.729824169: ☑️ agreed by fixdb.
  • 2023-12-13 04:28:35.449642275 +0000 UTC m=+416806.486869203: ☑️ agreed by hawkingrei.

@hawkingrei
Copy link
Member

/retest

.
Signed-off-by: AilinKid <[email protected]>
Signed-off-by: AilinKid <[email protected]>
Signed-off-by: AilinKid <[email protected]>
.
Signed-off-by: AilinKid <[email protected]>
.
Signed-off-by: AilinKid <[email protected]>
@AilinKid AilinKid force-pushed the refactor_planner_warning_and_note_appending branch from 6003784 to aba5dd1 Compare December 14, 2023 07:12
@ti-chi-bot ti-chi-bot bot merged commit 6aea95e into pingcap:master Dec 14, 2023
15 of 16 checks passed
AilinKid added a commit to AilinKid/tidb that referenced this pull request Dec 22, 2023
ti-chi-bot bot pushed a commit that referenced this pull request Dec 22, 2023
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 Denotes a PR that will be considered when it comes time to generate release notes. 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
3 participants