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

sql: add doctor check for parent schema in parent db #58875

Merged
merged 1 commit into from
Jan 14, 2021

Conversation

postamar
Copy link
Contributor

With this patch, doctor now also checks that the parent id of an object
matches the parent id of the parent schema of the object.

Fixes #55716.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@postamar
Copy link
Contributor Author

For good measure I checked out the commit prior to the merge commit #55723, cherry-picked this commit, successfully reproduced the problem in the issue and checked that doctor ran the new check correctly:

Examining 36 descriptors and 40 namespace entries...
   Table  55: ParentID  52, ParentSchemaID 54, Name 'bar': invalid parent schema parent id 50
Examining 0 running jobs...
ERROR: validation failed
Failed running "debug doctor cluster"

@postamar
Copy link
Contributor Author

CI failed on what appears to be a flaky test, which already has an issue open: #58624 . I don't believe the failure is related to my changes.

@postamar postamar marked this pull request as ready for review January 12, 2021 20:02
@postamar postamar requested a review from a team January 12, 2021 20:02
Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Thanks for picking this up

Reviewed 2 of 2 files at r1.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @postamar)


pkg/sql/doctor/doctor.go, line 177 at r1 (raw file):

			} else if !invalidParentID && parentSchema.GetParentID() != desc.GetParentID() {
				problemsFound = true
				fmt.Fprint(stdout, reportMsg(desc, "invalid parent schema parent id %d", parentSchema.GetParentID()))

I think this message can be clearer and can have a test. Namely, it'd be interesting to know both parent id values.

Copy link
Contributor Author

@postamar postamar left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner)


pkg/sql/doctor/doctor.go, line 177 at r1 (raw file):

Previously, ajwerner wrote…

I think this message can be clearer and can have a test. Namely, it'd be interesting to know both parent id values.

Perhaps I'm misunderstanding but it is tested and the other parent id values already get reported in the prefix of the error message. See the test case I added for an example of this.

Copy link
Contributor Author

@postamar postamar left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner)


pkg/sql/doctor/doctor.go, line 177 at r1 (raw file):

Previously, postamar (Marius Posta) wrote…

Perhaps I'm misunderstanding but it is tested and the other parent id values already get reported in the prefix of the error message. See the test case I added for an example of this.

I changed the message to something that should be less confusing.

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

Reviewed 1 of 2 files at r2.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @postamar)


pkg/sql/doctor/doctor.go, line 174 at r2 (raw file):

			if !parentSchemaExists {
				problemsFound = true
				fmt.Fprint(stdout, reportMsg(desc, "invalid parent schema id %d", desc.GetParentSchemaID()))

err, then this case is not tested then, right?

Copy link
Contributor Author

@postamar postamar left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner)


pkg/sql/doctor/doctor.go, line 174 at r2 (raw file):

Previously, ajwerner wrote…

err, then this case is not tested then, right?

This case was already there and only shows up in the diff because I broke down the if clause into an if-else statement, so I didn't check if it was covered. I'll add a test for good measure.

Copy link
Contributor

@ajwerner ajwerner left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewed 1 of 2 files at r2.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @postamar)


pkg/sql/doctor/doctor.go, line 174 at r2 (raw file):

Previously, postamar (Marius Posta) wrote…

This case was already there and only shows up in the diff because I broke down the if clause into an if-else statement, so I didn't check if it was covered. I'll add a test for good measure.

gotcha, thanks

With this patch, doctor now also checks that the parent id of an object
matches the parent id of the parent schema of the object.

Fixes cockroachdb#55716.

Release note: None
@postamar
Copy link
Contributor Author

bors r+

@craig
Copy link
Contributor

craig bot commented Jan 14, 2021

Build failed:

@postamar
Copy link
Contributor Author

bors r+

Flaky test fix has been merged, trying again.

@craig
Copy link
Contributor

craig bot commented Jan 14, 2021

Build succeeded:

@craig craig bot merged commit b1f5a62 into cockroachdb:master Jan 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

doctor: ensure that parentSchemaID is in parentID
3 participants