Skip to content

Commit

Permalink
VTAdmin: Add support for Create Reshard (#16903)
Browse files Browse the repository at this point in the history
Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 authored Oct 11, 2024
1 parent 9d2e450 commit d209847
Show file tree
Hide file tree
Showing 14 changed files with 2,027 additions and 845 deletions.
1,771 changes: 928 additions & 843 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 @@ -426,6 +426,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 @@ -1888,6 +1889,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 @@ -173,6 +173,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 @@ -917,6 +919,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

0 comments on commit d209847

Please sign in to comment.