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

VTAdmin: Add support for Create Reshard #16903

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1,748 changes: 916 additions & 832 deletions go/vt/proto/vtadmin/vtadmin.pb.go

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions go/vt/proto/vtadmin/vtadmin_grpc.pb.go

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

205 changes: 205 additions & 0 deletions go/vt/proto/vtadmin/vtadmin_vtproto.pb.go

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

20 changes: 20 additions & 0 deletions go/vt/vtadmin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ func (api *API) Handler() http.Handler {
router.HandleFunc("/workflow/{cluster_id}/{keyspace}/{name}/start", httpAPI.Adapt(vtadminhttp.StartWorkflow)).Name("API.StartWorkflow")
router.HandleFunc("/workflow/{cluster_id}/{keyspace}/{name}/stop", httpAPI.Adapt(vtadminhttp.StopWorkflow)).Name("API.StopWorkflow")
router.HandleFunc("/workflow/{cluster_id}/movetables", httpAPI.Adapt(vtadminhttp.MoveTablesCreate)).Name("API.MoveTablesCreate").Methods("POST")
router.HandleFunc("/workflow/{cluster_id}/reshard", httpAPI.Adapt(vtadminhttp.ReshardCreate)).Name("API.ReshardCreate").Methods("POST")

experimentalRouter := router.PathPrefix("/experimental").Subrouter()
experimentalRouter.HandleFunc("/tablet/{tablet}/debug/vars", httpAPI.Adapt(experimental.TabletDebugVarsPassthrough)).Name("API.TabletDebugVarsPassthrough")
Expand Down Expand Up @@ -1865,6 +1866,25 @@ func (api *API) MoveTablesCreate(ctx context.Context, req *vtadminpb.MoveTablesC
return c.Vtctld.MoveTablesCreate(ctx, req.Request)
}

// ReshardCreate is part of the vtadminpb.VTAdminServer interface.
func (api *API) ReshardCreate(ctx context.Context, req *vtadminpb.ReshardCreateRequest) (*vtctldatapb.WorkflowStatusResponse, error) {
span, ctx := trace.NewSpan(ctx, "API.ReshardCreate")
defer span.Finish()

span.Annotate("cluster_id", req.ClusterId)

if !api.authz.IsAuthorized(ctx, req.ClusterId, rbac.WorkflowResource, rbac.CreateAction) {
return nil, fmt.Errorf("%w: cannot create workflow in %s", errors.ErrUnauthorized, req.ClusterId)
}

c, err := api.getClusterForRequest(req.ClusterId)
if err != nil {
return nil, err
}

return c.Vtctld.ReshardCreate(ctx, req.Request)
}

// PingTablet is part of the vtadminpb.VTAdminServer interface.
func (api *API) PingTablet(ctx context.Context, req *vtadminpb.PingTabletRequest) (*vtadminpb.PingTabletResponse, error) {
span, ctx := trace.NewSpan(ctx, "API.PingTablet")
Expand Down
24 changes: 24 additions & 0 deletions go/vt/vtadmin/http/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,27 @@ func MoveTablesCreate(ctx context.Context, r Request, api *API) *JSONResponse {

return NewJSONResponse(res, err)
}

// ReshardCreate implements the http wrapper for the VTAdminServer.ReshardCreate
// method.
//
// Its route is /workflow/{cluster_id}/reshard
func ReshardCreate(ctx context.Context, r Request, api *API) *JSONResponse {
vars := r.Vars()
decoder := json.NewDecoder(r.Body)
defer r.Body.Close()

var req vtctldatapb.ReshardCreateRequest
if err := decoder.Decode(&req); err != nil {
return NewJSONResponse(nil, &errors.BadRequest{
Err: err,
})
}

res, err := api.server.ReshardCreate(ctx, &vtadminpb.ReshardCreateRequest{
ClusterId: vars["cluster_id"],
Request: &req,
})

return NewJSONResponse(res, err)
}
7 changes: 7 additions & 0 deletions proto/vtadmin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ service VTAdmin {
rpc RetrySchemaMigration(RetrySchemaMigrationRequest) returns (vtctldata.RetrySchemaMigrationResponse) {};
// RunHealthCheck runs a healthcheck on the tablet.
rpc RunHealthCheck(RunHealthCheckRequest) returns (RunHealthCheckResponse) {};
// ReshardCreate creates a workflow to reshard a keyspace.
rpc ReshardCreate(ReshardCreateRequest) returns (vtctldata.WorkflowStatusResponse) {};
// SetReadOnly sets the tablet to read-only mode.
rpc SetReadOnly(SetReadOnlyRequest) returns (SetReadOnlyResponse) {};
// SetReadWrite sets the tablet to read-write mode.
Expand Down Expand Up @@ -909,6 +911,11 @@ message RunHealthCheckResponse {
Cluster cluster = 2;
}

message ReshardCreateRequest {
string cluster_id = 1;
vtctldata.ReshardCreateRequest request = 2;
}

message SetReadOnlyRequest {
topodata.TabletAlias alias = 1;
repeated string cluster_ids = 2;
Expand Down
Loading
Loading