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

Towards a VReplication/OnlineDDL testing suite #8181

Merged

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented May 25, 2021

Setting up a VReplication testing suite.

Initial commit: support for ddl_strategy '-vreplication-test-suite', which renames both tables on cut-over to names inaccessible to the app

e.g. if table name is mytable, then we end up with mytable_before and mytable_after. The app (and the scripts executed by the test suite) knows nothing about those tables and therefore cannot make changes to those tabes. This means both tables are frozen in time at the moment of cut-over, and this means they can be compared without interference. And that's how the suite validates that the migration is correct: by comparing table data.

Related Issue(s)

Checklist

  • Tests were added or are not required
  • Documentation was added or is not required

Deployment Notes

…th tables on cut-over to names inaccessible to the app, paving the way for a reliable test suite

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
…ast 5 seconds

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>
…e.g. via an internal EVENT), we need to cut-over using two-step, to hard-hide the original table

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 May 26, 2021

Ready for review

Suite is now working: https://github.com/vitessio/vitess/pull/8181/checks?check_run_id=2672882181

Main file is https://github.com/vitessio/vitess/pull/8181/files#diff-5b2f7e26e6a031b4098461528dca98e5ff630e70e1986f35efaab59f3fa5bd76, the endtoend test that runs the suite.
It is a translatoin of the test shell script https://github.com/vitessio/vitess/pull/8181/files#diff-fc1d6f6f07384c7c6b53fba52d16e64f5d3943d0ca1fcc8b4b4e4dd7df7982fb imported from gh-ost (which is kept for a while; I'll delete it later).

All tests files are under testdata: https://github.com/planetscale/vitess/tree/online-ddl-vreplication-test-suite/go/test/endtoend/onlineddl/vrepl_suite/testdata. Right now I only added two tests: one trivial that has to pass, and one that is expected to fail.

The rest of the tests are temporarily in untestdata: https://github.com/planetscale/vitess/tree/online-ddl-vreplication-test-suite/go/test/endtoend/onlineddl/vrepl_suite/untestdata. There's dozens of them, and I expect many to fail, if tested.

The objective is:

  • Approve and merge this PR with proof of concept of two working tests
  • Later, iterate the tests in untestdata and slowly move them to testdata. Anything that passes, great! Anything that fails: fix VReplication/OnlineDDL to make it pass...

@@ -106,6 +106,12 @@ func CheckCancelAllMigrations(t *testing.T, vtParams *mysql.ConnParams, expectCo
assert.Equal(t, expectCount, int(r.RowsAffected))
}

// ReadMigrations reads migration entries
func ReadMigrations(t *testing.T, vtParams *mysql.ConnParams, like string) *sqltypes.Result {
showQuery := fmt.Sprintf("show vitess_migrations like '%s'", like)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can I talk you into using sqlparser.TrackedBuffer for this? I don't think anybody is gonna do SQL injection in our integration test suite buuuut it's a good consistency habit to pick up :p

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm looking at Vitess code and I don't see sqlparser.TrackedBuffer widely used for encapsulating values; I see construction using sqlparser.NewStrLiteral, like in:

sql := "SELECT * FROM _vt.schema_migrations"
if show.Filter != nil {
if show.Filter.Filter != nil {
sql += fmt.Sprintf(" where %s", sqlparser.String(show.Filter.Filter))
} else if show.Filter.Like != "" {
lit := sqlparser.String(sqlparser.NewStrLiteral(show.Filter.Like))
sql += fmt.Sprintf(" where migration_uuid LIKE %s OR migration_context LIKE %s OR migration_status LIKE %s", lit, lit, lit)
}
}

Any thoughts on how to use TrackedBuffer to avoid SQL injection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten to use sqlparser.ParseAndBind()

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's the one! Sorry I didn't make it explicit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good good, thank you!

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

Request for review 🙏 I have more to come on this topic but don't want to overwhelm with a giant PR

@@ -0,0 +1,376 @@
/*
Copyright 2019 The Vitess Authors.
Copy link
Contributor

Choose a reason for hiding this comment

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

2021?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

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

some nits, otherwise lgtm


exitcode, err := func() (int, error) {
clusterInstance = cluster.NewCluster(cell, hostname)
schemaChangeDirectory = path.Join("/tmp", fmt.Sprintf("schema_change_dir_%d", clusterInstance.GetAndReserveTabletUID()))
Copy link
Contributor

Choose a reason for hiding this comment

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

ClusterInstance has a TmpDirectory parameter (based off of VTDATAROOT). Maybe using that here might be more consistent with the other tests. I have found that helps while debugging: if you comment out the teardown temporarily all transient files are then in the same root dir.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I inherited this schemaChangeDirectory variable, and am unsure how Vitess even uses it. Having said that, there's a problem with using suggested TmpDirectory:

  • TmpDirectory is only set in StartTopo()
  • StartTopo() requires that VtctldExtraArgs are set
  • VtctldExtraArgs rely on schemaChangeDirectory

so if we introduce schemaChangeDirectory = cluster.TmpDirectory there's a dependency loop.

I have no strong opinions (and really no opinions at all) on how this should be resolved. Even after reviewing the code I don't understand how SchemaChangeDirName is being used: it's used by LocalController -- I don't really understand what LocalController is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm gonna merge this PR with the nit still outstanding, and resolve TmpDirectory in a future PR 🙏

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
@shlomi-noach shlomi-noach merged commit f3bcf98 into vitessio:master May 31, 2021
@shlomi-noach shlomi-noach deleted the online-ddl-vreplication-test-suite branch May 31, 2021 11:45
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.

3 participants