Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-19.0] VReplication: Fix workflow update changed handling (#15621) #15629

Merged
merged 2 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func commandUpdateState(cmd *cobra.Command, args []string) error {
TabletTypes: []topodatapb.TabletType{topodatapb.TabletType(textutil.SimulatedNullInt)},
OnDdl: binlogdatapb.OnDDLAction(textutil.SimulatedNullInt),
State: state,
Shards: baseOptions.Shards,
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
TabletTypes: updateOptions.TabletTypes,
TabletSelectionPreference: tsp,
OnDdl: binlogdatapb.OnDDLAction(onddl),
Shards: baseOptions.Shards,
State: binlogdatapb.VReplicationWorkflowState(textutil.SimulatedNullInt), // We don't allow changing this in the client command

Check warning on line 114 in go/cmd/vtctldclient/command/vreplication/workflow/update.go

View check run for this annotation

Codecov / codecov/patch

go/cmd/vtctldclient/command/vreplication/workflow/update.go#L114

Added line #L114 was not covered by tests
},
}

Expand Down
31 changes: 28 additions & 3 deletions go/test/endtoend/vreplication/resharding_workflows_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/encoding/protojson"

"vitess.io/vitess/go/test/endtoend/cluster"
"vitess.io/vitess/go/vt/log"
"vitess.io/vitess/go/vt/wrangler"

binlogdatapb "vitess.io/vitess/go/vt/proto/binlogdata"
vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata"
)

