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

OnlineDDL: avoid schema_migrations AUTO_INCREMENT gaps by pre-checking for existing migration #12169

Merged
merged 5 commits into from
Jan 31, 2023

Conversation

shlomi-noach
Copy link
Contributor

Description

Fixes #12168
This PR prevents excessive gaps in _vt.schema_migrations id values with a small refactor:

  • Instead of relying on INSERT IGNORE, we first SELECT for existing migration UUID, and only if it does not exist, we INSERT.
  • Because this is now a two-step logic, we add a mutex around the function (the mutex is only used by SubmitMigration function and does not otherwise conflict with the rest of the scheduler's work)
  • The logic that used to follow the INSERT IGNORE, which addresses the case where the UUID pre-existed, is now moved to run before INSERT IGNORE

Tests are unchanged. We expect no change in behavior.

Related Issue(s)

#12168

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

@shlomi-noach
Copy link
Contributor Author

converted to draft, doing another necessary refactor (need to take singleron/singleton-context scenario into consideration)

… logic applies both to migration submission as well as RetryMigration()

Signed-off-by: Shlomi Noach <[email protected]>
@shlomi-noach
Copy link
Contributor Author

OK, did another refactor; extracted an inner function, validateSingleton() and some logic around it, onto a new function, func (e *Executor) submitCallbackIfNonConflicting(). And this logic applies to either submitting a migration or retrying a migration. It validates whether it is OK for the given migration to retry/submit given singleton or singleton-context constraints.

@shlomi-noach shlomi-noach marked this pull request as ready for review January 26, 2023 07:42
@shlomi-noach shlomi-noach requested a review from a team January 26, 2023 11: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!

Not breaking any test would indicate that we probably don't have test coverage around submissions. 🙂 I think we should add more unit tests eventually (that could also e.g. confirm that we don't have gaps anymore when we resubmit) but that's a bigger issue and not specific to this work.

In the meantime, can we easily add anything to the endtoend tests to confirm the behavioral change? Perhaps a select at the end of a workflow to look for gaps in the migration IDs?

@mattlord mattlord added the Component: Online DDL Online DDL (vitess/native/gh-ost/pt-osc) label Jan 27, 2023
@shlomi-noach
Copy link
Contributor Author

Not breaking any test would indicate that we probably don't have test coverage around submissions.

The opposite is true. We have plenty tests around submissions -- every single test, really, and in particular all singleton and singleton-context tests -- literally hundreds.

@shlomi-noach
Copy link
Contributor Author

Perhaps a select at the end of a workflow to look for gaps in the migration IDs?

I'll look into that.

@mattlord
Copy link
Contributor

Not breaking any test would indicate that we probably don't have test coverage around submissions.

The opposite is true. We have plenty tests around submissions -- every single test, really, and in particular all singleton and singleton-context tests -- literally hundreds.

Yea, I meant code test coverage — i.e. unit tests. 🙂 Was just noting it (not a blocker).

@shlomi-noach
Copy link
Contributor Author

Added an explicit test to validate id values are sequential and without gaps; this test is now called at the end of multiple endtoend workflows.

@shlomi-noach shlomi-noach requested a review from a team January 29, 2023 06:38
@deepthi
Copy link
Member

deepthi commented Jan 31, 2023

request for review from @vitessio/query-serving

@GuptaManan100 GuptaManan100 mentioned this pull request Jan 31, 2023
35 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OnlineDDL: _vt.schema_migrations AUTO_INCREMENT can have substantial gaps
5 participants