Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request vitessio#7360 from tinyspeck/am_vtctld_getvschema
Browse files Browse the repository at this point in the history
[vtctld] Migrate GetVSchema to VtctldServer
  • Loading branch information
rohit-nayak-ps authored and setassociative committed Mar 11, 2021
1 parent 73fa048 commit b7b5a2d
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 100 deletions.
27 changes: 27 additions & 0 deletions go/cmd/vtctldclient/internal/command/vschemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ var (
Args: cobra.ExactArgs(1),
RunE: commandGetSrvVSchema,
}
// GetVSchema makes a GetVSchema gRPC call to a vtctld.
GetVSchema = &cobra.Command{
Use: "GetVSchema keyspace",
Args: cobra.ExactArgs(1),
RunE: commandGetVSchema,
}
)

func commandGetSrvVSchema(cmd *cobra.Command, args []string) error {
Expand All @@ -55,6 +61,27 @@ func commandGetSrvVSchema(cmd *cobra.Command, args []string) error {
return nil
}

func commandGetVSchema(cmd *cobra.Command, args []string) error {
keyspace := cmd.Flags().Arg(0)

resp, err := client.GetVSchema(commandCtx, &vtctldatapb.GetVSchemaRequest{
Keyspace: keyspace,
})
if err != nil {
return err
}

data, err := cli.MarshalJSON(resp.VSchema)
if err != nil {
return err
}

fmt.Printf("%s\n", data)

return nil
}

func init() {
Root.AddCommand(GetSrvVSchema)
Root.AddCommand(GetVSchema)
}
230 changes: 156 additions & 74 deletions go/vt/proto/vtctldata/vtctldata.pb.go

Large diffs are not rendered by default.

90 changes: 64 additions & 26 deletions go/vt/proto/vtctlservice/vtctlservice.pb.go

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

9 changes: 9 additions & 0 deletions go/vt/vtctl/grpcvtctldclient/client_gen.go

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

12 changes: 12 additions & 0 deletions go/vt/vtctl/grpcvtctldserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,18 @@ func (s *VtctldServer) GetTablets(ctx context.Context, req *vtctldatapb.GetTable
}, nil
}

// GetVSchema is part of the vtctlservicepb.VtctldServer interface.
func (s *VtctldServer) GetVSchema(ctx context.Context, req *vtctldatapb.GetVSchemaRequest) (*vtctldatapb.GetVSchemaResponse, error) {
vschema, err := s.ts.GetVSchema(ctx, req.Keyspace)
if err != nil {
return nil, err
}

return &vtctldatapb.GetVSchemaResponse{
VSchema: vschema,
}, nil
}

// StartServer registers a VtctldServer for RPCs on the given gRPC server.
func StartServer(s *grpc.Server, ts *topo.Server) {
vtctlservicepb.RegisterVtctldServer(s, NewVtctldServer(ts))
Expand Down
40 changes: 40 additions & 0 deletions go/vt/vtctl/grpcvtctldserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,3 +859,43 @@ func TestGetTablets(t *testing.T) {
})
}
}

func TestGetVSchema(t *testing.T) {
ctx := context.Background()
ts := memorytopo.NewServer("zone1")
vtctld := NewVtctldServer(ts)

err := ts.SaveVSchema(ctx, "testkeyspace", &vschemapb.Keyspace{
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"v1": {
Type: "hash",
},
},
})
require.NoError(t, err)

expected := &vtctldatapb.GetVSchemaResponse{
VSchema: &vschemapb.Keyspace{
Sharded: true,
Vindexes: map[string]*vschemapb.Vindex{
"v1": {
Type: "hash",
},
},
},
}

resp, err := vtctld.GetVSchema(ctx, &vtctldatapb.GetVSchemaRequest{
Keyspace: "testkeyspace",
})
assert.NoError(t, err)
assert.Equal(t, expected, resp)

t.Run("not found", func(t *testing.T) {
_, err := vtctld.GetVSchema(ctx, &vtctldatapb.GetVSchemaRequest{
Keyspace: "doesnotexist",
})
assert.Error(t, err)
})
}
8 changes: 8 additions & 0 deletions proto/vtctldata.proto
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ message GetTabletsResponse {
repeated topodata.Tablet tablets = 1;
}

message GetVSchemaRequest {
string keyspace = 1;
}

message GetVSchemaResponse {
vschema.Keyspace v_schema = 1;
}

message Keyspace {
string name = 1;
topodata.Keyspace keyspace = 2;
Expand Down
2 changes: 2 additions & 0 deletions proto/vtctlservice.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,6 @@ service Vtctld {
rpc GetTablet(vtctldata.GetTabletRequest) returns (vtctldata.GetTabletResponse) {};
// GetTablets returns tablets, optionally filtered by keyspace and shard.
rpc GetTablets(vtctldata.GetTabletsRequest) returns (vtctldata.GetTabletsResponse) {};
// GetVSchema returns the vschema for a keyspace.
rpc GetVSchema(vtctldata.GetVSchemaRequest) returns (vtctldata.GetVSchemaResponse) {};
}

0 comments on commit b7b5a2d

Please sign in to comment.