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/schemachanger: add compatibility with 22.2 rules #95361

Merged
merged 2 commits into from
Jan 19, 2023

Conversation

fqazi
Copy link
Collaborator

@fqazi fqazi commented Jan 17, 2023

This PR will make the following changes:

  1. Refactor the existing rules package so that there is a common package, and multiple dep/op rules registries to allow us to support rules from older releases. This also includes splitting out helper functions to make this process easier
  2. Import the 22.2 rules and have them adopt the same refactoring, so that a new rules/deps registry exists with them
  3. Select the dep/op rules based on the active version of CRDB

@cockroach-teamcity
Copy link
Member

This change is Reviewable

@fqazi fqazi force-pushed the ruleBackCompat branch 2 times, most recently from 3aaf70a to 87ce2fe Compare January 17, 2023 19:30
@fqazi
Copy link
Collaborator Author

fqazi commented Jan 17, 2023

This is best looked at on a commit-by-commit basis, the first one just shifts things around. The second one adds 22.2 rules, there are some changes here to facilitate planning on the master, specifically for dropping constraints (which are harmless and should be optimized out general DROP cases)

@fqazi fqazi marked this pull request as ready for review January 17, 2023 19:42
@fqazi fqazi requested a review from a team January 17, 2023 19:42
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.

Is there any reason common can't just be in the rules package?

@ajwerner
Copy link
Contributor

Also, this might be a good use case for a . import. WDYT?

@fqazi
Copy link
Collaborator Author

fqazi commented Jan 18, 2023

Is there any reason common can't just be in the rules package?

Good point, I'll eliminate the common package and move everything up

@fqazi
Copy link
Collaborator Author

fqazi commented Jan 18, 2023

Also, this might be a good use case for a . import. WDYT?

The linter doesn't like the idea of those imports :(

@fqazi fqazi force-pushed the ruleBackCompat branch 2 times, most recently from 07b4df3 to df09ee9 Compare January 18, 2023 23:42
@fqazi fqazi requested a review from a team as a code owner January 18, 2023 23:42
@fqazi fqazi requested a review from ajwerner January 18, 2023 23:43
@fqazi
Copy link
Collaborator Author

fqazi commented Jan 18, 2023

@ajwerner Made both of those changes

Comment on lines 132 to 169
func applyOpRules(
ctx context.Context, activeVersion clusterversion.ClusterVersion, g *scgraph.Graph,
) (*scgraph.Graph, error) {
if activeVersion.IsActive(clusterversion.V23_1) {
return current.ApplyOpRules(ctx, g)
} else if activeVersion.IsActive(clusterversion.V22_2) {
return release_22_2.ApplyOpRules(ctx, g)
} else {
log.Warningf(ctx, "Falling back to the oldest supported version 22.2")
return release_22_2.ApplyOpRules(ctx, g)
}
}

func applyDepRules(
ctx context.Context, activeVersion clusterversion.ClusterVersion, g *scgraph.Graph,
) error {
if activeVersion.IsActive(clusterversion.V23_1) {
return current.ApplyDepRules(ctx, g)
} else if activeVersion.IsActive(clusterversion.V22_2) {
return release_22_2.ApplyDepRules(ctx, g)
} else {
log.Warningf(ctx, "Falling back to the oldest supported version 22.2")
return release_22_2.ApplyDepRules(ctx, g)
}
}
Copy link
Contributor

@ajwerner ajwerner Jan 19, 2023

Choose a reason for hiding this comment

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

nit: make a function to look up the registry for the version rather than dispatching each of these methods.

Also, that function is a great place to write a comment explaining why we're doing this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, added a new function and use that here:

// getRulesRegistryForRelease returns the rules registry based on the current
// active version of cockroach. In a mixed version state, it's possible for the state
// generated by a newer version of cockroach to be incompatible with old versions.
// For example dependent objects or combinations of them in a partially executed,
// plan may reach states where older versions of cockroach may not be able
// to plan further (and vice versa). To eliminate the possibility of these issues, we
// will plan with the set of rules belonging to the currently active version. One
// example of this is the dependency between index name and secondary indexes
// is more relaxed on 23.1 vs 22.2, which can lead to scenarios where the index
// name may become public before the index is public (which was disallowed on older
// versions).

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

…eleases

Previously, the declarative schema changer rules were tightly
coupled, so we had no way of allowing them to be portal between
releases for mixed version compatibility. To address this, this
patch introduces a common package that will help facilitate making
rules more portable between different version.

Release note: None
Epic: None
Previously, when rules were relaxed on master
we could have compatibility issues in mixed version
environments. This was inadequate because, the relaxed
rules could not generate plans that could pass assertions
in a mixed version state. To address this, this
patch adds the 22.2 rules on master, and uses
them in mixed version scenarios.

Release note: none
Epic: none
@fqazi
Copy link
Collaborator Author

fqazi commented Jan 19, 2023

bors r+

Failure is a known test flake

@craig
Copy link
Contributor

craig bot commented Jan 19, 2023

Build succeeded:

@craig craig bot merged commit c8c4241 into cockroachdb:master Jan 19, 2023
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.

3 participants