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

*: Improve errors for mutation checker #30434

Merged
merged 13 commits into from
Dec 17, 2021

Conversation

ekexium
Copy link
Contributor

@ekexium ekexium commented Dec 6, 2021

The PR is based on #30310

What problem does this PR solve?

Issue Number: ref #26833

Problem Summary:

  • add error codes
  • redact log

What is changed and how it works?

Check List

Tests

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

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

None

Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Dec 6, 2021

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • MyonKeminta
  • cfzjywxk

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/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 6, 2021
Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
@ekexium
Copy link
Contributor Author

ekexium commented Dec 6, 2021

/run-check_dev

executor/admin_test.go Outdated Show resolved Hide resolved
Signed-off-by: ekexium <ekexium@gmail.com>
@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Dec 7, 2021
@ekexium
Copy link
Contributor Author

ekexium commented Dec 7, 2021

/run-check_dev

@@ -295,6 +302,7 @@ func collectTableMutationsFromBufferStage(t *TableCommon, memBuffer kv.MemBuffer
// Returns error if the index data is not a subset of the input data.
func compareIndexData(
sc *stmtctx.StatementContext, cols []*table.Column, indexData, input []types.Datum, indexInfo *model.IndexInfo,
tableName string,
Copy link
Contributor

Choose a reason for hiding this comment

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

We could pass table info directly as something related to the table could be referenced in the future for example if we want to print out if it is partitioned table etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the name is the only info we need at present, and it's easy to change the signature in the future if needed.
Anyway I've made this change. There's no big difference

Signed-off-by: ekexium <ekexium@gmail.com>
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Dec 13, 2021
@cfzjywxk
Copy link
Contributor

@MyonKeminta PTAL

"inconsistent row mutation, row datum = {%v}, input datum = {%v}", decodedDatum.String(),
inputDatum.String(),
"inconsistent row mutation", zap.String("table", tableName),
logutil2.Redact(zap.String("decoded datum", decodedDatum.String())),
Copy link
Contributor

Choose a reason for hiding this comment

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

This Redact function looks like comes from BR and is not supposed to be used in code of TiDB's core. I thinks there should be another way to redact it..

Copy link
Contributor

Choose a reason for hiding this comment

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

And the table name should be redacted too

Copy link
Contributor Author

@ekexium ekexium Dec 15, 2021

Choose a reason for hiding this comment

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

This Redact function looks like comes from BR and is not supposed to be used in code of TiDB's core. I thinks there should be another way to redact it..

Totally agree. I think the problem is that BR and TiDB maintain their own logging utilities. Those in BR should be moved/merged to TiDB's, which should be another PR.
I tried but didn't find something convenient in TiDB for log redaction. If we want clean dependencies, I'm afraid we have to copy these utilities?

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you confirm if this function's behavior can be controlled by TiDB's configuration? Or can you try to print the error object you created instead, which seem to have built-in redacting?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you confirm if this function's behavior can be controlled by TiDB's configuration?

I think so. It's controlled by errors.RedactLogEnabled. I had a manual test.

Or can you try to print the error object you created instead, which seem to have built-in redacting?

Sounds like a good idea.

@@ -1009,6 +1009,9 @@ var MySQLErrName = map[uint16]*mysql.ErrMessage{
ErrInvalidIncrementAndOffset: mysql.Message("Invalid auto_increment settings: auto_increment_increment: %d, auto_increment_offset: %d, both of them must be in range [1..65535]", nil),
ErrDataInconsistentMismatchCount: mysql.Message("data inconsistency in table: %s, index: %s, index-count:%d != record-count:%d", nil),
ErrDataInconsistentMismatchIndex: mysql.Message("data inconsistency in table: %s, index: %s, col: %s, handle: %#v, index-values:%#v != record-values:%#v, compare err:%#v", []int{3, 4, 5, 6}),
ErrInconsistentRowValue: mysql.Message("writing inconsistent data in table: %s, expected-values:{%s} != record-values:{%s}", []int{1, 2}),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be hard to say which is the expected one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a mistake here, the arguments are passed in the wrong order. But I think the input of the AddRecords should be the expected data?

Signed-off-by: ekexium <ekexium@gmail.com>
Signed-off-by: ekexium <ekexium@gmail.com>
@ekexium
Copy link
Contributor Author

ekexium commented Dec 16, 2021

/run-check_dev

@ti-chi-bot ti-chi-bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Dec 16, 2021
@ekexium
Copy link
Contributor Author

ekexium commented Dec 16, 2021

/run-check_dev

1 similar comment
@ekexium
Copy link
Contributor Author

ekexium commented Dec 16, 2021

/run-check_dev

@ti-chi-bot ti-chi-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Dec 16, 2021
"row handle = %v, index = %+v, row = %+v",
indexHandle, insertionHandle, m, rowInsertion)
err = ErrInconsistentHandle.GenWithStackByArgs(tableName, indexInfo.Name.O, indexHandle, insertionHandle, m, rowInsertion)
logutil.BgLogger().Error(err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider:

Suggested change
logutil.BgLogger().Error(err.Error())
logutil.BgLogger().Error("inconsistent handles in row and index insertions detected", zap.Error(err))

Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to use zap.Error to put the error to the log

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's the benefit?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's the pattern that we always use. Usually the log message is a constant string and the other various information are provided in additional fields, wrapped with zap which makes it lazy-evaluated.

Signed-off-by: ekexium <ekexium@gmail.com>
@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 Dec 16, 2021
@ekexium ekexium merged commit 7f1b00c into pingcap:ft-data-inconsistency Dec 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants