-
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
VDiff: "show all" should only report vdiffs for the specified keyspace and workflow #14442
Merged
deepthi
merged 7 commits into
vitessio:main
from
planetscale:rohit/vdiff-concurrent-movetables
Nov 4, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ddc569c
New test and logs to test if multiple vdiffs on concurrent movetables…
rohit-nayak-ps af93f1c
Show All should filter by passed keyspace and workflow
rohit-nayak-ps fb86f1e
Confirm that 'show all' returns the specific workflow. Add test to CI
rohit-nayak-ps 31539f0
Minor mods
rohit-nayak-ps a31a10c
Add unit test
mattlord 4d249be
Add show last test case as well
mattlord 4637603
add copyright to new test file
deepthi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
go/test/endtoend/vreplication/vdiff_multiple_movetables_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
Copyright 2023 The Vitess Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vreplication | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sync" | ||
"testing" | ||
"time" | ||
|
||
"github.com/tidwall/gjson" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
"vitess.io/vitess/go/vt/log" | ||
binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata" | ||
deepthi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
func TestMultipleConcurrentVDiffs(t *testing.T) { | ||
cellName := "zone" | ||
cells := []string{cellName} | ||
vc = NewVitessCluster(t, t.Name(), cells, mainClusterConfig) | ||
|
||
require.NotNil(t, vc) | ||
allCellNames = cellName | ||
defaultCellName := cellName | ||
defaultCell = vc.Cells[defaultCellName] | ||
sourceKeyspace := "product" | ||
shardName := "0" | ||
|
||
defer vc.TearDown(t) | ||
|
||
cell := vc.Cells[cellName] | ||
vc.AddKeyspace(t, []*Cell{cell}, sourceKeyspace, shardName, initialProductVSchema, initialProductSchema, 0, 0, 100, sourceKsOpts) | ||
|
||
vtgate = cell.Vtgates[0] | ||
require.NotNil(t, vtgate) | ||
err := cluster.WaitForHealthyShard(vc.VtctldClient, sourceKeyspace, shardName) | ||
require.NoError(t, err) | ||
vtgate.WaitForStatusOfTabletInShard(fmt.Sprintf("%s.%s.primary", sourceKeyspace, shardName), 1, 30*time.Second) | ||
|
||
vtgateConn = getConnection(t, vc.ClusterConfig.hostname, vc.ClusterConfig.vtgateMySQLPort) | ||
defer vtgateConn.Close() | ||
verifyClusterHealth(t, vc) | ||
|
||
insertInitialData(t) | ||
targetTabletId := 200 | ||
targetKeyspace := "customer" | ||
vc.AddKeyspace(t, []*Cell{cell}, targetKeyspace, shardName, initialProductVSchema, initialProductSchema, 0, 0, targetTabletId, sourceKsOpts) | ||
vtgate.WaitForStatusOfTabletInShard(fmt.Sprintf("%s.%s.primary", targetKeyspace, shardName), 1, 30*time.Second) | ||
|
||
index := 1000 | ||
var loadCtx context.Context | ||
var loadCancel context.CancelFunc | ||
loadCtx, loadCancel = context.WithCancel(context.Background()) | ||
load := func(tableName string) { | ||
query := "insert into %s(cid, name) values(%d, 'customer-%d')" | ||
for { | ||
select { | ||
case <-loadCtx.Done(): | ||
log.Infof("load cancelled") | ||
return | ||
default: | ||
index += 1 | ||
vtgateConn := getConnection(t, vc.ClusterConfig.hostname, vc.ClusterConfig.vtgateMySQLPort) | ||
q := fmt.Sprintf(query, tableName, index, index) | ||
vtgateConn.ExecuteFetch(q, 1000, false) | ||
vtgateConn.Close() | ||
} | ||
time.Sleep(10 * time.Millisecond) | ||
} | ||
} | ||
targetKs := vc.Cells[cellName].Keyspaces[targetKeyspace] | ||
targetTab := targetKs.Shards["0"].Tablets[fmt.Sprintf("%s-%d", cellName, targetTabletId)].Vttablet | ||
require.NotNil(t, targetTab) | ||
|
||
time.Sleep(15 * time.Second) // wait for some rows to be inserted. | ||
|
||
createWorkflow := func(workflowName, tables string) { | ||
mt := newMoveTables(vc, &moveTables{ | ||
workflowName: workflowName, | ||
targetKeyspace: targetKeyspace, | ||
sourceKeyspace: sourceKeyspace, | ||
tables: tables, | ||
}, moveTablesFlavorVtctld) | ||
mt.Create() | ||
waitForWorkflowState(t, vc, fmt.Sprintf("%s.%s", targetKeyspace, workflowName), binlogdatapb.VReplicationWorkflowState_Running.String()) | ||
catchup(t, targetTab, workflowName, "MoveTables") | ||
} | ||
|
||
createWorkflow("wf1", "customer") | ||
createWorkflow("wf2", "customer2") | ||
|
||
go load("customer") | ||
go load("customer2") | ||
|
||
var wg sync.WaitGroup | ||
wg.Add(2) | ||
|
||
doVdiff := func(workflowName, table string) { | ||
defer wg.Done() | ||
vdiff(t, targetKeyspace, workflowName, cellName, true, false, nil) | ||
} | ||
go doVdiff("wf1", "customer") | ||
go doVdiff("wf2", "customer2") | ||
wg.Wait() | ||
loadCancel() | ||
|
||
// confirm that show all shows the correct workflow and only that workflow. | ||
output, err := vc.VtctldClient.ExecuteCommandWithOutput("VDiff", "--format", "json", "--workflow", "wf1", "--target-keyspace", "customer", "show", "all") | ||
require.NoError(t, err) | ||
log.Infof("VDiff output: %s", output) | ||
count := gjson.Get(output, "..#").Int() | ||
wf := gjson.Get(output, "0.Workflow").String() | ||
ksName := gjson.Get(output, "0.Keyspace").String() | ||
require.Equal(t, int64(1), count) | ||
require.Equal(t, "wf1", wf) | ||
require.Equal(t, "customer", ksName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,8 @@ const ( | |
DeleteAction VDiffAction = "delete" | ||
AllActionArg = "all" | ||
LastActionArg = "last" | ||
|
||
maxVDiffsToReport = 100 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably worth adding a flag for this. But we can do it later if needed. |
||
) | ||
|
||
var ( | ||
|
@@ -267,13 +269,13 @@ func (vde *Engine) handleCreateResumeAction(ctx context.Context, dbClient binlog | |
|
||
func (vde *Engine) handleShowAction(ctx context.Context, dbClient binlogplayer.DBClient, action VDiffAction, req *tabletmanagerdatapb.VDiffRequest, resp *tabletmanagerdatapb.VDiffResponse) error { | ||
var qr *sqltypes.Result | ||
var err error | ||
vdiffUUID := "" | ||
|
||
if req.ActionArg == LastActionArg { | ||
query, err := sqlparser.ParseAndBind(sqlGetMostRecentVDiff, | ||
query, err := sqlparser.ParseAndBind(sqlGetMostRecentVDiffByKeyspaceWorkflow, | ||
sqltypes.StringBindVariable(req.Keyspace), | ||
sqltypes.StringBindVariable(req.Workflow), | ||
sqltypes.Int64BindVariable(1), | ||
) | ||
if err != nil { | ||
return err | ||
|
@@ -322,7 +324,15 @@ func (vde *Engine) handleShowAction(ctx context.Context, dbClient binlogplayer.D | |
} | ||
switch req.ActionArg { | ||
case AllActionArg: | ||
if qr, err = dbClient.ExecuteFetch(sqlGetAllVDiffs, -1); err != nil { | ||
query, err := sqlparser.ParseAndBind(sqlGetMostRecentVDiffByKeyspaceWorkflow, | ||
sqltypes.StringBindVariable(req.Keyspace), | ||
sqltypes.StringBindVariable(req.Workflow), | ||
sqltypes.Int64BindVariable(maxVDiffsToReport), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
if qr, err = dbClient.ExecuteFetch(query, -1); err != nil { | ||
return err | ||
} | ||
resp.Output = sqltypes.ResultToProto3(qr) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 could instead/additionally add a
show all
test case toTestPerformVDiffAction
. I just pushed one. We can keep or remove the e2e test, up to you. IMO we can remove it.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.
Thanks for adding the unit test. I looked at those tests first, but wanted to actually test multiple vdiffs for concurrent workflows in the same keyspace and test if that works.
We don't seem to have any current e2e test that has multiple active workflows and vdiffs run on them. Hence the e2e test. I want to expand that soon to test the state changes in the concurrent workflows and run vdiffs on them, etc.