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: improved diff ordering with various foreign key strategies #16081

Merged

Conversation

shlomi-noach
Copy link
Contributor

Description

We introduce a new foreign key diff strategy flag and improve the diff sorting mechanism. The strategy flags are now: (from strict to loose):

  • ForeignKeyCheckStrategyStrict
  • ForeignKeyCheckStrategyCreateTableFirst
  • ForeignKeyCheckStrategyIgnore

The main change in this PR is the understanding that "stricter is better, if possible". In this PR, if we request a diff using a loose ForeignKeyCheckStrategyIgnore strategy, and the diff can be fulfilled by the stricter ForeignKeyCheckStrategyStrict, then it will. If not, and can be fulfilled by still stricter ForeignKeyCheckStrategyCreateTableFirst, it will.

The converse is not true: if we request a diff using ForeignKeyCheckStrategyStrict strategy, then it may only be fulfilled via ForeignKeyCheckStrategyStrict.

In effect, this is only relevant when cyclic foreign keys are introduced. When we say "cyclic", we refer to tables referencing each other such as t1->t2->t3->t1. This PR is not about existence of cyclic tables; it is about introducing a cyclic change such that the diff themselves might depend on each other. And the discussion is: "what is a valid order of diffs, such that we can introduce one diff at a time, maintain a valid schema, and end of with the desired schema"?

It is not always possible to get such ordering given a set of changes, and the different strategies tell us how to tackle such situations:

  • ForeignKeyCheckStrategyStrict: there absolutely must be a valid sequence, or else we return an error.
  • ForeignKeyCheckStrategyCreateTableFirst: it's possible to have an invalid sequence, but we tolerate a sequence where the first change is ALTER TABLE, even if it introduces a dependency which is not yet met. The rest of changes must then all line up. At the end of all changes, we must achieve a valid schema.
  • ForeignKeyCheckStrategyIgnore: we don't care at all if there's no valid sequence. But at the end of all changes, we must achieve a valid schema.

Related Issue(s)

#15430

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on 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>
…-desired search path, that first attempts to echieve a dependency resolution with strictest means, but if impossible, resotrs to more relaxed constraints

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>
@shlomi-noach shlomi-noach requested review from dbussink and a team June 9, 2024 06:35
Copy link
Contributor

vitess-bot bot commented Jun 9, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Jun 9, 2024
@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) and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Jun 9, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Jun 9, 2024
Copy link

codecov bot commented Jun 9, 2024

Codecov Report

Attention: Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.

Project coverage is 68.19%. Comparing base (87ecae7) to head (0da285a).

Files Patch % Lines
go/vt/schemadiff/schema_diff.go 94.44% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16081      +/-   ##
==========================================
- Coverage   68.19%   68.19%   -0.01%     
==========================================
  Files        1541     1541              
  Lines      197369   197391      +22     
==========================================
+ Hits       134605   134618      +13     
- Misses      62764    62773       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@shlomi-noach shlomi-noach requested a review from a team June 10, 2024 08:01
@mattlord mattlord merged commit 6fb0f0e into vitessio:main Jun 10, 2024
108 checks passed
@mattlord mattlord deleted the schemadiff-sequential-complex-refactor branch June 10, 2024 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) 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.

3 participants