Skip to content

Commit

Permalink
VReplication Workflow command: Allow stop/start on specific shards (#…
Browse files Browse the repository at this point in the history
…17581)

Signed-off-by: Rohit Nayak <[email protected]>
  • Loading branch information
rohit-nayak-ps authored Jan 22, 2025
1 parent 99856a2 commit 55b6865
Show file tree
Hide file tree
Showing 8 changed files with 413 additions and 278 deletions.
4 changes: 4 additions & 0 deletions go/cmd/vtctldclient/command/vreplication/workflow/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ func commandUpdateState(cmd *cobra.Command, args []string) error {
cli.FinishedParsing(cmd)

var state binlogdatapb.VReplicationWorkflowState
var shards []string
switch strings.ToLower(cmd.Name()) {
case "start":
if err := common.CanRestartWorkflow(baseOptions.Keyspace, baseOptions.Workflow); err != nil {
return err
}
state = binlogdatapb.VReplicationWorkflowState_Running
shards = baseOptions.Shards
case "stop":
state = binlogdatapb.VReplicationWorkflowState_Stopped
shards = baseOptions.Shards
default:
return fmt.Errorf("invalid workflow state: %s", args[0])
}
Expand All @@ -80,6 +83,7 @@ func commandUpdateState(cmd *cobra.Command, args []string) error {
Cells: textutil.SimulatedNullStringSlice,
TabletTypes: textutil.SimulatedNullTabletTypeSlice,
State: &state,
Shards: shards,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"testing"

"github.com/stretchr/testify/require"
"github.com/tidwall/gjson"
"golang.org/x/exp/maps"
"google.golang.org/protobuf/encoding/protojson"

Expand Down Expand Up @@ -501,6 +502,28 @@ func splitShard(t *testing.T, keyspace, workflowName, sourceShards, targetShards
waitForWorkflowState(t, vc, ksWorkflow, binlogdatapb.VReplicationWorkflowState_Stopped.String())
rs.Start()
waitForWorkflowState(t, vc, fmt.Sprintf("%s.%s", keyspace, workflowName), binlogdatapb.VReplicationWorkflowState_Running.String())

t.Run("Test --shards in workflow start/stop", func(t *testing.T) {
// This subtest expects workflow to be running at the start and restarts it at the end.
type tCase struct {
shards string
action string
expected int
}
testCases := []tCase{
{"-40", "stop", 1},
{"40-80", "stop", 1},
{"-40,40-80", "start", 2},
}
for _, tc := range testCases {
output, err := vc.VtctldClient.ExecuteCommandWithOutput("workflow", "--keyspace", keyspace, tc.action, "--workflow", workflowName, "--shards", tc.shards)
require.NoError(t, err, "failed to %s workflow: %v", tc.action, err)
cnt := gjson.Get(output, "details.#").Int()
require.EqualValuesf(t, tc.expected, cnt, "expected %d shards, got %d for action %s, shards %s", tc.expected, cnt, tc.action, tc.shards)
}
})
waitForWorkflowState(t, vc, fmt.Sprintf("%s.%s", keyspace, workflowName), binlogdatapb.VReplicationWorkflowState_Running.String())

for _, targetTab := range targetTabs {
catchup(t, targetTab, workflowName, "Reshard")
}
Expand Down
563 changes: 286 additions & 277 deletions go/vt/proto/tabletmanagerdata/tabletmanagerdata.pb.go

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions go/vt/proto/tabletmanagerdata/tabletmanagerdata_vtproto.pb.go

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

2 changes: 2 additions & 0 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1719,8 +1719,10 @@ func (s *Server) WorkflowUpdate(ctx context.Context, req *vtctldatapb.WorkflowUp
span.Annotate("on_ddl", req.TabletRequest.OnDdl)
span.Annotate("state", req.TabletRequest.State)
span.Annotate("config_overrides", req.TabletRequest.ConfigOverrides)
span.Annotate("shards", req.TabletRequest.Shards)

vx := vexec.NewVExec(req.Keyspace, req.TabletRequest.Workflow, s.ts, s.tmc, s.env.Parser())
vx.SetShardSubset(req.TabletRequest.Shards)
callback := func(ctx context.Context, tablet *topo.TabletInfo) (*querypb.QueryResult, error) {
res, err := s.tmc.UpdateVReplicationWorkflow(ctx, tablet.Tablet, req.TabletRequest)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion proto/tabletmanagerdata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ message UpdateVReplicationWorkflowRequest {
optional TabletSelectionPreference tablet_selection_preference = 4;
optional binlogdata.OnDDLAction on_ddl = 5;
optional binlogdata.VReplicationWorkflowState state = 6;
reserved 7; // unused, was: repeated string shards
repeated string shards = 7;
map<string, string> config_overrides = 8;
optional string message = 9;
}
Expand Down
6 changes: 6 additions & 0 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.

39 changes: 39 additions & 0 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 55b6865

Please sign in to comment.