-
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.
feat: run move tables in stress test
Signed-off-by: Manan Gupta <[email protected]>
- Loading branch information
1 parent
d916e81
commit 07dee3c
Showing
4 changed files
with
144 additions
and
12 deletions.
There are no files selected for viewing
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,94 @@ | ||
/* | ||
Copyright 2024 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 cluster | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
"time" | ||
) | ||
|
||
// MoveTablesWorkflow is used to store the information needed to run | ||
// MoveTables commands. | ||
type MoveTablesWorkflow struct { | ||
t *testing.T | ||
clusterInstance *LocalProcessCluster | ||
workflowName string | ||
targetKs string | ||
srcKs string | ||
tables string | ||
} | ||
|
||
// NewMoveTables creates a new MoveTablesWorkflow. | ||
func NewMoveTables(t *testing.T, clusterInstance *LocalProcessCluster, workflowName, targetKs, srcKs, tables string) *MoveTablesWorkflow { | ||
return &MoveTablesWorkflow{ | ||
t: t, | ||
clusterInstance: clusterInstance, | ||
workflowName: workflowName, | ||
tables: tables, | ||
targetKs: targetKs, | ||
srcKs: srcKs, | ||
} | ||
} | ||
|
||
func (mtw *MoveTablesWorkflow) Create() (string, error) { | ||
args := []string{"Create", "--source-keyspace=" + mtw.srcKs} | ||
if mtw.tables != "" { | ||
args = append(args, "--tables="+mtw.tables) | ||
} else { | ||
args = append(args, "--all-tables") | ||
} | ||
return mtw.exec(args...) | ||
} | ||
|
||
func (mtw *MoveTablesWorkflow) exec(args ...string) (string, error) { | ||
args2 := []string{"MoveTables", "--workflow=" + mtw.workflowName, "--target-keyspace=" + mtw.targetKs} | ||
args2 = append(args2, args...) | ||
return mtw.clusterInstance.VtctldClientProcess.ExecuteCommandWithOutput(args2...) | ||
} | ||
|
||
func (mtw *MoveTablesWorkflow) SwitchReadsAndWrites() (string, error) { | ||
return mtw.exec("SwitchTraffic") | ||
} | ||
|
||
func (mtw *MoveTablesWorkflow) ReverseReadsAndWrites() (string, error) { | ||
return mtw.exec("ReverseTraffic") | ||
} | ||
|
||
func (mtw *MoveTablesWorkflow) Cancel() (string, error) { | ||
return mtw.exec("Cancel") | ||
} | ||
|
||
func (mtw *MoveTablesWorkflow) Complete() (string, error) { | ||
return mtw.exec("Complete") | ||
} | ||
|
||
func (mtw *MoveTablesWorkflow) Show() (string, error) { | ||
return mtw.exec("Show") | ||
} | ||
|
||
func (mtw *MoveTablesWorkflow) WaitForVreplCatchup() { | ||
for _, ks := range mtw.clusterInstance.Keyspaces { | ||
if ks.Name != mtw.targetKs { | ||
continue | ||
} | ||
for _, shard := range ks.Shards { | ||
vttablet := shard.PrimaryTablet().VttabletProcess | ||
vttablet.WaitForVReplicationToCatchup(mtw.t, mtw.workflowName, fmt.Sprintf("vt_%s", vttablet.Keyspace), "", 10*time.Second) | ||
} | ||
} | ||
} |
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