From 196245227db1bdc08068904467f8800a24df2dbd Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Tue, 8 Dec 2020 16:24:57 -0500 Subject: [PATCH 1/4] Implement FindAllShardsInKeyspace Signed-off-by: Andrew Mason --- go/cmd/vtctldclient/commands.go | 27 +++ go/vt/proto/vtctldata/vtctldata.pb.go | 214 ++++++++++++++++---- go/vt/proto/vtctlservice/vtctlservice.pb.go | 56 ++++- go/vt/vtctl/grpcvtctldclient/client.go | 8 + go/vt/vtctl/grpcvtctldserver/server.go | 21 ++ go/vt/vtctl/grpcvtctldserver/server_test.go | 39 ++++ proto/vtctldata.proto | 14 ++ proto/vtctlservice.proto | 2 + 8 files changed, 338 insertions(+), 43 deletions(-) diff --git a/go/cmd/vtctldclient/commands.go b/go/cmd/vtctldclient/commands.go index 322858b3782..dc706d9a372 100644 --- a/go/cmd/vtctldclient/commands.go +++ b/go/cmd/vtctldclient/commands.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "fmt" "github.com/spf13/cobra" @@ -9,6 +10,12 @@ import ( ) var ( + findAllShardsInKeyspaceCmd = &cobra.Command{ + Use: "FindAllShardsInKeyspace keyspace", + Aliases: []string{"findallshardsinkeyspace"}, + Args: cobra.ExactArgs(1), + RunE: commandFindAllShardsInKeyspace, + } getKeyspaceCmd = &cobra.Command{ Use: "GetKeyspace keyspace", Aliases: []string{"getkeyspace"}, @@ -23,6 +30,25 @@ var ( } ) +func commandFindAllShardsInKeyspace(cmd *cobra.Command, args []string) error { + ks := cmd.Flags().Arg(0) + resp, err := client.FindAllShardsInKeyspace(commandCtx, &vtctldatapb.FindAllShardsInKeyspaceRequest{ + Keyspace: ks, + }) + + if err != nil { + return err + } + + data, err := json.Marshal(&resp) + if err != nil { + return err + } + + fmt.Printf("%s\n", data) + return nil +} + func commandGetKeyspace(cmd *cobra.Command, args []string) error { ks := cmd.Flags().Arg(0) resp, err := client.GetKeyspace(commandCtx, &vtctldatapb.GetKeyspaceRequest{ @@ -48,6 +74,7 @@ func commandGetKeyspaces(cmd *cobra.Command, args []string) error { } func init() { + rootCmd.AddCommand(findAllShardsInKeyspaceCmd) rootCmd.AddCommand(getKeyspaceCmd) rootCmd.AddCommand(getKeyspacesCmd) } diff --git a/go/vt/proto/vtctldata/vtctldata.pb.go b/go/vt/proto/vtctldata/vtctldata.pb.go index c869f3d51ea..9f0a17dc861 100644 --- a/go/vt/proto/vtctldata/vtctldata.pb.go +++ b/go/vt/proto/vtctldata/vtctldata.pb.go @@ -268,6 +268,139 @@ func (m *Keyspace) GetKeyspace() *topodata.Keyspace { return nil } +type FindAllShardsInKeyspaceRequest struct { + Keyspace string `protobuf:"bytes,1,opt,name=keyspace,proto3" json:"keyspace,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *FindAllShardsInKeyspaceRequest) Reset() { *m = FindAllShardsInKeyspaceRequest{} } +func (m *FindAllShardsInKeyspaceRequest) String() string { return proto.CompactTextString(m) } +func (*FindAllShardsInKeyspaceRequest) ProtoMessage() {} +func (*FindAllShardsInKeyspaceRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{6} +} + +func (m *FindAllShardsInKeyspaceRequest) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_FindAllShardsInKeyspaceRequest.Unmarshal(m, b) +} +func (m *FindAllShardsInKeyspaceRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_FindAllShardsInKeyspaceRequest.Marshal(b, m, deterministic) +} +func (m *FindAllShardsInKeyspaceRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_FindAllShardsInKeyspaceRequest.Merge(m, src) +} +func (m *FindAllShardsInKeyspaceRequest) XXX_Size() int { + return xxx_messageInfo_FindAllShardsInKeyspaceRequest.Size(m) +} +func (m *FindAllShardsInKeyspaceRequest) XXX_DiscardUnknown() { + xxx_messageInfo_FindAllShardsInKeyspaceRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_FindAllShardsInKeyspaceRequest proto.InternalMessageInfo + +func (m *FindAllShardsInKeyspaceRequest) GetKeyspace() string { + if m != nil { + return m.Keyspace + } + return "" +} + +type FindAllShardsInKeyspaceResponse struct { + Shards map[string]*Shard `protobuf:"bytes,1,rep,name=shards,proto3" json:"shards,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *FindAllShardsInKeyspaceResponse) Reset() { *m = FindAllShardsInKeyspaceResponse{} } +func (m *FindAllShardsInKeyspaceResponse) String() string { return proto.CompactTextString(m) } +func (*FindAllShardsInKeyspaceResponse) ProtoMessage() {} +func (*FindAllShardsInKeyspaceResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{7} +} + +func (m *FindAllShardsInKeyspaceResponse) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_FindAllShardsInKeyspaceResponse.Unmarshal(m, b) +} +func (m *FindAllShardsInKeyspaceResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_FindAllShardsInKeyspaceResponse.Marshal(b, m, deterministic) +} +func (m *FindAllShardsInKeyspaceResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_FindAllShardsInKeyspaceResponse.Merge(m, src) +} +func (m *FindAllShardsInKeyspaceResponse) XXX_Size() int { + return xxx_messageInfo_FindAllShardsInKeyspaceResponse.Size(m) +} +func (m *FindAllShardsInKeyspaceResponse) XXX_DiscardUnknown() { + xxx_messageInfo_FindAllShardsInKeyspaceResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_FindAllShardsInKeyspaceResponse proto.InternalMessageInfo + +func (m *FindAllShardsInKeyspaceResponse) GetShards() map[string]*Shard { + if m != nil { + return m.Shards + } + return nil +} + +type Shard struct { + Keyspace string `protobuf:"bytes,1,opt,name=keyspace,proto3" json:"keyspace,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Shard *topodata.Shard `protobuf:"bytes,3,opt,name=shard,proto3" json:"shard,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Shard) Reset() { *m = Shard{} } +func (m *Shard) String() string { return proto.CompactTextString(m) } +func (*Shard) ProtoMessage() {} +func (*Shard) Descriptor() ([]byte, []int) { + return fileDescriptor_f41247b323a1ab2e, []int{8} +} + +func (m *Shard) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Shard.Unmarshal(m, b) +} +func (m *Shard) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Shard.Marshal(b, m, deterministic) +} +func (m *Shard) XXX_Merge(src proto.Message) { + xxx_messageInfo_Shard.Merge(m, src) +} +func (m *Shard) XXX_Size() int { + return xxx_messageInfo_Shard.Size(m) +} +func (m *Shard) XXX_DiscardUnknown() { + xxx_messageInfo_Shard.DiscardUnknown(m) +} + +var xxx_messageInfo_Shard proto.InternalMessageInfo + +func (m *Shard) GetKeyspace() string { + if m != nil { + return m.Keyspace + } + return "" +} + +func (m *Shard) GetName() string { + if m != nil { + return m.Name + } + return "" +} + +func (m *Shard) GetShard() *topodata.Shard { + if m != nil { + return m.Shard + } + return nil +} + // TableMaterializeSttings contains the settings for one table. type TableMaterializeSettings struct { TargetTable string `protobuf:"bytes,1,opt,name=target_table,json=targetTable,proto3" json:"target_table,omitempty"` @@ -286,7 +419,7 @@ func (m *TableMaterializeSettings) Reset() { *m = TableMaterializeSettin func (m *TableMaterializeSettings) String() string { return proto.CompactTextString(m) } func (*TableMaterializeSettings) ProtoMessage() {} func (*TableMaterializeSettings) Descriptor() ([]byte, []int) { - return fileDescriptor_f41247b323a1ab2e, []int{6} + return fileDescriptor_f41247b323a1ab2e, []int{9} } func (m *TableMaterializeSettings) XXX_Unmarshal(b []byte) error { @@ -349,7 +482,7 @@ func (m *MaterializeSettings) Reset() { *m = MaterializeSettings{} } func (m *MaterializeSettings) String() string { return proto.CompactTextString(m) } func (*MaterializeSettings) ProtoMessage() {} func (*MaterializeSettings) Descriptor() ([]byte, []int) { - return fileDescriptor_f41247b323a1ab2e, []int{7} + return fileDescriptor_f41247b323a1ab2e, []int{10} } func (m *MaterializeSettings) XXX_Unmarshal(b []byte) error { @@ -426,6 +559,10 @@ func init() { proto.RegisterType((*GetKeyspacesResponse)(nil), "vtctldata.GetKeyspacesResponse") proto.RegisterType((*GetKeyspaceRequest)(nil), "vtctldata.GetKeyspaceRequest") proto.RegisterType((*Keyspace)(nil), "vtctldata.Keyspace") + proto.RegisterType((*FindAllShardsInKeyspaceRequest)(nil), "vtctldata.FindAllShardsInKeyspaceRequest") + proto.RegisterType((*FindAllShardsInKeyspaceResponse)(nil), "vtctldata.FindAllShardsInKeyspaceResponse") + proto.RegisterMapType((map[string]*Shard)(nil), "vtctldata.FindAllShardsInKeyspaceResponse.ShardsEntry") + proto.RegisterType((*Shard)(nil), "vtctldata.Shard") proto.RegisterType((*TableMaterializeSettings)(nil), "vtctldata.TableMaterializeSettings") proto.RegisterType((*MaterializeSettings)(nil), "vtctldata.MaterializeSettings") } @@ -433,37 +570,44 @@ func init() { func init() { proto.RegisterFile("vtctldata.proto", fileDescriptor_f41247b323a1ab2e) } var fileDescriptor_f41247b323a1ab2e = []byte{ - // 505 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x93, 0xd1, 0x8e, 0xd3, 0x3c, - 0x10, 0x85, 0x95, 0xb6, 0xbb, 0x7f, 0x33, 0xfd, 0x9b, 0x82, 0x0b, 0x52, 0x54, 0x84, 0x54, 0x02, - 0xec, 0x56, 0x42, 0x4a, 0x61, 0x79, 0x02, 0x28, 0x15, 0x02, 0x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, 0x5f, 0xe3, 0x37, 0x35, 0x9d, 0xc9, 0x72, 0xcf, 0x3e, - 0x42, 0xa0, 0x53, 0x49, 0x55, 0xe3, 0x33, 0x3c, 0xd1, 0x6f, 0xfe, 0xf4, 0xe8, 0xcd, 0xff, 0x95, - 0x6c, 0xd2, 0xd7, 0xa5, 0x6e, 0x43, 0x06, 0x9d, 0x0c, 0x85, 0x08, 0x4f, 0xcd, 0x4b, 0xd6, 0x67, - 0x13, 0xfe, 0x52, 0xd4, 0xe1, 0xef, 0x4b, 0x54, 0xe1, 0x7f, 0x36, 0xfc, 0x9a, 0x2d, 0x6a, 0xf4, - 0x76, 0xf2, 0xe3, 0x6c, 0x97, 0x13, 0x2a, 0x15, 0xe7, 0x72, 0x6a, 0x4e, 0xd3, 0xb5, 0x9c, 0xee, - 0x68, 0xaa, 0x7f, 0xaf, 0xa9, 0x33, 0xb2, 0x3c, 0xd5, 0xe0, 0xf5, 0xdf, 0x00, 0x00, 0x00, 0xff, - 0xff, 0xd5, 0x06, 0x15, 0x84, 0xac, 0x03, 0x00, 0x00, + // 620 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xdf, 0x6e, 0xd3, 0x4a, + 0x10, 0xc6, 0xe5, 0xa4, 0xe9, 0x89, 0x27, 0x27, 0x49, 0xcf, 0xf6, 0x20, 0x59, 0x41, 0x40, 0x30, + 0xb4, 0x8d, 0x84, 0xe4, 0x40, 0x91, 0x10, 0x42, 0xdc, 0x94, 0x12, 0x50, 0xa9, 0xe8, 0x85, 0x5b, + 0x81, 0xc4, 0x05, 0xd6, 0xd6, 0x9e, 0x06, 0xab, 0x1b, 0xaf, 0xf1, 0x4e, 0xd2, 0x86, 0x37, 0xe0, + 0x65, 0x78, 0x04, 0x9e, 0x0d, 0x79, 0xd7, 0x76, 0x5c, 0xa9, 0x05, 0x71, 0x37, 0xf9, 0xcd, 0xbf, + 0x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 0x86, 0x9c, 0x30, 0x88, + 0x22, 0xa1, 0x85, 0xd9, 0xbe, 0x6d, 0xc8, 0xeb, 0x48, 0xb8, 0x3f, 0x1a, 0xb0, 0x79, 0x9d, 0x8c, + 0x01, 0xb4, 0x2f, 0x64, 0x76, 0x7e, 0x26, 0xe4, 0x45, 0x79, 0x7a, 0xf9, 0x9b, 0xed, 0x40, 0xbf, + 0xd8, 0x7f, 0xe5, 0x55, 0xd9, 0x7e, 0xcf, 0xe0, 0xea, 0x2d, 0xee, 0x40, 0xbf, 0xb8, 0xa5, 0x2a, + 0x34, 0x02, 0x7a, 0x06, 0x57, 0x85, 0xdb, 0xd0, 0x57, 0x24, 0xd3, 0x80, 0x9f, 0x11, 0x66, 0x41, + 0x28, 0xd3, 0xa5, 0xb3, 0x36, 0xb4, 0x46, 0x6d, 0xbf, 0x9b, 0xe3, 0xbd, 0x9c, 0xee, 0xcb, 0x74, + 0xc9, 0xde, 0x41, 0x4f, 0xbb, 0x12, 0xa8, 0x42, 0xa7, 0xd3, 0xd2, 0xcf, 0xe7, 0x41, 0xed, 0x73, + 0xde, 0xe4, 0xac, 0xdf, 0xd5, 0xad, 0xd5, 0x85, 0x0c, 0xd6, 0x42, 0x14, 0xc2, 0x59, 0x37, 0x1f, + 0x30, 0x8f, 0x8d, 0xf9, 0xa7, 0x22, 0x37, 0x7f, 0x99, 0xa2, 0x72, 0xfe, 0x29, 0xcd, 0xcf, 0xd9, + 0x49, 0x8e, 0x5e, 0x8d, 0x3e, 0x6d, 0x2f, 0x62, 0x42, 0xa5, 0xbc, 0x58, 0x8e, 0x4d, 0x34, 0x9e, + 0xca, 0xf1, 0x82, 0xc6, 0xfa, 0xdf, 0x6b, 0x5c, 0x09, 0x39, 0x5d, 0xd7, 0xe0, 0xe9, 0xaf, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x25, 0x63, 0x6b, 0x01, 0x0b, 0x05, 0x00, 0x00, } diff --git a/go/vt/proto/vtctlservice/vtctlservice.pb.go b/go/vt/proto/vtctlservice/vtctlservice.pb.go index d8bc9e46e78..7f25fd998b8 100644 --- a/go/vt/proto/vtctlservice/vtctlservice.pb.go +++ b/go/vt/proto/vtctlservice/vtctlservice.pb.go @@ -29,20 +29,22 @@ const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package func init() { proto.RegisterFile("vtctlservice.proto", fileDescriptor_27055cdbb1148d2b) } var fileDescriptor_27055cdbb1148d2b = []byte{ - // 204 bytes of a gzipped FileDescriptorProto + // 239 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2a, 0x2b, 0x49, 0x2e, 0xc9, 0x29, 0x4e, 0x2d, 0x2a, 0xcb, 0x4c, 0x4e, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x41, 0x16, 0x93, 0xe2, 0x07, 0xf3, 0x52, 0x12, 0x4b, 0x12, 0x21, 0xd2, 0x46, 0x85, 0x5c, 0xac, 0x61, 0x20, 0x21, 0xa1, 0x0c, 0x2e, 0x61, 0xd7, 0x8a, 0xd4, 0xe4, 0xd2, 0x92, 0x54, 0x30, 0xdf, 0x39, 0x3f, 0x37, 0x37, 0x31, 0x2f, 0x45, 0x48, 0x55, 0x0f, 0xa1, 0x03, 0x8b, 0x7c, 0x50, 0x6a, 0x61, 0x69, 0x6a, 0x71, 0x89, 0x94, 0x1a, 0x21, 0x65, 0xc5, 0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x4a, - 0x0c, 0x06, 0x8c, 0x46, 0x0b, 0x18, 0xb9, 0xd8, 0xc0, 0x92, 0x29, 0x42, 0xce, 0x5c, 0xdc, 0xee, - 0xa9, 0x25, 0xde, 0xa9, 0x95, 0xc5, 0x05, 0x89, 0xc9, 0xa9, 0x42, 0xb2, 0x48, 0xa6, 0x20, 0x89, - 0xc3, 0x2c, 0x11, 0x46, 0x92, 0x86, 0xc9, 0x29, 0x31, 0x08, 0x05, 0x72, 0xf1, 0x20, 0x29, 0x2e, - 0x16, 0x92, 0xc3, 0x6e, 0x4a, 0x31, 0xcc, 0x18, 0x79, 0x9c, 0xf2, 0x30, 0x47, 0x3a, 0x69, 0x47, - 0x69, 0x96, 0x65, 0x96, 0xa4, 0x16, 0x17, 0xeb, 0x65, 0xe6, 0xeb, 0x43, 0x58, 0xfa, 0xe9, 0xf9, - 0xfa, 0x65, 0x25, 0xfa, 0xe0, 0x50, 0xd3, 0x47, 0x0e, 0xd3, 0x24, 0x36, 0xb0, 0x98, 0x31, 0x20, - 0x00, 0x00, 0xff, 0xff, 0x6a, 0xd1, 0x88, 0x6e, 0x7e, 0x01, 0x00, 0x00, + 0x0c, 0x06, 0x8c, 0x46, 0x53, 0x98, 0xb8, 0xd8, 0xc0, 0x92, 0x29, 0x42, 0x45, 0x5c, 0xe2, 0x6e, + 0x99, 0x79, 0x29, 0x8e, 0x39, 0x39, 0xc1, 0x19, 0x89, 0x45, 0x29, 0xc5, 0x9e, 0x79, 0xde, 0xa9, + 0x95, 0xc5, 0x05, 0x89, 0xc9, 0xa9, 0x42, 0x9a, 0x48, 0x26, 0xe2, 0x50, 0x03, 0xb3, 0x5c, 0x8b, + 0x18, 0xa5, 0x30, 0x07, 0x08, 0x39, 0x73, 0x71, 0xbb, 0xa7, 0x96, 0xc0, 0xed, 0x91, 0x45, 0xd2, + 0x8c, 0x24, 0x0e, 0x33, 0x5b, 0x18, 0x49, 0x1a, 0x26, 0xa7, 0xc4, 0x20, 0x14, 0xc8, 0xc5, 0x83, + 0xa4, 0xb8, 0x58, 0x48, 0x0e, 0xbb, 0x29, 0xc5, 0x30, 0x63, 0xe4, 0x71, 0xca, 0xc3, 0xdc, 0xe5, + 0xa4, 0x1d, 0xa5, 0x59, 0x96, 0x59, 0x92, 0x5a, 0x5c, 0xac, 0x97, 0x99, 0xaf, 0x0f, 0x61, 0xe9, + 0xa7, 0xe7, 0xeb, 0x97, 0x95, 0xe8, 0x83, 0x63, 0x4a, 0x1f, 0x39, 0x1e, 0x93, 0xd8, 0xc0, 0x62, + 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xa6, 0x9d, 0x46, 0x8d, 0xf2, 0x01, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -156,6 +158,8 @@ var _Vtctl_serviceDesc = grpc.ServiceDesc{ // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type VtctldClient interface { + // FindAllShardsInKeyspace returns a map of shard names to shard references for a given keyspace. + FindAllShardsInKeyspace(ctx context.Context, in *vtctldata.FindAllShardsInKeyspaceRequest, opts ...grpc.CallOption) (*vtctldata.FindAllShardsInKeyspaceResponse, error) // GetKeyspace reads the given keyspace from the topo and returns it. GetKeyspace(ctx context.Context, in *vtctldata.GetKeyspaceRequest, opts ...grpc.CallOption) (*vtctldata.Keyspace, error) // GetKeyspaces returns the keyspace struct of all keyspaces in the topo. @@ -170,6 +174,15 @@ func NewVtctldClient(cc *grpc.ClientConn) VtctldClient { return &vtctldClient{cc} } +func (c *vtctldClient) FindAllShardsInKeyspace(ctx context.Context, in *vtctldata.FindAllShardsInKeyspaceRequest, opts ...grpc.CallOption) (*vtctldata.FindAllShardsInKeyspaceResponse, error) { + out := new(vtctldata.FindAllShardsInKeyspaceResponse) + err := c.cc.Invoke(ctx, "/vtctlservice.Vtctld/FindAllShardsInKeyspace", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *vtctldClient) GetKeyspace(ctx context.Context, in *vtctldata.GetKeyspaceRequest, opts ...grpc.CallOption) (*vtctldata.Keyspace, error) { out := new(vtctldata.Keyspace) err := c.cc.Invoke(ctx, "/vtctlservice.Vtctld/GetKeyspace", in, out, opts...) @@ -190,6 +203,8 @@ func (c *vtctldClient) GetKeyspaces(ctx context.Context, in *vtctldata.GetKeyspa // VtctldServer is the server API for Vtctld service. type VtctldServer interface { + // FindAllShardsInKeyspace returns a map of shard names to shard references for a given keyspace. + FindAllShardsInKeyspace(context.Context, *vtctldata.FindAllShardsInKeyspaceRequest) (*vtctldata.FindAllShardsInKeyspaceResponse, error) // GetKeyspace reads the given keyspace from the topo and returns it. GetKeyspace(context.Context, *vtctldata.GetKeyspaceRequest) (*vtctldata.Keyspace, error) // GetKeyspaces returns the keyspace struct of all keyspaces in the topo. @@ -200,6 +215,9 @@ type VtctldServer interface { type UnimplementedVtctldServer struct { } +func (*UnimplementedVtctldServer) FindAllShardsInKeyspace(ctx context.Context, req *vtctldata.FindAllShardsInKeyspaceRequest) (*vtctldata.FindAllShardsInKeyspaceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method FindAllShardsInKeyspace not implemented") +} func (*UnimplementedVtctldServer) GetKeyspace(ctx context.Context, req *vtctldata.GetKeyspaceRequest) (*vtctldata.Keyspace, error) { return nil, status.Errorf(codes.Unimplemented, "method GetKeyspace not implemented") } @@ -211,6 +229,24 @@ func RegisterVtctldServer(s *grpc.Server, srv VtctldServer) { s.RegisterService(&_Vtctld_serviceDesc, srv) } +func _Vtctld_FindAllShardsInKeyspace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(vtctldata.FindAllShardsInKeyspaceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(VtctldServer).FindAllShardsInKeyspace(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/vtctlservice.Vtctld/FindAllShardsInKeyspace", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(VtctldServer).FindAllShardsInKeyspace(ctx, req.(*vtctldata.FindAllShardsInKeyspaceRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _Vtctld_GetKeyspace_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(vtctldata.GetKeyspaceRequest) if err := dec(in); err != nil { @@ -251,6 +287,10 @@ var _Vtctld_serviceDesc = grpc.ServiceDesc{ ServiceName: "vtctlservice.Vtctld", HandlerType: (*VtctldServer)(nil), Methods: []grpc.MethodDesc{ + { + MethodName: "FindAllShardsInKeyspace", + Handler: _Vtctld_FindAllShardsInKeyspace_Handler, + }, { MethodName: "GetKeyspace", Handler: _Vtctld_GetKeyspace_Handler, diff --git a/go/vt/vtctl/grpcvtctldclient/client.go b/go/vt/vtctl/grpcvtctldclient/client.go index ceda5c2f134..e392b6b0d61 100644 --- a/go/vt/vtctl/grpcvtctldclient/client.go +++ b/go/vt/vtctl/grpcvtctldclient/client.go @@ -69,6 +69,14 @@ func (client *gRPCVtctldClient) Close() error { // (TODO:@amason) - This boilerplate should end up the same for all ~70 commands // .... we should do this with code gen. +func (client *gRPCVtctldClient) FindAllShardsInKeyspace(ctx context.Context, in *vtctldatapb.FindAllShardsInKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.FindAllShardsInKeyspaceResponse, error) { + if client.c == nil { + return nil, status.Error(codes.Unavailable, connClosedMsg) + } + + return client.c.FindAllShardsInKeyspace(ctx, in, opts...) +} + func (client *gRPCVtctldClient) GetKeyspace(ctx context.Context, in *vtctldatapb.GetKeyspaceRequest, opts ...grpc.CallOption) (*vtctldatapb.Keyspace, error) { if client.c == nil { return nil, status.Error(codes.Unavailable, connClosedMsg) diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index 9331ccddbdf..da38eea872b 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -20,6 +20,27 @@ func NewVtctldServer(ts *topo.Server) *VtctldServer { return &VtctldServer{ts: ts} } +// FindAllShardsInKeyspace is part of the vtctlservicepb.VtctldServer interface. +func (s *VtctldServer) FindAllShardsInKeyspace(ctx context.Context, req *vtctldatapb.FindAllShardsInKeyspaceRequest) (*vtctldatapb.FindAllShardsInKeyspaceResponse, error) { + result, err := s.ts.FindAllShardsInKeyspace(ctx, req.Keyspace) + if err != nil { + return nil, err + } + + shards := map[string]*vtctldatapb.Shard{} + for _, shard := range result { + shards[shard.ShardName()] = &vtctldatapb.Shard{ + Keyspace: req.Keyspace, + Name: shard.ShardName(), + Shard: shard.Shard, + } + } + + return &vtctldatapb.FindAllShardsInKeyspaceResponse{ + Shards: shards, + }, nil +} + // GetKeyspace is part of the vtctlservicepb.VtctldServer interface. func (s *VtctldServer) GetKeyspace(ctx context.Context, req *vtctldatapb.GetKeyspaceRequest) (*vtctldatapb.Keyspace, error) { keyspace, err := s.ts.GetKeyspace(ctx, req.Keyspace) diff --git a/go/vt/vtctl/grpcvtctldserver/server_test.go b/go/vt/vtctl/grpcvtctldserver/server_test.go index 42a9dbb3935..70342b20d41 100644 --- a/go/vt/vtctl/grpcvtctldserver/server_test.go +++ b/go/vt/vtctl/grpcvtctldserver/server_test.go @@ -14,6 +14,45 @@ import ( vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" ) +func TestFindAllShardsInKeyspace(t *testing.T) { + ctx := context.Background() + ts := memorytopo.NewServer("cell1") + vtctld := NewVtctldServer(ts) + + ks := &vtctldatapb.Keyspace{ + Name: "testkeyspace", + Keyspace: &topodatapb.Keyspace{}, + } + addKeyspace(ctx, t, ts, ks) + + si1, err := ts.GetOrCreateShard(ctx, ks.Name, "-80") + require.NoError(t, err) + si2, err := ts.GetOrCreateShard(ctx, ks.Name, "80-") + require.NoError(t, err) + + resp, err := vtctld.FindAllShardsInKeyspace(ctx, &vtctldatapb.FindAllShardsInKeyspaceRequest{Keyspace: ks.Name}) + assert.NoError(t, err) + assert.NotNil(t, resp) + + expected := map[string]*vtctldatapb.Shard{ + "-80": { + Keyspace: ks.Name, + Name: "-80", + Shard: si1.Shard, + }, + "80-": { + Keyspace: ks.Name, + Name: "80-", + Shard: si2.Shard, + }, + } + + assert.Equal(t, expected, resp.Shards) + + _, err = vtctld.FindAllShardsInKeyspace(ctx, &vtctldatapb.FindAllShardsInKeyspaceRequest{Keyspace: "nothing"}) + assert.Error(t, err) +} + func TestGetKeyspace(t *testing.T) { ctx := context.Background() ts := memorytopo.NewServer("cell1") diff --git a/proto/vtctldata.proto b/proto/vtctldata.proto index 875d6e200cd..e2e98542f4a 100644 --- a/proto/vtctldata.proto +++ b/proto/vtctldata.proto @@ -53,6 +53,20 @@ message Keyspace { topodata.Keyspace keyspace = 2; } +message FindAllShardsInKeyspaceRequest { + string keyspace = 1; +} + +message FindAllShardsInKeyspaceResponse { + map shards = 1; +} + +message Shard { + string keyspace = 1; + string name = 2; + topodata.Shard shard = 3; +} + // TableMaterializeSttings contains the settings for one table. message TableMaterializeSettings { string target_table = 1; diff --git a/proto/vtctlservice.proto b/proto/vtctlservice.proto index 20d88eba87e..45a9302a28b 100644 --- a/proto/vtctlservice.proto +++ b/proto/vtctlservice.proto @@ -31,6 +31,8 @@ service Vtctl { // Service Vtctld exposes gRPC endpoints for each vt command. service Vtctld { + // FindAllShardsInKeyspace returns a map of shard names to shard references for a given keyspace. + rpc FindAllShardsInKeyspace(vtctldata.FindAllShardsInKeyspaceRequest) returns (vtctldata.FindAllShardsInKeyspaceResponse) {}; // GetKeyspace reads the given keyspace from the topo and returns it. rpc GetKeyspace(vtctldata.GetKeyspaceRequest) returns (vtctldata.Keyspace) {}; // GetKeyspaces returns the keyspace struct of all keyspaces in the topo. From c7a345fc3f0d6fafd4067f819711be3b80f74d22 Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Thu, 17 Dec 2020 15:33:42 -0500 Subject: [PATCH 2/4] Add grpcvtctldclient test for FindAllShardsInKeyspace Signed-off-by: Andrew Mason --- go/vt/vtctl/grpcvtctldclient/client_test.go | 79 ++++++++++++++++----- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/go/vt/vtctl/grpcvtctldclient/client_test.go b/go/vt/vtctl/grpcvtctldclient/client_test.go index 7e5ff7eca18..c052d7ace7a 100644 --- a/go/vt/vtctl/grpcvtctldclient/client_test.go +++ b/go/vt/vtctl/grpcvtctldclient/client_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/require" "golang.org/x/net/nettest" "google.golang.org/grpc" + "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/memorytopo" "vitess.io/vitess/go/vt/vtctl/grpcvtctldserver" "vitess.io/vitess/go/vt/vtctl/vtctldclient" @@ -17,13 +18,23 @@ import ( vtctlservicepb "vitess.io/vitess/go/vt/proto/vtctlservice" ) +// annoyingly, this is duplicated with theu tests in package grpcvtctldserver. +// fine for now, I suppose. +func addKeyspace(ctx context.Context, t *testing.T, ts *topo.Server, ks *vtctldatapb.Keyspace) { + in := *ks.Keyspace // take a copy to avoid the XXX_ fields changing + + err := ts.CreateKeyspace(ctx, ks.Name, &in) + require.NoError(t, err) +} + func withTestServer( t *testing.T, server vtctlservicepb.VtctldServer, - test func(t *testing.T, addr string), + test func(t *testing.T, client vtctldclient.VtctldClient), ) { lis, err := nettest.NewLocalListener("tcp") require.NoError(t, err, "cannot create nettest listener") + defer lis.Close() s := grpc.NewServer() @@ -32,28 +43,68 @@ func withTestServer( go s.Serve(lis) defer s.Stop() - test(t, lis.Addr().String()) + client, err := vtctldclient.New("grpc", lis.Addr().String()) + require.NoError(t, err, "cannot create vtctld client") + + test(t, client) } -func TestGetKeyspace(t *testing.T) { +func TestFindAllShardsInKeyspace(t *testing.T) { ctx := context.Background() - ts := memorytopo.NewServer("cell1") vtctld := grpcvtctldserver.NewVtctldServer(ts) - withTestServer(t, vtctld, func(t *testing.T, addr string) { - client, err := vtctldclient.New("grpc", addr) + withTestServer(t, vtctld, func(t *testing.T, client vtctldclient.VtctldClient) { + ks := &vtctldatapb.Keyspace{ + Name: "testkeyspace", + Keyspace: &topodatapb.Keyspace{}, + } + addKeyspace(ctx, t, ts, ks) + + si1, err := ts.GetOrCreateShard(ctx, ks.Name, "-80") + require.NoError(t, err) + si2, err := ts.GetOrCreateShard(ctx, ks.Name, "80-") require.NoError(t, err) + resp, err := client.FindAllShardsInKeyspace(ctx, &vtctldatapb.FindAllShardsInKeyspaceRequest{Keyspace: ks.Name}) + assert.NoError(t, err) + assert.NotNil(t, resp) + + expected := map[string]*vtctldatapb.Shard{ + "-80": { + Keyspace: ks.Name, + Name: "-80", + Shard: si1.Shard, + }, + "80-": { + Keyspace: ks.Name, + Name: "80-", + Shard: si2.Shard, + }, + } + + assert.Equal(t, expected, resp.Shards) + + client.Close() + _, err = client.FindAllShardsInKeyspace(ctx, &vtctldatapb.FindAllShardsInKeyspaceRequest{Keyspace: ks.Name}) + assert.Error(t, err) + }) +} + +func TestGetKeyspace(t *testing.T) { + ctx := context.Background() + + ts := memorytopo.NewServer("cell1") + vtctld := grpcvtctldserver.NewVtctldServer(ts) + + withTestServer(t, vtctld, func(t *testing.T, client vtctldclient.VtctldClient) { expected := &vtctldatapb.Keyspace{ Name: "testkeyspace", Keyspace: &topodatapb.Keyspace{ ShardingColumnName: "col1", }, } - in := *expected.Keyspace - - ts.CreateKeyspace(ctx, expected.Name, &in) + addKeyspace(ctx, t, ts, expected) resp, err := client.GetKeyspace(ctx, &vtctldatapb.GetKeyspaceRequest{Keyspace: expected.Name}) assert.NoError(t, err) @@ -71,10 +122,7 @@ func TestGetKeyspaces(t *testing.T) { ts := memorytopo.NewServer("cell1") vtctld := grpcvtctldserver.NewVtctldServer(ts) - withTestServer(t, vtctld, func(t *testing.T, addr string) { - client, err := vtctldclient.New("grpc", addr) - require.NoError(t, err) - + withTestServer(t, vtctld, func(t *testing.T, client vtctldclient.VtctldClient) { resp, err := client.GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{}) assert.NoError(t, err) assert.Empty(t, resp.Keyspaces) @@ -83,10 +131,7 @@ func TestGetKeyspaces(t *testing.T) { Name: "testkeyspace", Keyspace: &topodatapb.Keyspace{}, } - in := *expected.Keyspace - - err = ts.CreateKeyspace(ctx, expected.Name, &in) - require.NoError(t, err) + addKeyspace(ctx, t, ts, expected) resp, err = client.GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{}) assert.NoError(t, err) From 5b1618c2af5e07afe517194c6f8e7f294305a899 Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Thu, 17 Dec 2020 15:44:16 -0500 Subject: [PATCH 3/4] Fix copyright notices Signed-off-by: Andrew Mason --- go/cmd/vtctldclient/commands.go | 16 ++++++++++++++++ go/cmd/vtctldclient/main.go | 2 +- go/cmd/vtctldclient/plugin_grpcvtctldclient.go | 2 +- go/vt/vtctl/grpcvtctldclient/client.go | 16 ++++++++++++++++ go/vt/vtctl/grpcvtctldclient/client_test.go | 16 ++++++++++++++++ go/vt/vtctl/grpcvtctldserver/server.go | 16 ++++++++++++++++ go/vt/vtctl/grpcvtctldserver/server_test.go | 17 +++++++++++++++++ 7 files changed, 83 insertions(+), 2 deletions(-) diff --git a/go/cmd/vtctldclient/commands.go b/go/cmd/vtctldclient/commands.go index dc706d9a372..a57dafac6dd 100644 --- a/go/cmd/vtctldclient/commands.go +++ b/go/cmd/vtctldclient/commands.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 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 main import ( diff --git a/go/cmd/vtctldclient/main.go b/go/cmd/vtctldclient/main.go index 0d8412ee2d8..f00eee7a410 100644 --- a/go/cmd/vtctldclient/main.go +++ b/go/cmd/vtctldclient/main.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The Vitess Authors. +Copyright 2020 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. diff --git a/go/cmd/vtctldclient/plugin_grpcvtctldclient.go b/go/cmd/vtctldclient/plugin_grpcvtctldclient.go index ca5320855d2..e93c2a6e700 100644 --- a/go/cmd/vtctldclient/plugin_grpcvtctldclient.go +++ b/go/cmd/vtctldclient/plugin_grpcvtctldclient.go @@ -1,5 +1,5 @@ /* -Copyright 2019 The Vitess Authors. +Copyright 2020 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. diff --git a/go/vt/vtctl/grpcvtctldclient/client.go b/go/vt/vtctl/grpcvtctldclient/client.go index e392b6b0d61..a63e349bfdc 100644 --- a/go/vt/vtctl/grpcvtctldclient/client.go +++ b/go/vt/vtctl/grpcvtctldclient/client.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 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 grpcvtctldclient contains the gRPC version of the vtctld client // protocol. package grpcvtctldclient diff --git a/go/vt/vtctl/grpcvtctldclient/client_test.go b/go/vt/vtctl/grpcvtctldclient/client_test.go index c052d7ace7a..519f5ce6782 100644 --- a/go/vt/vtctl/grpcvtctldclient/client_test.go +++ b/go/vt/vtctl/grpcvtctldclient/client_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 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 grpcvtctldclient_test import ( diff --git a/go/vt/vtctl/grpcvtctldserver/server.go b/go/vt/vtctl/grpcvtctldserver/server.go index da38eea872b..252c78dbba8 100644 --- a/go/vt/vtctl/grpcvtctldserver/server.go +++ b/go/vt/vtctl/grpcvtctldserver/server.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 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 grpcvtctldserver import ( diff --git a/go/vt/vtctl/grpcvtctldserver/server_test.go b/go/vt/vtctl/grpcvtctldserver/server_test.go index 70342b20d41..b48a4c470a0 100644 --- a/go/vt/vtctl/grpcvtctldserver/server_test.go +++ b/go/vt/vtctl/grpcvtctldserver/server_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2020 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 grpcvtctldserver import ( @@ -119,6 +135,7 @@ func TestGetKeyspaces(t *testing.T) { assert.Equal(t, expected, resp.Keyspaces) topofactory.SetError(errors.New("error from toposerver")) + _, err = vtctld.GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{}) assert.Error(t, err) } From 0d14b7edb27faa39c1d8f31853ede92da43236db Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Thu, 17 Dec 2020 15:57:13 -0500 Subject: [PATCH 4/4] Embed vtctldserver impl in wrangler, update FindAllShardsInKeyspace to be backwards-compat Signed-off-by: Andrew Mason --- go/vt/vtctl/vtctl.go | 15 +++++++-------- go/vt/wrangler/wrangler.go | 11 +++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/go/vt/vtctl/vtctl.go b/go/vt/vtctl/vtctl.go index 456d2001fc3..ea5748339ea 100644 --- a/go/vt/vtctl/vtctl.go +++ b/go/vt/vtctl/vtctl.go @@ -113,7 +113,6 @@ import ( "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/topo/topoproto" "vitess.io/vitess/go/vt/topotools" - "vitess.io/vitess/go/vt/vtctl/grpcvtctldserver" "vitess.io/vitess/go/vt/vterrors" "vitess.io/vitess/go/vt/wrangler" @@ -1767,9 +1766,7 @@ func commandGetKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags *fl keyspace := subFlags.Arg(0) - // TODO: make vtctld a field of the wrangler - vtctld := grpcvtctldserver.NewVtctldServer(wr.TopoServer()) - keyspaceInfo, err := vtctld.GetKeyspace(ctx, &vtctldatapb.GetKeyspaceRequest{ + keyspaceInfo, err := wr.VtctldServer().GetKeyspace(ctx, &vtctldatapb.GetKeyspaceRequest{ Keyspace: keyspace, }) if err != nil { @@ -1780,8 +1777,7 @@ func commandGetKeyspace(ctx context.Context, wr *wrangler.Wrangler, subFlags *fl } func commandGetKeyspaces(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { - vtctld := grpcvtctldserver.NewVtctldServer(wr.TopoServer()) - resp, err := vtctld.GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{}) + resp, err := wr.VtctldServer().GetKeyspaces(ctx, &vtctldatapb.GetKeyspacesRequest{}) if err != nil { return err } @@ -2250,11 +2246,14 @@ func commandFindAllShardsInKeyspace(ctx context.Context, wr *wrangler.Wrangler, } keyspace := subFlags.Arg(0) - result, err := wr.TopoServer().FindAllShardsInKeyspace(ctx, keyspace) + result, err := wr.VtctldServer().FindAllShardsInKeyspace(ctx, &vtctldatapb.FindAllShardsInKeyspaceRequest{ + Keyspace: keyspace, + }) if err != nil { return err } - return printJSON(wr.Logger(), result) + + return printJSON(wr.Logger(), result.Shards) } func commandValidate(ctx context.Context, wr *wrangler.Wrangler, subFlags *flag.FlagSet, args []string) error { diff --git a/go/vt/wrangler/wrangler.go b/go/vt/wrangler/wrangler.go index 83672b0f880..787f5008fc7 100644 --- a/go/vt/wrangler/wrangler.go +++ b/go/vt/wrangler/wrangler.go @@ -21,7 +21,10 @@ package wrangler import ( "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/topo" + "vitess.io/vitess/go/vt/vtctl/grpcvtctldserver" "vitess.io/vitess/go/vt/vttablet/tmclient" + + vtctlservicepb "vitess.io/vitess/go/vt/proto/vtctlservice" ) var ( @@ -42,6 +45,7 @@ type Wrangler struct { logger logutil.Logger ts *topo.Server tmc tmclient.TabletManagerClient + vtctld vtctlservicepb.VtctldServer } // New creates a new Wrangler object. @@ -50,6 +54,7 @@ func New(logger logutil.Logger, ts *topo.Server, tmc tmclient.TabletManagerClien logger: logger, ts: ts, tmc: tmc, + vtctld: grpcvtctldserver.NewVtctldServer(ts), } } @@ -64,6 +69,12 @@ func (wr *Wrangler) TabletManagerClient() tmclient.TabletManagerClient { return wr.tmc } +// VtctldServer returns the vtctlservicepb.VtctldServer implementation this +// wrangler is using. +func (wr *Wrangler) VtctldServer() vtctlservicepb.VtctldServer { + return wr.vtctld +} + // SetLogger can be used to change the current logger. Not synchronized, // no calls to this wrangler should be in progress. func (wr *Wrangler) SetLogger(logger logutil.Logger) {