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

[vtctld] Migrate GetVSchema to VtctldServer #7360

Merged
merged 3 commits into from
Jan 24, 2021
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
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)
}
250 changes: 166 additions & 84 deletions go/vt/proto/vtctldata/vtctldata.pb.go

Large diffs are not rendered by default.

86 changes: 62 additions & 24 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 @@ -343,6 +343,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
}

// InitShardPrimary is part of the vtctlservicepb.VtctldServer interface.
func (s *VtctldServer) InitShardPrimary(ctx context.Context, req *vtctldatapb.InitShardPrimaryRequest) (*vtctldatapb.InitShardPrimaryResponse, error) {
if req.Keyspace == "" {
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 @@ -934,3 +934,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 @@ -142,6 +142,14 @@ message GetTabletsResponse {
repeated topodata.Tablet tablets = 1;
}

message GetVSchemaRequest {
string keyspace = 1;
}

message GetVSchemaResponse {
vschema.Keyspace v_schema = 1;
}

message InitShardPrimaryRequest {
string keyspace = 1;
string shard = 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,6 +57,8 @@ 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) {};
// InitShardPrimary sets the initial primary for a shard. Will make all other
// tablets in the shard replicas of the provided primary.
//
Expand Down