Skip to content

sql/catalog,migrations: propagate HasPostDeserializationChanges, simplify migrations#76590

Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom
ajwerner:ajwerner/simplify-descriptor-migrations
Feb 16, 2022
Merged

sql/catalog,migrations: propagate HasPostDeserializationChanges, simplify migrations#76590
craig[bot] merged 2 commits intocockroachdb:masterfrom
ajwerner:ajwerner/simplify-descriptor-migrations

Conversation

@ajwerner
Copy link
Copy Markdown
Contributor

@ajwerner ajwerner commented Feb 15, 2022

This is an imperfect change that feels a bit ad-hoc for my liking, but does
improve the situation. The problem is that in recent changes, we no longer
just retrieve mutable descriptors and then sometimes clone Immutable
descriptors. Instead we create the more general Immutable descriptors and
clone out mutables. The problem is that when we did this, we threw away
information regarding whether the descriptor itself had been modified
by post-deserialization. In general, this is mostly an exercise in plumbing.
The key feature is that when we retreive a Mutable descriptor and it was
changed, we need to know that. This change tests that.

There is some ad-hoc code to propagate isUncommitedVersion in various places
which I don't feel great about, but it also felt wrong not to. A follow-up
should come through to really nail down the properties here.

The existence of NewBuilder and the fact that it's called in various places
is another mechanism by which this information could be erased, but that's
less of a concern for me. This change makes it possible to simplify migrations
around descriptor upgrades.

migrations: simplify descriptor migrations

We have two migrations which have the goal of iterating through the descriptors
and re-writing them if there are any changes due to the post-deserialization
logic. They were needlessly complex and low-level. Probably part of the reason
was that we were swallowing this information. This commit reworks them to use
shared library code.

Probably one of them could be eliminated altogether.

Release note: None

@ajwerner ajwerner requested review from a team, RichardJCai and postamar February 15, 2022 16:49
@cockroach-teamcity
Copy link
Copy Markdown
Member

This change is Reviewable

@ajwerner ajwerner force-pushed the ajwerner/simplify-descriptor-migrations branch from c7fbe91 to 3f5179c Compare February 15, 2022 18:16
Copy link
Copy Markdown

@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.

Reviewed 16 of 20 files at r1, 9 of 9 files at r3, 5 of 5 files at r4, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @RichardJCai)


pkg/migration/migrations/descriptor_utils.go, line 74 at r4 (raw file):

func runPostDeserializationChangesOnAllDescriptors(
	ctx context.Context, d migration.TenantDeps,
) error {

I'm glad you're putting this thing in our migration toolbox of sorts. I feel like there's bound to be at least one such migration in each release.


pkg/sql/catalog/descriptor.go, line 215 at r3 (raw file):

	GetDeclarativeSchemaChangerState() *scpb.DescriptorState

	// HasPostDeserializationChanges returns if the MutableDescriptor was changed after running

nit: s/MutableDescriptor/Descriptor


pkg/sql/catalog/dbdesc/database_desc.go, line 48 at r3 (raw file):

	// changed represents whether or not the descriptor was changed
	// after RunPostDeserializationChanges.
	changed bool

While we're at it, consider:

  • moving PostDeserializationChangeType to catalog and,
  • store the map[PostDeserializationChangeType]bool in this immutable instead of this flag,
  • same with other descriptor types,
  • replace HasPostDeserializationChanges with, say, ForEachPostDeserializationChange(func(PostDeserializationChangeType) error) error
  • provide HasPostDeserializationChanges as a helper function which calls this ForEachPostDeserializationChange instead.

Feel free to not bother if you don't want to, & file a follow-up issue based off this comment & assign it to me.


pkg/migration/migrations/ensure_constraint_id_test.go, line 126 at r4 (raw file):

		[][]string{{"false", "false"}},
	)
	log.Infof(ctx, "okay about to upgrade")

detritus?

…alog

This is an imperfect change that feels a bit ad-hoc for my liking, but does
improve the situation. The problem is that in recent changes, we no longer
just retreive mutable descriptors and then sometimes clone Immutable
descriptors. Instead we create the more general Immutable descriptors and
clone out mutables. The problem is that when we did this, we threw away
information regarding whether the descriptor itself had been modified
by post-deserialization. In general, this is mostly an exercise in plumbing.
The key feature is that when we retreive a Mutable descriptor and it was
changed, we need to know that. This change tests that.

There is some ad-hoc code to propagate isUncommitedVersion in various places
which I don't feel great about, but it also felt wrong not to. A follow-up
should come through to really nail down the properties here.

The existence of NewBuilder and the fact that it's called in various places
is another mechanism by which this information could be erased, but that's
less of a concern for me. This change makes it possible to simplify migrations
around descriptor upgrades.

Release note: None
We have two migrations which have the goal of iterating through the descriptors
and re-writing them if there are any changes due to the post-deserialization
logic. They were needlessly complex and low-level. Probably part of the reason
was that we were swallowing this information. This commit reworks them to use
shared library code.

Probably one of them could be eliminated altogether.

Release note: None
@ajwerner ajwerner force-pushed the ajwerner/simplify-descriptor-migrations branch from 3f5179c to 698b97c Compare February 15, 2022 21:30
Copy link
Copy Markdown
Contributor Author

@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.

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


pkg/sql/catalog/dbdesc/database_desc.go, line 48 at r3 (raw file):

Previously, postamar (Marius Posta) wrote…

While we're at it, consider:

  • moving PostDeserializationChangeType to catalog and,
  • store the map[PostDeserializationChangeType]bool in this immutable instead of this flag,
  • same with other descriptor types,
  • replace HasPostDeserializationChanges with, say, ForEachPostDeserializationChange(func(PostDeserializationChangeType) error) error
  • provide HasPostDeserializationChanges as a helper function which calls this ForEachPostDeserializationChange instead.

Feel free to not bother if you don't want to, & file a follow-up issue based off this comment & assign it to me.

I did this, more or less,


pkg/migration/migrations/ensure_constraint_id_test.go, line 126 at r4 (raw file):

Previously, postamar (Marius Posta) wrote…

detritus?

Done.

Copy link
Copy Markdown

@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.

Reviewed 23 of 23 files at r5, 5 of 5 files at r6, all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @RichardJCai)


pkg/sql/catalog/dbdesc/database_desc.go, line 48 at r3 (raw file):

Previously, ajwerner wrote…

I did this, more or less,

Nicely done.

@ajwerner
Copy link
Copy Markdown
Contributor Author

TFTR!

bors r+

Copy link
Copy Markdown
Contributor

@RichardJCai RichardJCai left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @ajwerner and @postamar)


pkg/migration/migrations/descriptor_utils.go, line 74 at r4 (raw file):

Previously, postamar (Marius Posta) wrote…

I'm glad you're putting this thing in our migration toolbox of sorts. I feel like there's bound to be at least one such migration in each release.

Huge +1, thanks for this.

@craig
Copy link
Copy Markdown
Contributor

craig bot commented Feb 16, 2022

Build succeeded:

@craig craig bot merged commit 9f98cde into cockroachdb:master Feb 16, 2022
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.

4 participants