const (
Expand Down Expand Up @@ -212,19 +214,42 @@ func tstWorkflowComplete(t *testing.T) error {
// to primary,replica,rdonly (the only applicable types in these tests).
func testWorkflowUpdate(t *testing.T) {
tabletTypes := "primary,replica,rdonly"
// Test vtctlclient first
// Test vtctlclient first.
_, err := vc.VtctlClient.ExecuteCommandWithOutput("workflow", "--", "--tablet-types", tabletTypes, "noexist.noexist", "update")
require.Error(t, err, err)
resp, err := vc.VtctlClient.ExecuteCommandWithOutput("workflow", "--", "--tablet-types", tabletTypes, ksWorkflow, "update")
require.NoError(t, err)
require.NotEmpty(t, resp)

// Test vtctldclient last
// Test vtctldclient last.
_, err = vc.VtctldClient.ExecuteCommandWithOutput("workflow", "--keyspace", "noexist", "update", "--workflow", "noexist", "--tablet-types", tabletTypes)
require.Error(t, err)
// Change the tablet-types to rdonly.
resp, err = vc.VtctldClient.ExecuteCommandWithOutput("workflow", "--keyspace", targetKs, "update", "--workflow", workflowName, "--tablet-types", "rdonly")
require.NoError(t, err, err)
// Confirm that we changed the workflow.
var ures vtctldatapb.WorkflowUpdateResponse
require.NoError(t, err)
err = protojson.Unmarshal([]byte(resp), &ures)
require.NoError(t, err)
require.Greater(t, len(ures.Details), 0)
require.True(t, ures.Details[0].Changed)
// Change tablet-types back to primary,replica,rdonly.
resp, err = vc.VtctldClient.ExecuteCommandWithOutput("workflow", "--keyspace", targetKs, "update", "--workflow", workflowName, "--tablet-types", tabletTypes)
require.NoError(t, err, err)
require.NotEmpty(t, resp)
// Confirm that we changed the workflow.
err = protojson.Unmarshal([]byte(resp), &ures)
require.NoError(t, err)
require.Greater(t, len(ures.Details), 0)
require.True(t, ures.Details[0].Changed)
// Execute a no-op as tablet-types is already primary,replica,rdonly.
resp, err = vc.VtctldClient.ExecuteCommandWithOutput("workflow", "--keyspace", targetKs, "update", "--workflow", workflowName, "--tablet-types", tabletTypes)
require.NoError(t, err, err)
// Confirm that we didn't change the workflow.
err = protojson.Unmarshal([]byte(resp), &ures)
require.NoError(t, err)
require.Greater(t, len(ures.Details), 0)
require.False(t, ures.Details[0].Changed)
}

func tstWorkflowCancel(t *testing.T) error {
Expand Down
87 changes: 42 additions & 45 deletions go/vt/proto/tabletmanagerdata/tabletmanagerdata.pb.go

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

52 changes: 0 additions & 52 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.

1 change: 1 addition & 0 deletions go/vt/vtctl/vtctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -3829,6 +3829,7 @@
TabletTypes: tabletTypes,
TabletSelectionPreference: tsp,
OnDdl: binlogdatapb.OnDDLAction(onddl),
State: binlogdatapb.VReplicationWorkflowState(textutil.SimulatedNullInt), // We don't allow changing this in the client command

Check warning on line 3832 in go/vt/vtctl/vtctl.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vtctl/vtctl.go#L3832

Added line #L3832 was not covered by tests
}
}
results, err = wr.WorkflowAction(ctx, workflow, keyspace, action, *dryRun, rpcReq, *shards) // Only update currently uses the new RPC path
Expand Down
2 changes: 0 additions & 2 deletions go/vt/vtctl/workflow/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2235,10 +2235,8 @@ func (s *Server) WorkflowUpdate(ctx context.Context, req *vtctldatapb.WorkflowUp
span.Annotate("tablet_types", req.TabletRequest.TabletTypes)
span.Annotate("on_ddl", req.TabletRequest.OnDdl)
span.Annotate("state", req.TabletRequest.State)
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
4 changes: 3 additions & 1 deletion go/vt/vttablet/tabletmanager/rpc_vreplication.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
return &tabletmanagerdatapb.UpdateVReplicationWorkflowResponse{Result: nil}, nil
}

rowsAffected := uint64(0)
for _, row := range res.Named().Rows {
id := row.AsInt64("id", 0)
cells := strings.Split(row.AsString("cell", ""), ",")
Expand Down Expand Up @@ -317,11 +318,12 @@
if err != nil {
return nil, err
}
rowsAffected += res.RowsAffected

Check warning on line 321 in go/vt/vttablet/tabletmanager/rpc_vreplication.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vttablet/tabletmanager/rpc_vreplication.go#L321

Added line #L321 was not covered by tests
}

return &tabletmanagerdatapb.UpdateVReplicationWorkflowResponse{
Result: &querypb.QueryResult{
RowsAffected: uint64(len(res.Rows)),
RowsAffected: rowsAffected,

Check warning on line 326 in go/vt/vttablet/tabletmanager/rpc_vreplication.go

View check run for this annotation

Codecov / codecov/patch

go/vt/vttablet/tabletmanager/rpc_vreplication.go#L326

Added line #L326 was not covered by tests
},
}, nil
}
Expand Down
8 changes: 7 additions & 1 deletion proto/tabletmanagerdata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -631,14 +631,20 @@ message VDiffOptions {
VDiffReportOptions report_options = 3;
}

// UpdateVReplicationWorkflowRequest is used to update an existing VReplication
// workflow. Note that the following fields MUST have an explicit value provided
// if you do NOT wish to update the existing value to the given type's ZeroValue:
// cells, tablet_types, on_ddl, and state.
// TODO: leverage the optional modifier for these fields rather than using SimulatedNull
// values: https://github.com/vitessio/vitess/issues/15627
message UpdateVReplicationWorkflowRequest {
string workflow = 1;
repeated string cells = 2;
repeated topodata.TabletType tablet_types = 3;
TabletSelectionPreference tablet_selection_preference = 4;
binlogdata.OnDDLAction on_ddl = 5;
binlogdata.VReplicationWorkflowState state = 6;
repeated string shards = 7;
reserved 7; // unused, was: repeated string shards
}

message UpdateVReplicationWorkflowResponse {
Expand Down
6 changes: 0 additions & 6 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.

Loading
Loading