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

(re)Formalize SQLError in VReplication, add underlying wrap/unwrap functionality #12327

Merged
merged 4 commits into from
Feb 22, 2023

Conversation

shlomi-noach
Copy link
Contributor

Description

Fixes #12326

This PR re-formalizes SQLError in vreplication in two ways:

While here:

  • Added Unwrap and UnwrapAll functions in vterrors
  • Using said functions in NewSQLErrorFromError() to first (attempt to) get the original error object, before resorting to parsing.

Added a bunch of unit tests.

Related Issue(s)

Fixes #12326
Precondition for #12323
Precondition for #12325
Formalizes changes made in #10828

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

…nctionality

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Feb 13, 2023

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • If this is a change that users need to know about, please apply the release notes (needs details) label so that merging is blocked unless the summary release notes document is included.
  • If a test is added or modified, there should be a documentation on top of the test to explain what the expected behavior is what the test does.

If a new flag is being introduced:

  • Is it really necessary to add this flag?
  • Flag names should be clear and intuitive (as far as possible)
  • Help text should be descriptive.
  • Flag names should use dashes (-) as word separators rather than underscores (_).

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow should be required, the maintainer team should be notified.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should include a link to an issue that describes the bug.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from VTop, if used there.

Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

The wrapping parts makes sense to me, but unless I'm missing something we should remove the utils.go changes.

Comment on lines +262 to +264
for wasWrapped {
wasWrapped, err = Unwrap(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should probably add a limit here to prevent never getting out of here some odd reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic is legit IMHO and the unit tests make good coverage. Please give this another thought. Would you want to see code that counts to 50 and then fails? Would that code look clearer or even more confusing? Please let me know and I'll do whatever you think.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, what to do when this fails due to hitting the limit would be unknown. We have some protection from infinite recursion and would panic: golang/go@757e0de

So I'm totally fine with it as-is.

@shlomi-noach
Copy link
Contributor Author

shlomi-noach commented Feb 14, 2023

but unless I'm missing something we should remove the utils.go changes.

The addition to utils.go, ie the use of NewSQLErrorFromError(), is a fallback technique, designed to prevent future regressions. The function NewSQLErrorFromError() parses the text of an error, and reconstructs a SqlError object if the text seems to indicate a SQLError. I cannot design a endtoend or unit test that validates that any error path does indeed produce a real SqlError; it's impossible to validate that no one ever wraps an error with fmt.Errorf(); that's because we can't anticipate any and all errors, or any and all code paths. And some errors actually will not be SqlError.

So the idea of this safeguard is very appealing and I think we should keep it.

Now, as it happens, the current implementation NewSQLErrorFromError() always returns a SqlError, even if the error really has nothing to do with SQL. That's the implementation and I chose not to deal with it in this PR. I've already opened 6 different PRs for tackling the flaky tests, going down quite a few rabbit holes. So I wanted to stop at some point. I confirm to the existing behavior, and maybe in a future PR I'll tackle the NewSQLErrorFromError() logic.

At any case, if the error has nothing to do with SQL, you get a error object, which you need to cast to SqlError, that has sqlErr.Num == mysql.ERUnknownError. That's the existing logic and I agree it's confusing. But I still prefer to not try and fix everything in this PR. There's a dozen or more files that use this pattern and I wanted to keep this PR focused.

@frouioui frouioui mentioned this pull request Feb 16, 2023
51 tasks
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

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

lgtm

@shlomi-noach
Copy link
Contributor Author

@mattlord since you had comments, can you please take another look?

Comment on lines +262 to +264
for wasWrapped {
wasWrapped, err = Unwrap(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, what to do when this fails due to hitting the limit would be unknown. We have some protection from infinite recursion and would panic: golang/go@757e0de

So I'm totally fine with it as-is.

@mattlord
Copy link
Contributor

but unless I'm missing something we should remove the utils.go changes.

The addition to utils.go, ie the use of NewSQLErrorFromError(), is a fallback technique, designed to prevent future regressions. The function NewSQLErrorFromError() parses the text of an error, and reconstructs a SqlError object if the text seems to indicate a SQLError. I cannot design a endtoend or unit test that validates that any error path does indeed produce a real SqlError; it's impossible to validate that no one ever wraps an error with fmt.Errorf(); that's because we can't anticipate any and all errors, or any and all code paths. And some errors actually will not be SqlError.

So the idea of this safeguard is very appealing and I think we should keep it.

Now, as it happens, the current implementation NewSQLErrorFromError() always returns a SqlError, even if the error really has nothing to do with SQL. That's the implementation and I chose not to deal with it in this PR. I've already opened 6 different PRs for tackling the flaky tests, going down quite a few rabbit holes. So I wanted to stop at some point. I confirm to the existing behavior, and maybe in a future PR I'll tackle the NewSQLErrorFromError() logic.

At any case, if the error has nothing to do with SQL, you get a error object, which you need to cast to SqlError, that has sqlErr.Num == mysql.ERUnknownError. That's the existing logic and I agree it's confusing. But I still prefer to not try and fix everything in this PR. There's a dozen or more files that use this pattern and I wanted to keep this PR focused.

Makes sense (I read through what that code does and how too). Thanks!

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

Not sure what changed that a bunch of vtgate_* CI tests consistently fail. I merged main but to no effect.

@shlomi-noach
Copy link
Contributor Author

The failing tests are due to the change

	err = vterrors.UnwrapAll(err)

I'm digging in.

@shlomi-noach
Copy link
Contributor Author

OK i'm reverting the err = vterrors.UnwrapAll(err) change, it is not very important to this PR, will handle it in a later PR. It seems to affect too many tests.

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach
Copy link
Contributor Author

I see why the Unwrap addition in sql_error.go caused the tests to fail. There's logic that attempts to convert a vterrors error code into SQL code. Unwrap stripped down the vterrros information, thus said info was lost.

@shlomi-noach shlomi-noach merged commit 6b5eb50 into vitessio:main Feb 22, 2023
@shlomi-noach shlomi-noach deleted the sql-error-unwrap-vreplication branch February 22, 2023 06:44
@shlomi-noach
Copy link
Contributor Author

Will cherry pick this to v16 manually, since I've merged main in the process.

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

Successfully merging this pull request may close these issues.

Bug Report: regression, VReplication errors lost their type, converted to errorString
5 participants