Skip to content

Commit

Permalink
vdiff delete
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Sep 18, 2023
1 parent f1e4f26 commit 28850ac
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 235 deletions.
62 changes: 62 additions & 0 deletions go/cmd/vtctldclient/command/vreplication/vdiff/vdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ var (
AutoRetry bool
}{}

vDiffDeleteOptions = struct {
Arg string
}{}

vDiffShowOptions = struct {
Arg string
Verbose bool
Expand Down Expand Up @@ -125,6 +129,30 @@ See the --help output for each command for more details.`,
RunE: commandVDiffCreate,
}

// vDiffShow makes a VDiffDelete gRPC call to a vtctld.
vDiffDelete = &cobra.Command{
Use: "delete",
Short: "Delete VDiffs.",
Example: `vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace delete a037a9e2-5628-11ee-8c99-0242ac120002
vtctldclient --server localhost:15999 vdiff --workflow commerce2customer --target-keyspace delete all`,
DisableFlagsInUseLine: true,
Aliases: []string{"Delete"},
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
larg := strings.ToLower(args[0])
switch larg {
case "all":
default:
if _, err := uuid.Parse(args[0]); err != nil {
return fmt.Errorf("invalid UUID provided: %v", err)
}
}
vDiffDeleteOptions.Arg = larg
return nil
},
RunE: commandVDiffDelete,
}

// vDiffShow makes a VDiffShow gRPC call to a vtctld.
vDiffShow = &cobra.Command{
Use: "show",
Expand Down Expand Up @@ -198,6 +226,38 @@ func commandVDiffCreate(cmd *cobra.Command, args []string) error {
return nil
}

func commandVDiffDelete(cmd *cobra.Command, args []string) error {
format, err := common.GetOutputFormat(cmd)
if err != nil {
return err
}
cli.FinishedParsing(cmd)

resp, err := common.GetClient().VDiffDelete(common.GetCommandCtx(), &vtctldatapb.VDiffDeleteRequest{
Workflow: common.BaseOptions.Workflow,
TargetKeyspace: common.BaseOptions.TargetKeyspace,
Arg: vDiffDeleteOptions.Arg,
})

if err != nil {
return err
}

var data []byte
if format == "json" {
data, err = cli.MarshalJSON(resp)
if err != nil {
return err
}
} else {
data = []byte(resp.Status)
}

fmt.Printf("%s\n", data)

return nil
}

// Summary aggregates/selects the current state of the vdiff from all shards.
type vdiffTableSummary struct {
TableName string
Expand Down Expand Up @@ -666,6 +726,8 @@ func registerVDiffCommands(root *cobra.Command) {
vDiffCreate.Flags().Uint32Var(&vDiffCreateOptions.MaxExtraRowsToCompare, "max-extra-rows-to-compare", 1000, "If there are collation differences between the source and target, you can have rows that are identical but simply returned in a different order from MySQL. We will do a second pass to compare the rows for any actual differences in this case and this flag allows you to control the resources used for this operation.")
vDiff.AddCommand(vDiffCreate)

vDiff.AddCommand(vDiffDelete)

vDiffShow.Flags().BoolVar(&vDiffShowOptions.Verbose, "verbose", false, "Show verbose output in summaries")
vDiff.AddCommand(vDiffShow)
}
Expand Down
415 changes: 208 additions & 207 deletions go/vt/proto/vtctldata/vtctldata.pb.go

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions go/vt/proto/vtctldata/vtctldata_vtproto.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions go/vt/vtctl/grpcvtctldserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4706,6 +4706,21 @@ func (s *VtctldServer) VDiffCreate(ctx context.Context, req *vtctldatapb.VDiffCr
return resp, err
}

// VDiffDelete is part of the vtctlservicepb.VtctldServer interface.
func (s *VtctldServer) VDiffDelete(ctx context.Context, req *vtctldatapb.VDiffDeleteRequest) (resp *vtctldatapb.VDiffDeleteResponse, err error) {
span, ctx := trace.NewSpan(ctx, "VtctldServer.VDiffDelete")
defer span.Finish()

defer panicHandler(&err)

span.Annotate("keyspace", req.TargetKeyspace)
span.Annotate("workflow", req.Workflow)
span.Annotate("argument", req.Arg)

resp, err = s.ws.VDiffDelete(ctx, req)
return resp, err
}

// VDiffShow is part of the vtctlservicepb.VtctldServer interface.
func (s *VtctldServer) VDiffShow(ctx context.Context, req *vtctldatapb.VDiffShowRequest) (resp *vtctldatapb.VDiffShowResponse, err error) {
span, ctx := trace.NewSpan(ctx, "VtctldServer.VDiffShow")
Expand Down
41 changes: 41 additions & 0 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,6 +1371,47 @@ func (s *Server) VDiffCreate(ctx context.Context, req *vtctldatapb.VDiffCreateRe
}, nil
}

// VDiffDelete is part of the vtctlservicepb.VtctldServer interface.
func (s *Server) VDiffDelete(ctx context.Context, req *vtctldatapb.VDiffDeleteRequest) (*vtctldatapb.VDiffDeleteResponse, error) {
span, ctx := trace.NewSpan(ctx, "workflow.Server.VDiffDelete")
defer span.Finish()

span.Annotate("keyspace", req.TargetKeyspace)
span.Annotate("workflow", req.Workflow)
span.Annotate("argument", req.Arg)

tabletreq := &tabletmanagerdatapb.VDiffRequest{
Keyspace: req.TargetKeyspace,
Workflow: req.Workflow,
Action: string(vdiff.DeleteAction),
ActionArg: req.Arg,
}

ts, err := s.buildTrafficSwitcher(ctx, req.TargetKeyspace, req.Workflow)
if err != nil {
return nil, err
}

err = ts.ForAllTargets(func(target *MigrationTarget) error {
_, err := s.tmc.VDiff(ctx, target.GetPrimary().Tablet, tabletreq)
return err
})
if err != nil {
log.Errorf("Error executing action %s: %v", vdiff.CreateAction, err)
return nil, err
}
var status string
if req.Arg == "all" {
status = "Deleted all VDiffs"
} else {
status = fmt.Sprintf("Deleted VDiff %s", req.Arg)
}

return &vtctldatapb.VDiffDeleteResponse{
Status: status,
}, nil
}

// VDiffShow is part of the vtctlservicepb.VtctldServer interface.
func (s *Server) VDiffShow(ctx context.Context, req *vtctldatapb.VDiffShowRequest) (*vtctldatapb.VDiffShowResponse, error) {
span, ctx := trace.NewSpan(ctx, "workflow.Server.VDiffShow")
Expand Down
3 changes: 2 additions & 1 deletion proto/vtctldata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -1605,7 +1605,8 @@ message VDiffCreateResponse {
message VDiffDeleteRequest {
string workflow = 1;
string target_keyspace = 2;
string uuid = 3;
// This will be 'all' or a UUID.
string arg = 3;
}

message VDiffDeleteResponse {
Expand Down
8 changes: 4 additions & 4 deletions web/vtadmin/src/proto/vtadmin.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 15 additions & 15 deletions web/vtadmin/src/proto/vtadmin.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 28850ac

Please sign in to comment.