-
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.
Move tables with atomic transactions (#16676)
Signed-off-by: Manan Gupta <[email protected]>
- Loading branch information
1 parent
9137c5b
commit b2ec6a5
Showing
7 changed files
with
245 additions
and
25 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
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(timeToWait time.Duration) { | ||
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), "", timeToWait) | ||
} | ||
} | ||
} |
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