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: formalize InstantDDLCapability #14900

Merged
merged 24 commits into from
Jan 18, 2024

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Jan 7, 2024

Description

Another followup and iteration on #14878.

The changes in this PR are not (yet) put to use, so this PR does not modify any existing behavior.

In this PR we formalize further what it means for a single diff, or for a group of diffs, to be INSTANT-capable.

  1. We formalize a capability type:
type InstantDDLCapability int

const (
	InstantDDLCapabilityUnknown InstantDDLCapability = iota
	InstantDDLCapabilityIrrelevant
	InstantDDLCapabilityImpossible
	InstantDDLCapabilityPossible
)
  1. EntityDiff interface now has InstantDDLCapability() InstantDDLCapability function.
    For most diffs, like CREATE TABLE, ALTER VIEW, etc., the capability is InstantDDLCapabilityIrrelevant. That's because you can't apply ALGORITHM=INSTANT on such diff. For AlterTableEntityDiff, which stands for ALTER TABLE, the capability would be either InstantDDLCapabilityUnknown (more on this shortly), InstantDDLCapabilityImpossible (e.g. on ADD FOREIGN KEY) or InstantDDLCapabilityPossible (e.g. on ADD COLUMN).
  2. We add MySQLServerVersion in DiffHints. Without this information, we do not know what INSTANT capabilities the diff has. And therefore without this info the capability is InstantDDLCapabilityUnknown.
  3. SchemaDiff() function, that computes a SchemaDiff object, computes and populates relevant InstantDDLCapability in any AlterTableEntityDiff.
  4. Convenience function func (d *SchemaDiff) InstantDDLCapability() InstantDDLCapability tells us what the overall INSTANT-capability is for a multi-change.

We remove CapableOfInstantDDL() function (unused) which only returned a bool value, which wasn't informative enough.

Related Issue(s)

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>
…ff is capable of INSTANT algorithm

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>
…ntDDL instead

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…it. Introduce mysql.ServerVersionCapableOf() helper function

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>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) labels Jan 7, 2024
Copy link
Contributor

vitess-bot bot commented Jan 7, 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 Jan 7, 2024
@github-actions github-actions bot added this to the v19.0.0 milestone Jan 7, 2024
@shlomi-noach shlomi-noach changed the title Schemadiff instant info schemadiff: formalize InstantDDLCapability Jan 7, 2024
@shlomi-noach shlomi-noach 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 Jan 8, 2024
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach marked this pull request as ready for review January 8, 2024 09:09
@shlomi-noach shlomi-noach requested a review from deepthi as a code owner January 8, 2024 09:09
@shlomi-noach
Copy link
Contributor Author

Now that #14883 is merged, this PR is ready to review.

@shlomi-noach shlomi-noach requested a review from a team January 8, 2024 09:09
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

LGTM! Only had minor questions that you can handle as you feel is best.

@@ -23,6 +23,7 @@ import (
"sort"
"strings"

"vitess.io/vitess/go/mysql"
Copy link
Contributor

Choose a reason for hiding this comment

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

Not directly related but I thought that the other capabilities package refactor was meant to avoid having to import the mysql package in schemadiff. No? Perhaps I'm misremembering.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that's true! Good catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Going to refactor go/mysql a bit, it will be better for everyone in the end. Will comment again once done for another review.

Comment on lines 350 to 351
// The general logic: we return "InstantDDLCapabilityPossible" if there is one or more diffs that is capable of
// ALGORITHM=INSTANT, and zero or more diffs that are irrelevant.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be simpler and more clear to say that we return "InstantDDLCapabilityPossible" if there are no diffs which are impossible to run with ALGORITHM=INSTANT? They're both saying the same thing, AFAICT, but it feels easier to parse. I think it's also more precise because you could have:

if there is one or more diffs that is capable of
	// ALGORITHM=INSTANT, and zero or more diffs that are irrelevant.`

But ALSO have one more more that are impossible. No? It's obviously minor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it be simpler and more clear to say that we return "InstantDDLCapabilityPossible" if there are no diffs which are impossible to run with ALGORITHM=INSTANT?

The distinction we're trying to make is between "there's nothing relevant to INSTANT" and "there's nothing to prevent an INSTANT".

Example to the first would be a change with only a bunch of CREATE and DROP statements. None of them are "impossible" for INSTANT, but they're all just irrelevant. For this diff, you can technically say it's eligigle for INSTANT, but that's also misleading. There would be nothing to do. You cannot improve, change, or hasten the migrations in any way.

Example to the second is a bunch of CREATE and DROP, and one ALTER TABLE ... ADD COLUMN. Here, as a whole, we say that it's possible to run INSTANT DDL. There is an actual different course of action to the diff as a whole, if we apply ALGORITHM=INSTANT.

The distinction is really important, because we want to be able to look at a diff and say "hey, if you want this diff to run faster, you could add ALGORITHM=INSTANT". This kind of suggestion would be misleading in the 1st example, and beneficial in the 2nd example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But ALSO have one more more that are impossible. No? It's obviously minor.

Yes, clarified in code comment.

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>
@shlomi-noach
Copy link
Contributor Author

shlomi-noach commented Jan 9, 2024

@mattlord I've refactored go/mysql/* a bit to move version-capabilities logic into go/mysql/capabilities. This actually unifies logic from mysql57, mysql80 and mysqlGR flavors into a single MySQL-specific function.

Please take another look. Refactor is in 27bbd7a

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>
Copy link

codecov bot commented Jan 14, 2024

Codecov Report

Attention: 17 lines in your changes are missing coverage. Please review.

Comparison is base (1b328bf) 47.28% compared to head (d3f4677) 47.29%.

Files Patch % Lines
go/mysql/capabilities/capability.go 89.09% 6 Missing ⚠️
go/vt/schemadiff/table.go 54.54% 4 Missing and 1 partial ⚠️
go/vt/schemadiff/schema.go 76.92% 2 Missing and 1 partial ⚠️
go/vt/schemadiff/schema_diff.go 85.71% 2 Missing ⚠️
go/mysql/flavor.go 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14900      +/-   ##
==========================================
+ Coverage   47.28%   47.29%   +0.01%     
==========================================
  Files        1138     1139       +1     
  Lines      238842   238845       +3     
==========================================
+ Hits       112925   112972      +47     
+ Misses     117326   117282      -44     
  Partials     8591     8591              

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

@shlomi-noach
Copy link
Contributor Author

Gonna merge this shortly so I can start using the new functionality.

@mattlord
Copy link
Contributor

@mattlord I've refactored go/mysql/* a bit to move version-capabilities logic into go/mysql/capabilities. This actually unifies logic from mysql57, mysql80 and mysqlGR flavors into a single MySQL-specific function.

Please take another look. Refactor is in 27bbd7a

LGTM!

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 merged commit a207a69 into vitessio:main Jan 18, 2024
102 checks passed
@shlomi-noach shlomi-noach deleted the schemadiff-instant-info branch January 18, 2024 05:34
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) 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