Skip to content

Commit 5b317c5

Browse files
committed
VReplication: Add reference-tables to existing workflow
Signed-off-by: Noble Mittal <[email protected]>
1 parent 4c27ea8 commit 5b317c5

File tree

18 files changed

+4464
-2924
lines changed

18 files changed

+4464
-2924
lines changed

go/cmd/vtctldclient/command/vreplication/materialize/materialize.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@ package materialize
1818

1919
import (
2020
"fmt"
21+
"strings"
2122

2223
"github.com/spf13/cobra"
2324

2425
"vitess.io/vitess/go/cmd/vtctldclient/command/vreplication/common"
2526
"vitess.io/vitess/go/mysql/config"
2627
"vitess.io/vitess/go/vt/topo/topoproto"
28+
29+
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
2730
)
2831

2932
var (
33+
addReferenceTablesOptions = struct {
34+
Tables []string
35+
}{}
36+
3037
// base is the base command for all actions related to Materialize.
3138
base = &cobra.Command{
3239
Use: "Materialize --workflow <workflow> --target-keyspace <keyspace> [command] [command-flags]",
@@ -35,8 +42,31 @@ var (
3542
Aliases: []string{"materialize"},
3643
Args: cobra.ExactArgs(1),
3744
}
45+
46+
// addReferenceTables makes a MaterializeAddTables gRPC call to a vtctld.
47+
addReferenceTables = &cobra.Command{
48+
Use: "add-reference-tables --tables='table1,table2'",
49+
Short: "Add reference tables to the existing materialize workflow",
50+
Aliases: []string{"Add-Reference-Tables"},
51+
Args: cobra.NoArgs,
52+
RunE: commandAddReferenceTables,
53+
}
3854
)
3955

56+
func commandAddReferenceTables(cmd *cobra.Command, args []string) error {
57+
_, err := common.GetClient().MaterializeAddTables(common.GetCommandCtx(), &vtctldatapb.MaterializeAddTablesRequest{
58+
Workflow: common.BaseOptions.Workflow,
59+
Keyspace: common.BaseOptions.TargetKeyspace,
60+
Tables: addReferenceTablesOptions.Tables,
61+
})
62+
if err != nil {
63+
return err
64+
}
65+
fmt.Printf("Reference table(s) %s added to the workflow %s. Use show to view the status.\n",
66+
strings.Join(addReferenceTablesOptions.Tables, ", "), common.BaseOptions.Workflow)
67+
return nil
68+
}
69+
4070
func registerCommands(root *cobra.Command) {
4171
common.AddCommonFlags(base)
4272
root.AddCommand(base)
@@ -54,6 +84,10 @@ func registerCommands(root *cobra.Command) {
5484
create.Flags().StringSliceVarP(&common.CreateOptions.ReferenceTables, "reference-tables", "r", nil, "Used to specify the reference tables to materialize on every target shard.")
5585
base.AddCommand(create)
5686

87+
addReferenceTables.Flags().StringSliceVar(&addReferenceTablesOptions.Tables, "tables", nil, "Used to specify the reference tables to be added to the existing workflow")
88+
addReferenceTables.MarkFlagRequired("tables")
89+
base.AddCommand(addReferenceTables)
90+
5791
// Generic workflow commands.
5892
opts := &common.SubCommandsOpts{
5993
SubCommand: "Materialize",

go/vt/proto/tabletmanagerdata/tabletmanagerdata.pb.go

Lines changed: 317 additions & 302 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/vt/proto/tabletmanagerdata/tabletmanagerdata_vtproto.pb.go

Lines changed: 59 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)