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 bugfix: make sure schema is applied on tablet #6910

Merged
merged 1 commit into from
Oct 22, 2020

Conversation

shlomi-noach
Copy link
Contributor

co-submission of #6909

This fixes a bug where the master tablet may be read_only when attempting to apply the online DDL schema (_vt.schema_migrations table).

With this PR we ensure schema is deployed before any online DDL operation.

It's noteworthy that we move away from WithDDL, which was meant to solve this exact problem, but is not strict enough. For this PR, we choose a smaller fix, but later on we may want to improve upon WithDDL.

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@@ -605,3 +605,20 @@ func IsConnErr(err error) bool {
}
return false
}

// IsSchemaApplyError returns true when given error is a MySQL error applying schema change
func IsSchemaApplyError(err error) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this error specific to the current use case? I'm wondering why you chose not to use withddl.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

withddl is flawed in that it only applies the schema when there's an error with the query. So, in my case, I ran a SELECT * on the tablet -- that didn't error, but the caller would error because it can't find expected columns.

What If I wanted to add an index? There's no error in the schema, withDDL will not invoke the ADD INDEX statement, but my performance degrades.

And on the flip side, what if I actually dropped a column? If my code no longer uses that column, withDDL will not see any problem and keep that column around.

Regardless, this new IsSchemaApplyError function covers more schema cases than withDDL currently does.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

e.initMutex.Lock()
defer e.initMutex.Unlock()

if e.schemaInitialized {
Copy link
Contributor

Choose a reason for hiding this comment

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

We are not allowed to assume that we've "done" something even if we did it. There is one use case where users restore an older snapshot of a mysql instance underneath us. This was the reason why we have to use withddl lazily. We can only know at the time of applying a DML.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is one use case where users restore an older snapshot of a mysql instance underneath us.

That's a good point.

Consider looking at how I solved this with orchestrator: it always knows what schema to deploy. See versionIsDeployed function in db.go, which writes down the git sha1 to the backend database.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -605,3 +605,20 @@ func IsConnErr(err error) bool {
}
return false
}

// IsSchemaApplyError returns true when given error is a MySQL error applying schema change
func IsSchemaApplyError(err error) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

e.initMutex.Lock()
defer e.initMutex.Unlock()

if e.schemaInitialized {
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@sougou sougou merged commit 50b2f10 into vitessio:master Oct 22, 2020
@shlomi-noach shlomi-noach deleted the online-ddl-schema-apply-fix branch October 22, 2020 05:42
@shlomi-noach
Copy link
Contributor Author

I will look into fixing withDDL. Meanwhile, more important is to merge #6909 for 8.0 -- it's better than current code, and I will iterate later.

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.

None yet

2 participants