-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-18.0] VDiff: "show all" should only report vdiffs for the sp…
…ecified keyspace and workflow (#14442) (#14466) Signed-off-by: Rohit Nayak <rohit@planetscale.com> Signed-off-by: Matt Lord <mattalord@gmail.com> Signed-off-by: deepthi <deepthi@planetscale.com> Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com> Co-authored-by: Matt Lord <mattalord@gmail.com> Co-authored-by: deepthi <deepthi@planetscale.com>
- Loading branch information
1 parent
4b8f49f
commit 4d248ec
Showing
6 changed files
with
193 additions
and
9 deletions.
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" | ||
) | ||
|
||
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
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