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

schemadiff: multi-error in schema normalization #12675

Merged
merged 45 commits into from
Mar 22, 2023

Conversation

shlomi-noach
Copy link
Contributor

Description

In this PR a Schema's normalize() function, which also runs validations for the entire schema, tables and views, returns a potentially aggregated error rather than a single error.

The idea is to return as much information as possible about problems in the schema, we the user can have multiple action points they can handle at once. This is instead of receiving a single error, fixing it, trying again, receiving the next single error, etc.

Not all errors make sense to aggregate; we specifically aggregate errors that relate to view dependencies.

To top it all, NewSchemaFromEntities() returns whatever Schema object it may have processed, even if invalid, as opposed to returning nil on error.

Related Issue(s)

#10203

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation was added or is not required

Deployment Notes

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…t views reading from DUAL

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
… expression in DUAL

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…-view-columns-semantics

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…lidateViewReferences

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) labels Mar 21, 2023
@shlomi-noach shlomi-noach requested a review from deepthi as a code owner March 21, 2023 03:53
@shlomi-noach shlomi-noach requested review from dbussink and a team March 21, 2023 03:53
@shlomi-noach shlomi-noach removed the Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) label Mar 21, 2023
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach requested review from a team and dbussink March 22, 2023 10:27
@shlomi-noach shlomi-noach requested a review from a team March 22, 2023 14:19
}

// Unwrap unwraps an error created by errors.Join() in Go 1.20, into its components
func Unwrap(err error) []error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method will not be called right. u.Unwrap on line 27 is called on object level.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now no one is using this function... I added it for completeness.

@@ -153,6 +153,7 @@ func TestNewSchemaFromQueriesLoop(t *testing.T) {
)
_, err := NewSchemaFromQueries(queries)
assert.Error(t, err)
err = UnwrapOne(err)
assert.EqualError(t, err, (&ViewDependencyUnresolvedError{View: "v7"}).Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

can we assert err length here as well .. to assure the numbers of errors are as expected

Copy link
Contributor Author

@shlomi-noach shlomi-noach Mar 22, 2023

Choose a reason for hiding this comment

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

UnwrapOne() is guaranteed to return a slice of at least one element.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And yes! I'll add that assertion anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rather, I'll create a errors_test.go with a bunch of unit tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unit tests added

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Comment on lines 10 to 11
// Wrapped is used to unwrap an error created by errors.Join() in Go 1.20
type Wrapped interface {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is more a structural comment; i'd suggest either renaming or relocating these types. right now you import schemadiff.Wrapped which, somehow, is for errors? i would expect from that name alone it's some sort of, well, wrapped diff structure (ditto the Unwrap* functions).

so, i'd either advocate for schemadiff.WrappedError or vterrors.Wrapped (or a new package!)

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 agree. The location is suboptimal. I initially wanted to do this in vterrors, but vterrors has its own Unwrap. I'll create a new errors package.

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, refactored!

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach merged commit 7c033f4 into vitessio:main Mar 22, 2023
@shlomi-noach shlomi-noach deleted the schemadiff-normalize-multi-err branch March 22, 2023 20:01
dbussink added a commit to planetscale/vitess that referenced this pull request Mar 23, 2023
The logic added in vitessio#12675 has a
small issue. When a view is found that has an error, it's not present
anymore when a subsequent `.ToSQL()` call happens, so it looks like the
view disappears.

We should never have a view disappear since that could potentially break
things and lead to unexpected results.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Copy link
Contributor

@rsajwani rsajwani left a comment

Choose a reason for hiding this comment

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

LGTM

dbussink added a commit that referenced this pull request Mar 23, 2023
The logic added in #12675 has a
small issue. When a view is found that has an error, it's not present
anymore when a subsequent `.ToSQL()` call happens, so it looks like the
view disappears.

We should never have a view disappear since that could potentially break
things and lead to unexpected results.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants