Skip to content

catalog: spin off and adopt back-reference validation level#86420

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
postamar:separate-back-ref-validation
Sep 8, 2022
Merged

catalog: spin off and adopt back-reference validation level#86420
craig[bot] merged 2 commits intocockroachdb:masterfrom
postamar:separate-back-ref-validation

Conversation

@postamar
Copy link
Copy Markdown

@postamar postamar commented Aug 18, 2022

Previously, forward- and backward-reference-checking was done in one
same validation phase, identified by the
catalog.ValidationLevelCrossReferences constant and a similarly named
method on catalog.Descriptor. This validation phase was exercised both
when reading and when writing descriptors.

The problem with this was that a corrupt back-reference would make
a table unusable until descriptor surgery was performed. While this
might be warranted in the context of schema changes, that's not the case
when it comes to queries, which don't really care about these
back-references. For this reason, we want to bypass back-reference
validation when reading descriptors for the purpose of serving queries.
These reads are characterized by the flag AvoidLeased being unset.

To do this, this commit splits the cross-reference validation level into
two. The back-reference level now exists to check the integrity of
back-references directly, as well as to check that forward references
also have matching back-references in the referenced descriptors.

Fixes #85263.

Release justification: low-risk, high benefit change
Release note: None


This PR is based on #87067 which is the product of what made sense for me to take action on right now regarding #86420 (comment) .

@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@postamar postamar force-pushed the separate-back-ref-validation branch 6 times, most recently from 304f6b5 to bbd9419 Compare August 22, 2022 17:36
@postamar postamar changed the title catalog: separate forward- and back-reference validation catalog: relax validation level when reading immutable descs Aug 22, 2022
@postamar
Copy link
Copy Markdown
Author

The descriptors collection is way too self-referential for this to work reliably. It calls itself for validation and hydration in ways which are impossible to reason about. I think the way to go here is to tighten the self-referential parts into an inner core object of sorts:

  • this object contains the layers (virtual, temporary, synthetic, stored and leased);
  • it serves getByIDs queries, along with getByName and getAllDescriptors and other similar endpoints;
  • it handles validation and type hydration, along with memory management and caching;
  • the lease manager, the kv layer etc. can be dependency-injected so that we can do some kind of tracing, have data-driven tests, etc.

@postamar postamar closed this Aug 22, 2022
@postamar postamar reopened this Aug 23, 2022
@postamar postamar force-pushed the separate-back-ref-validation branch 12 times, most recently from 090066c to dc8c433 Compare August 30, 2022 02:52
@postamar postamar changed the title catalog: relax validation level when reading immutable descs catalog: spin off and adopt back-reference validation level Aug 30, 2022
@postamar
Copy link
Copy Markdown
Author

This is ready for review now, it's correct enough.

@postamar postamar marked this pull request as ready for review August 30, 2022 03:00
@postamar postamar requested review from a team August 30, 2022 03:00
@postamar postamar requested a review from a team as a code owner August 30, 2022 03:00
@postamar postamar requested a review from a team August 30, 2022 03:00
@postamar postamar requested a review from adityamaru August 30, 2022 03:00
@postamar postamar force-pushed the separate-back-ref-validation branch 2 times, most recently from bf297fc to b399401 Compare September 1, 2022 01:09
@postamar postamar requested review from ajwerner and removed request for a team and adityamaru September 1, 2022 12:22
@postamar postamar force-pushed the separate-back-ref-validation branch from b399401 to 61bcb03 Compare September 1, 2022 12:25
Copy link
Copy Markdown
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: nice!

Reviewed 28 of 28 files at r2, 1 of 1 files at r3, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @postamar)


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_primary_key.go line 397 at r2 (raw file):

	if _, _, inboundFKElem := scpb.FindForeignKeyConstraint(b.BackReferences(tableID)); inboundFKElem != nil {
		panic(scerrors.NotImplementedErrorf(t.n,
			fmt.Sprintf(`foreign keys to table with TTL %q are not permitted`, ns.Name)))

why fmt.Sprintf? It's already a formatting method, no? This is going to lead to redaction in a bad way


pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_alter_primary_key.go line 400 at r2 (raw file):

	}
	if _, _, outboundFKElem := scpb.FindForeignKeyConstraint(b.QueryByID(tableID)); outboundFKElem != nil {
		panic(scerrors.NotImplementedErrorf(t.n,

why fmt.Sprintf? It's already a formatting method, no? This is going to lead to redaction in a bad way

@postamar
Copy link
Copy Markdown
Author

postamar commented Sep 7, 2022

Thanks for the review! No good reason why fmt.Sprintf is being used there. Fixing.

Marius Posta added 2 commits September 7, 2022 16:40
Previously, forward- and backward-reference-checking was done in one
same validation phase, identified by the
catalog.ValidationLevelCrossReferences constant and a similarly named
method on catalog.Descriptor. This validation phase was exercised both
when reading and when writing descriptors.

The problem with this was that a corrupt back-reference would make
a table unusable until descriptor surgery was performed. While this
might be warranted in the context of schema changes, that's not the case
when it comes to queries, which don't really care about these
back-references. For this reason, we want to bypass back-reference
validation when reading descriptors for the purpose of serving queries.
These reads are characterized by the flag AvoidLeased being unset.

To do this, this commit splits the cross-reference validation level into
two. The back-reference level now exists to check the integrity of
back-references directly, as well as to check that forward references
also have matching back-references in the referenced descriptors.

Fixes cockroachdb#85263.

Release justification: low-risk, high benefit change
Release note: None
Previously, it swallowed all kinds of errors, making debugging painful.

Release justification: test-only change
Release note: None
@postamar postamar force-pushed the separate-back-ref-validation branch from 61bcb03 to 1a66a9b Compare September 7, 2022 20:40
@postamar
Copy link
Copy Markdown
Author

postamar commented Sep 7, 2022

bors r+

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 8, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 8, 2022

Build failed (retrying...):

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Sep 8, 2022

Build succeeded:

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.

catalog: spin validation of back-references off into distinct phase

3 participants