Skip to content

Commit

Permalink
VTAdmin(API): GetUnresolvedTransactions to fetch transactions by keys…
Browse files Browse the repository at this point in the history
…pace

Signed-off-by: Noble Mittal <[email protected]>
  • Loading branch information
beingnoble03 committed Sep 16, 2024
1 parent 646bfd4 commit a1dd579
Show file tree
Hide file tree
Showing 8 changed files with 1,946 additions and 1,176 deletions.
2,437 changes: 1,261 additions & 1,176 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.

198 changes: 198 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.

22 changes: 22 additions & 0 deletions go/vt/vtadmin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func (api *API) Handler() http.Handler {
router.HandleFunc("/tablet/{tablet}/start_replication", httpAPI.Adapt(vtadminhttp.StartReplication)).Name("API.StartReplication").Methods("PUT", "OPTIONS")
router.HandleFunc("/tablet/{tablet}/stop_replication", httpAPI.Adapt(vtadminhttp.StopReplication)).Name("API.StopReplication").Methods("PUT", "OPTIONS")
router.HandleFunc("/tablet/{tablet}/externally_promoted", httpAPI.Adapt(vtadminhttp.TabletExternallyPromoted)).Name("API.TabletExternallyPromoted").Methods("POST")
router.HandleFunc("/transactions/{cluster_id}/{keyspace}", httpAPI.Adapt(vtadminhttp.GetUnresolvedTransactions)).Name("API.GetUnresolvedTransactions").Methods("GET")
router.HandleFunc("/vschema/{cluster_id}/{keyspace}", httpAPI.Adapt(vtadminhttp.GetVSchema)).Name("API.GetVSchema")
router.HandleFunc("/vschemas", httpAPI.Adapt(vtadminhttp.GetVSchemas)).Name("API.GetVSchemas")
router.HandleFunc("/vtctlds", httpAPI.Adapt(vtadminhttp.GetVtctlds)).Name("API.GetVtctlds")
Expand Down Expand Up @@ -1482,6 +1483,27 @@ func (api *API) GetTopologyPath(ctx context.Context, req *vtadminpb.GetTopologyP
return c.Vtctld.GetTopologyPath(ctx, &vtctldatapb.GetTopologyPathRequest{Path: req.Path})
}

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

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

cluster.AnnotateSpan(c, span)

if !api.authz.IsAuthorized(ctx, c.ID, rbac.KeyspaceResource, rbac.GetAction) {
return nil, nil
}

return c.Vtctld.GetUnresolvedTransactions(ctx, &vtctldatapb.GetUnresolvedTransactionsRequest{
Keyspace: req.Keyspace,
})
}

// GetVSchema is part of the vtadminpb.VTAdminServer interface.
func (api *API) GetVSchema(ctx context.Context, req *vtadminpb.GetVSchemaRequest) (*vtadminpb.VSchema, error) {
span, ctx := trace.NewSpan(ctx, "API.GetVSchema")
Expand Down
36 changes: 36 additions & 0 deletions go/vt/vtadmin/http/transactions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2024 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package http

import (
"context"

vtadminpb "vitess.io/vitess/go/vt/proto/vtadmin"
)

// GetUnresolvedTransactions implements the http wrapper for the
// /transactions/{cluster_id}/{keyspace} route.
func GetUnresolvedTransactions(ctx context.Context, r Request, api *API) *JSONResponse {
vars := r.Vars()

res, err := api.server.GetUnresolvedTransactions(ctx, &vtadminpb.GetUnresolvedTransactionsRequest{
ClusterId: vars["cluster_id"],
Keyspace: vars["keyspace"],
})

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 @@ -114,6 +114,8 @@ service VTAdmin {
rpc GetTablets(GetTabletsRequest) returns (GetTabletsResponse) {};
// GetTopologyPath returns the cell located at the specified path in the topology server.
rpc GetTopologyPath(GetTopologyPathRequest) returns (vtctldata.GetTopologyPathResponse){};
// GetUnresolvedTransactions returns the unresolved transactions for the request.
rpc GetUnresolvedTransactions(GetUnresolvedTransactionsRequest) returns (vtctldata.GetUnresolvedTransactionsResponse){};
// GetVSchema returns a VSchema for the specified keyspace in the specified
// cluster.
rpc GetVSchema(GetVSchemaRequest) returns (VSchema) {};
Expand Down Expand Up @@ -619,6 +621,11 @@ message GetTopologyPathRequest {
string path = 2;
}

message GetUnresolvedTransactionsRequest {
string cluster_id = 1;
string keyspace = 2;
}

message GetVSchemaRequest {
string cluster_id = 1;
string keyspace = 2;
Expand Down
Loading

0 comments on commit a1dd579

Please sign in to comment.