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

conn: fix lost connection when insert from select panic cause by out of memory quota #12090

Merged
merged 8 commits into from
Sep 10, 2019

Conversation

crazycs520
Copy link
Contributor

What problem does this PR solve?

Set oom-action = "cancel" in the tidb config file.

drop table if exists t,t1;
create table t (a bigint);
create table t1 (a bigint);
insert into t1 values (1),(2),(3),(4),(5);
set @@tidb_mem_quota_query=200;
insert into t select a from t1 order by a desc;
ERROR 2013 (HY000): Lost connection to MySQL server during query

When insert ... select out of memory quota, TiDB should return error Out Of Memory Quota, instead of lost connection.

What is changed and how it works?

Check List

Tests

  • Unit test
  • Manual test (add detailed scripts or steps below)

Code changes

  • Has exported function/method change

Side effects

Related changes

  • Need to cherry-pick to the release branch

Release note

  • Fix the issue that lost connection when executing insert from select statement panic caused by out of memory quota.

@crazycs520
Copy link
Contributor Author

@zz-jason @tiancaiamao PTAL

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Sep 9, 2019
@codecov
Copy link

codecov bot commented Sep 9, 2019

Codecov Report

Merging #12090 into master will not change coverage.
The diff coverage is n/a.

@@             Coverage Diff             @@
##             master     #12090   +/-   ##
===========================================
  Coverage   81.6432%   81.6432%           
===========================================
  Files           449        449           
  Lines         96624      96624           
===========================================
  Hits          78887      78887           
  Misses        12169      12169           
  Partials       5568       5568

buf := make([]byte, 4096)
stackSize := runtime.Stack(buf, false)
buf = buf[:stackSize]
logutil.Logger(ctx).Error("execute sql panic", zap.String("sql", sql), zap.String("stack", string(buf)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer using zap.Stack() directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, done.

lonng
lonng previously approved these changes Sep 9, 2019
if r == nil {
return
}
if str, ok := r.(string); !ok || !strings.HasPrefix(str, memory.PanicMemoryExceed) {
Copy link
Member

Choose a reason for hiding this comment

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

I think a better place is ExecStmt.Exec() function, or ExecStmt.handleNoDelay() and ExecStmt.handlePessimisticSelectForUpdate() function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@tiancaiamao
Copy link
Contributor

/run-all-tests

@zyxbest
Copy link
Contributor

zyxbest commented Sep 10, 2019

/run-common-test

Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

@bb7133 bb7133 added status/LGT2 Indicates that a PR has LGTM 2. needs-cherry-pick-3.0 and removed status/LGT1 Indicates that a PR has LGTM 1. labels Sep 10, 2019
@winkyao
Copy link
Contributor

winkyao commented Sep 10, 2019

/rebuild

@crazycs520 crazycs520 merged commit 4ee517c into pingcap:master Sep 10, 2019
@sre-bot
Copy link
Contributor

sre-bot commented Sep 10, 2019

cherry pick to release-3.0 failed

@sre-bot
Copy link
Contributor

sre-bot commented Sep 10, 2019

cherry pick to release-2.1 failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants