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

*: add preparedStmt metric and add limit to max prepareStmt #8405

Merged
merged 7 commits into from Nov 28, 2018

Conversation

Projects
None yet
5 participants
@lysu
Member

lysu commented Nov 22, 2018

What problem does this PR solve?

fixes #8133

prepared statement should be prepare once and reuse in later execution and close them when no need them.

we need find and protect wrong prepare stmt usage, so this PR:

and we support -1 value for max_prepared_stmt_count that disable limit.

What is changed and how it works?

  • wrap up session.sessionVars.PreparedStmts operation
  • maintain global preparedStmtCount when prepare, dealloc, session exit [HIGH RISK]
  • update metric gauge
  • support set global variable

Check List

Tests

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

Code changes

  • Has exported function/method change
  • Has exported variable/fields change
  • Has persistent data change

Side effects

  • Increased code complexity

Related changes

  • Need to update the documentation
  • Need to be included in the release note

Risk

  • make sure preparedStmtCount is right, during retry, connection exception close and so on
  • default value that doesn't hurt user when preparedStmtCount have some wrong

This change is Reviewable

@lysu lysu force-pushed the lysu:max_prepared_stmt_count branch 2 times, most recently from 8cbf95e to 8d12cb7 Nov 26, 2018

@lysu

This comment has been minimized.

Member

lysu commented Nov 26, 2018

/run-all-tests

@winoros

This comment has been minimized.

Member

winoros commented Nov 26, 2018

I modified your description to add link to #8133

@lysu

This comment has been minimized.

Member

lysu commented Nov 26, 2018

/run-all-tests

@lysu lysu force-pushed the lysu:max_prepared_stmt_count branch from 27b249d to fbdc1bc Nov 27, 2018

@lysu

This comment has been minimized.

Member

lysu commented Nov 27, 2018

/run-all-tests

@lysu

This comment has been minimized.

Member

lysu commented Nov 27, 2018

/run-common-test
/run-integration-common-test

@lysu

This comment has been minimized.

Member

lysu commented Nov 27, 2018

/run-all-tests

@hhxcc

This comment has been minimized.

Contributor

hhxcc commented Nov 27, 2018

@lysu mysql protocol also can be use to close prepare stmt , I think ComStmtClose use a different way to close the prepare stmt .

@lysu lysu force-pushed the lysu:max_prepared_stmt_count branch from 2f49274 to 8db3287 Nov 28, 2018

@lysu

This comment has been minimized.

Member

lysu commented Nov 28, 2018

@hhxcc yes, most database sdk use binary protocol and comStmtClose way, and some cli will use text protocol comQuery deallocate execute stmtX.

the tricks in current tidb for this is there two impl to them, comStmtClose way more complex than comQuery deallocate, because it take transaction retry logic, stmtClose during transaction will delay to retry finished(session#cleanRetryInfo)

but, both comStmtClose and comQuery deallocate will need add/remove session#PreparedStmts, so this PR encapsulate it and covery both entry.

@lysu

This comment has been minimized.

Member

lysu commented Nov 28, 2018

@lysu lysu force-pushed the lysu:max_prepared_stmt_count branch from 8db3287 to 3dd0f57 Nov 28, 2018

@lysu

This comment has been minimized.

Member

lysu commented Nov 28, 2018

/run-all-tests

@lysu

This comment has been minimized.

Member

lysu commented Nov 28, 2018

/run-integration-common-test

@zz-jason

LGTM

@zz-jason zz-jason merged commit e7e31fa into pingcap:master Nov 28, 2018

4 checks passed

ci/circleci Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
jenkins-ci-tidb/build Jenkins job succeeded.
Details
license/cla Contributor License Agreement is signed.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment