-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
VReplication: extended e2e test for workflows with tables containing foreign key constraints #14327
Conversation
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
13cf85f
to
5e0ee68
Compare
7a43ef8
to
a7eae29
Compare
89b98f5
to
f338ef2
Compare
…or Reshard VDiffs Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]> Working test upto reverse traffic in import, with load stopped before switch traffic Signed-off-by: Rohit Nayak <[email protected]> Working import with vtctl, vtctld still failing. VDiff concurrency bug fixes Signed-off-by: Rohit Nayak <[email protected]> Add new FKExt workflow to CI Signed-off-by: Rohit Nayak <[email protected]> Moving tables from one keyspace to another after importing works, but not if replica constraints are dropped Signed-off-by: Rohit Nayak <[email protected]> Working materialize. Still dropping replica constraints doesn't work Signed-off-by: Rohit Nayak <[email protected]> Some cleanup Signed-off-by: Rohit Nayak <[email protected]> Drop replica constraints correctly. This fixes previously failing reverse workflows during the move to keyspaces. Materialize also works Signed-off-by: Rohit Nayak <[email protected]> Fix failing VDiff2 test Signed-off-by: Rohit Nayak <[email protected]> Fix shard name for the vreplication foreign key stress test Signed-off-by: Rohit Nayak <[email protected]> Fix issue with vtctld switch writes. All current workflows work Signed-off-by: Rohit Nayak <[email protected]> WIP Signed-off-by: Rohit Nayak <[email protected]> Reshard working for split/merge and merge. We think, because vdiff is giving some strange errors Signed-off-by: Rohit Nayak <[email protected]> Better retry and error handling. However vdiffs seem to be an issue Signed-off-by: Rohit Nayak <[email protected]> Use vdiff v1 which seems to work fine during reshard Signed-off-by: Rohit Nayak <[email protected]> Revert bug fixes that have been fixed in separate PRs Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
…failing for some reason. Additional logging to debug vdiff issue Signed-off-by: Rohit Nayak <[email protected]>
…and reverse workflows Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
…ys, since deferForeignKeys cannot be used for schemas with foreign keys Signed-off-by: Rohit Nayak <[email protected]>
f338ef2
to
15f768b
Compare
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this! This is great. In addition to all the bugs that it uncovered during the work, it will help to catch new things going forward. ❤️
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
Signed-off-by: Matt Lord <[email protected]>
…rectly Signed-off-by: Rohit Nayak <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! I have a couple questions where I don't understand the logic. Specifically one in fk_ext_test.go
and one in vplayer.go
.
if vp.vr.WorkflowSubType == int32(binlogdatapb.VReplicationWorkflowSubType_AtomicCopy) { | ||
// If this is an atomic copy, we must update the foreign_key_checks state even when the vplayer runs during | ||
// the copy phase, i.e., for catchup and fastforward. | ||
mustUpdate = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just curious, and want to understand the logic better. Why do we need to always update FK checks in atomic-copy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In atomic-copy
workflows we run with foreign_key_checks=on
by default, but not for regular workflows.
During catchup/fastforward, we may get a transaction that sets foreign_key_checks=off
. So we need to set the state, otherwise the transactions will fail. If not running in atomic_copy
the checks are off always.
@@ -65,8 +71,31 @@ func execMultipleQueries(t *testing.T, conn *mysql.Conn, database string, lines | |||
execVtgateQuery(t, conn, database, string(query)) | |||
} | |||
} | |||
|
|||
func execQueryWithRetry(t *testing.T, conn *mysql.Conn, query string, timeout time.Duration) *sqltypes.Result { | |||
timer := time.NewTimer(timeout) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not very important, ignore if you like; I prefer this model:
ctx, cancel := context.WithTimeout(ctx.Background(), timeout)
defer cancel()
ticker := time.NewTicker(defaultTick)
defer ticker.Stop()
for {
...
select {
case <- ctx.Done():
...
case <-ticker.C:
...
}
...
This way the timeout overrides the tick's sleep.
Anyway, just a styling comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modified to use the suggested pattern.
func getRowCount(t *testing.T, vtgateConn *mysql.Conn, table string) (int, error) { | ||
query := fmt.Sprintf("select count(*) from %s", table) | ||
qr := execVtgateQuery(t, vtgateConn, "", query) | ||
if qr == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
execVtgateQuery
calls execQuery
which runs require.NoError(t, err)
In which case qr
cannot be nil
, and this function does not need to return an error
type, just as execQuery
does not return an error
type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed.
for { | ||
select { | ||
case <-ticker.C: | ||
if condition() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this implementation you necessarily first have to wait once for tickInterval
before checking condition()
. Is this intentional? Alternatively, move this block to run before the select
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already check the condition at the start of the function. So the next time should be after a tick.
@@ -0,0 +1,2 @@ | |||
create table if not exists parent(id int, name varchar(128), primary key(id)) engine=innodb; | |||
create table if not exists child(id int, parent_id int, name varchar(128), primary key(id), foreign key(parent_id) references parent(id) on delete cascade) engine=innodb; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the deal with if not exists
especially compared with materialize_schema.sql
which does not contain this clause?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use these queries with ApplySchema
while resharding for the entire keyspace, expecting it to only run on the new shards and be noops on existing ones. The materialize schema doesn't have this requirement.
|
||
t.Run("MoveTables from unsharded to sharded keyspace", func(t *testing.T) { | ||
// Migrate data from target1Keyspace to the sharded target2Keyspace. Streams only from primaries | ||
// for one shard and replica for the other shard. Constraints have been dropped from this replica. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what "Streams only from primaries for one shard and replica for the other shard" mean here, as we're importing from an unsharded keyspace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment was incorrect/ambiguous. They were in the context of the following materialize workflow which is from the sharded target2
to the unsharded target1
. I updated the comments to reflect that.
// the binlogs created by the primary. This will confirm that vtgate is doing the cascades correctly. | ||
func dropReplicaConstraints(t *testing.T, keyspaceName string, tablet *cluster.VttabletProcess) { | ||
var dropConstraints []string | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's require.Equal(...)
that the tablet type is REPLICA
(or non-primary).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
const getConstraintsQuery = ` | ||
SELECT CONSTRAINT_NAME, TABLE_NAME | ||
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE | ||
WHERE TABLE_SCHEMA = ` + "'%s'" + ` AND REFERENCED_TABLE_NAME IS NOT NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I see the need to break the string.
WHERE TABLE_SCHEMA = ` + "'%s'" + ` AND REFERENCED_TABLE_NAME IS NOT NULL; | |
WHERE TABLE_SCHEMA = `'%s'` AND REFERENCED_TABLE_NAME IS NOT NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Signed-off-by: Rohit Nayak <[email protected]>
Signed-off-by: Rohit Nayak <[email protected]>
…foreign key constraints (vitessio#14327) Signed-off-by: Rohit Nayak <[email protected]> Signed-off-by: Matt Lord <[email protected]> Co-authored-by: Matt Lord <[email protected]>
Description
This PR adds a more comprehensive end-to-end test for vreplication workflows with tables containing foreign keys. More details in the issue at #13954.
This also fixes a regression in
vplayer
caused by the new foreign key flag handling while playing binlog events. Previously we were not checking constraints during the copy phase and the new handling, which was intended only for the atomic copy mode, causes failures in the copy phase for schemas with table constraints. Fix at https://github.com/vitessio/vitess/pull/14327/files#diff-5b79231a161c35f368514ad138a743e3c74db9fe1fe0cece290e2377e9250a51L156The new e2e test has been added as a separate workflow for now to isolate issues and enable rerunning often, and also confirm that the test is not flaky before making it Required. Also, this test will be enhanced with additional load generators: like the one currently used in the fk stress test in vtgate, requiring this test to possibly be run on the larger runners.
The PR includes test framework changes that were needed since we now have a load generator that runs concurrently and needs to handle expected transient errors during traffic switching/vtgate buffering. For some reason VDIff Show also gives temporary connection errors, possibly related to buffering, which had to be ignored to prevent false positives in reported errors.
Related Issue(s)
Fixes #13954
Checklist
Deployment Notes