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

ddl, executor: add warning log for lock/unlock tables #29301

Merged
merged 8 commits into from
Nov 4, 2021

Conversation

Defined2014
Copy link
Contributor

What problem does this PR solve?

Issue Number: close #28967

Problem Summary: Add warning log for lock tables and unlock tables when enable-table-lock flag not enabled.

What is changed and how it works?

Check List

Tests

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

Release note

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 1, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • morgo
  • tangenta

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

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

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 1, 2021
@Defined2014
Copy link
Contributor Author

/cc @morgo
PTAL

@ti-chi-bot ti-chi-bot requested a review from morgo November 1, 2021 08:18
executor/ddl.go Outdated
Comment on lines 807 to 812
func (e *DDLExec) executeUnlockTables(_ *ast.UnlockTablesStmt) error {
if !config.TableLockEnabled() {
e.ctx.GetSessionVars().StmtCtx.AppendWarning(errors.Errorf("Unlock tables works only when enable-table-lock is set in config file"))
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of suggestions:

  1. We make the mode dependent on https://docs.pingcap.com/tidb/dev/system-variables#tidb_enable_noop_functions-new-in-v40 -- but it only ever returns warnings at most (since it's important DDL can restore). This provides a mechanism for users to kill the warning if that is problematic for their script.
  2. We add a new error number / error code. This helps us track the errors in information schema so we know which unsupported syntax the user is encountering.

Let me know what you think about either. These are just suggestions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Sounds good for me.
  2. Maybe we can use mysql.ErrNotSupportedYet with different error message between ErrFunctionsNoopImpl.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me.

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,PTAL @morgo

@ti-chi-bot ti-chi-bot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 2, 2021
executor/ddl.go Outdated
Comment on lines 797 to 796
if noopFuncsMode == variable.OffInt {
return err
} else if noopFuncsMode == variable.WarnInt {
e.ctx.GetSessionVars().StmtCtx.AppendWarning(err)
}
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, for this syntax I think we can only WARN at most. I know this is different from most other noop functions, but this syntax is used by mysqldump. If we generate an error, mysqldump files won't restore by default :(

Copy link
Contributor Author

@Defined2014 Defined2014 Nov 3, 2021

Choose a reason for hiding this comment

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

The behavior will be very strange. If we only have WARN, I think use TableLockEnabled() to control it is better than noopFuncsMode . What's your opinion? @morgo

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree it is strange, but the change is too severe if mysqldump can not be restored.

For the docs: https://docs.pingcap.com/tidb/dev/system-variables#tidb_enable_noop_functions-new-in-v40

We can add a sentence: Setting tidb_enable_noop_functions to OFF does not prevent LOCK TABLE t1 WRITE from executing. A warning is returned instead. This behavior is required for compatibility with mysqldump.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, PTAL @morgo

@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 3, 2021
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 4, 2021
@@ -64,6 +64,7 @@ var (
ErrNotSupportedWithSem = dbterror.ClassOptimizer.NewStd(mysql.ErrNotSupportedWithSem)
ErrPluginIsNotLoaded = dbterror.ClassExecutor.NewStd(mysql.ErrPluginIsNotLoaded)
ErrSetPasswordAuthPlugin = dbterror.ClassExecutor.NewStd(mysql.ErrSetPasswordAuthPlugin)
ErrFuncNotEnabled = dbterror.ClassExecutor.NewStdErr(mysql.ErrNotSupportedYet, parser_mysql.Message("%-.32s works only when %-.32s is set in config file", nil))
Copy link
Contributor

@morgo morgo Nov 4, 2021

Choose a reason for hiding this comment

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

The warning is not clear that the behavior is a noop. This distinction is important in understanding the risks. May I suggest instead:

LOCK TABLE is not supported. To enable this experimental feature, set 'enable-table-lock' in the configuration file.

Otherwise LGTM. I think it is too confusing to say that it is also affected by tidb_enable_noop_funcs = ON, so we can handle that in docs.

Copy link
Contributor Author

@Defined2014 Defined2014 Nov 4, 2021

Choose a reason for hiding this comment

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

Yes, it's too confusing. I think we should return warning whether noop_funcs enabled or not. Maybe controlled by enable-table-lock is enough. @morgo

Copy link
Contributor Author

@Defined2014 Defined2014 Nov 4, 2021

Choose a reason for hiding this comment

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

Modified. @morgo

@AilinKid PTAL

@Defined2014
Copy link
Contributor Author

/cc @AilinKid

@ti-chi-bot ti-chi-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 4, 2021
@morgo morgo self-requested a review November 4, 2021 04:19
Copy link
Contributor

@morgo morgo left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for making edits!

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 4, 2021
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 4, 2021
@tangenta
Copy link
Contributor

tangenta commented Nov 4, 2021

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 18dd8d0

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 4, 2021
@winoros
Copy link
Member

winoros commented Nov 4, 2021

/run-cherry-picker

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Nov 4, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.3 in PR #29437

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Nov 4, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.1 in PR #29439

ti-srebot pushed a commit to ti-srebot/tidb that referenced this pull request Nov 4, 2021
Signed-off-by: ti-srebot <ti-srebot@pingcap.com>
@ti-srebot
Copy link
Contributor

cherry pick to release-5.2 in PR #29440

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-cherry-pick-release-5.1 needs-cherry-pick-release-5.2 needs-cherry-pick-release-5.3 Type: Need cherry pick to release-5.3 release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LOCK TABLE T1 write; does not raise error or warning
7 participants