From c8623140879dda9b8b70da1a637979b9e9471757 Mon Sep 17 00:00:00 2001 From: David Finkel Date: Wed, 14 Jun 2023 18:32:01 -0400 Subject: [PATCH] grpc: Convert key to a bytes field Galaxycache is perfectly fine with non-UTF-8 keys, but some go Protobuf library versions validate UTF-8 conformance when serializing string-fields. We can side-step this by setting the field definitions to conform to the protobuf spec by putting our possibly-not-utf-8 strings in a bytes field. Fortunately, string and bytes fields are 100% wire compatible, so switching the type only creates a mild API break. I doubt anyone's using these protobuf messages directly, so I'm just going to declare that they aren't covered by v1.x compatibility. Also, regenerate the protobuf types with the current protobuf library (google.golang.org/protobuf instead of github.com/golang/protobuf). Include a test to guarantee that this does the right thing with invalid UTF-8. --- galaxycachepb/galaxycache.pb.go | 359 +++++++++++++++------------ galaxycachepb/galaxycache.proto | 6 +- galaxycachepb/galaxycache_grpc.pb.go | 124 +++++++++ grpc/grpc_test.go | 2 +- grpc/grpcclient.go | 7 +- grpc/grpcserver.go | 3 +- 6 files changed, 333 insertions(+), 168 deletions(-) create mode 100644 galaxycachepb/galaxycache_grpc.pb.go diff --git a/galaxycachepb/galaxycache.pb.go b/galaxycachepb/galaxycache.pb.go index 116e3d79..2c45fef1 100644 --- a/galaxycachepb/galaxycache.pb.go +++ b/galaxycachepb/galaxycache.pb.go @@ -1,212 +1,249 @@ +// +//Copyright 2012 Google Inc. +// +//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. + // Code generated by protoc-gen-go. DO NOT EDIT. -// source: galaxycache.proto +// versions: +// protoc-gen-go v1.30.0 +// protoc v3.21.12 +// source: galaxycachepb/galaxycache.proto package galaxycachepb import ( - context "context" - fmt "fmt" - proto "github.com/golang/protobuf/proto" - grpc "google.golang.org/grpc" - math "math" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" ) -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) type GetRequest struct { - Galaxy string `protobuf:"bytes,1,opt,name=galaxy,proto3" json:"galaxy,omitempty"` - Key string `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *GetRequest) Reset() { *m = GetRequest{} } -func (m *GetRequest) String() string { return proto.CompactTextString(m) } -func (*GetRequest) ProtoMessage() {} -func (*GetRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_23bd509ca7b74957, []int{0} -} + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func (m *GetRequest) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetRequest.Unmarshal(m, b) -} -func (m *GetRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetRequest.Marshal(b, m, deterministic) -} -func (m *GetRequest) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetRequest.Merge(m, src) -} -func (m *GetRequest) XXX_Size() int { - return xxx_messageInfo_GetRequest.Size(m) -} -func (m *GetRequest) XXX_DiscardUnknown() { - xxx_messageInfo_GetRequest.DiscardUnknown(m) + Galaxy string `protobuf:"bytes,1,opt,name=galaxy,proto3" json:"galaxy,omitempty"` + Key []byte `protobuf:"bytes,2,opt,name=key,proto3" json:"key,omitempty"` // not required/guaranteed to be UTF-8 } -var xxx_messageInfo_GetRequest proto.InternalMessageInfo - -func (m *GetRequest) GetGalaxy() string { - if m != nil { - return m.Galaxy +func (x *GetRequest) Reset() { + *x = GetRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_galaxycachepb_galaxycache_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) } - return "" } -func (m *GetRequest) GetKey() string { - if m != nil { - return m.Key - } - return "" +func (x *GetRequest) String() string { + return protoimpl.X.MessageStringOf(x) } -type GetResponse struct { - Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` - MinuteQps float64 `protobuf:"fixed64,2,opt,name=minute_qps,json=minuteQps,proto3" json:"minute_qps,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} +func (*GetRequest) ProtoMessage() {} -func (m *GetResponse) Reset() { *m = GetResponse{} } -func (m *GetResponse) String() string { return proto.CompactTextString(m) } -func (*GetResponse) ProtoMessage() {} -func (*GetResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_23bd509ca7b74957, []int{1} +func (x *GetRequest) ProtoReflect() protoreflect.Message { + mi := &file_galaxycachepb_galaxycache_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -func (m *GetResponse) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetResponse.Unmarshal(m, b) -} -func (m *GetResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetResponse.Marshal(b, m, deterministic) -} -func (m *GetResponse) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetResponse.Merge(m, src) -} -func (m *GetResponse) XXX_Size() int { - return xxx_messageInfo_GetResponse.Size(m) -} -func (m *GetResponse) XXX_DiscardUnknown() { - xxx_messageInfo_GetResponse.DiscardUnknown(m) +// Deprecated: Use GetRequest.ProtoReflect.Descriptor instead. +func (*GetRequest) Descriptor() ([]byte, []int) { + return file_galaxycachepb_galaxycache_proto_rawDescGZIP(), []int{0} } -var xxx_messageInfo_GetResponse proto.InternalMessageInfo - -func (m *GetResponse) GetValue() []byte { - if m != nil { - return m.Value +func (x *GetRequest) GetGalaxy() string { + if x != nil { + return x.Galaxy } - return nil + return "" } -func (m *GetResponse) GetMinuteQps() float64 { - if m != nil { - return m.MinuteQps +func (x *GetRequest) GetKey() []byte { + if x != nil { + return x.Key } - return 0 + return nil } -func init() { - proto.RegisterType((*GetRequest)(nil), "galaxycachepb.GetRequest") - proto.RegisterType((*GetResponse)(nil), "galaxycachepb.GetResponse") -} +type GetResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields -func init() { proto.RegisterFile("galaxycache.proto", fileDescriptor_23bd509ca7b74957) } + Value []byte `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"` + MinuteQps float64 `protobuf:"fixed64,2,opt,name=minute_qps,json=minuteQps,proto3" json:"minute_qps,omitempty"` +} -var fileDescriptor_23bd509ca7b74957 = []byte{ - // 186 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x4c, 0x4f, 0xcc, 0x49, - 0xac, 0xa8, 0x4c, 0x4e, 0x4c, 0xce, 0x48, 0xd5, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0xe2, 0x45, - 0x12, 0x2a, 0x48, 0x52, 0x32, 0xe3, 0xe2, 0x72, 0x4f, 0x2d, 0x09, 0x4a, 0x2d, 0x2c, 0x4d, 0x2d, - 0x2e, 0x11, 0x12, 0xe3, 0x62, 0x83, 0x48, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x06, 0x41, 0x79, - 0x42, 0x02, 0x5c, 0xcc, 0xd9, 0xa9, 0x95, 0x12, 0x4c, 0x60, 0x41, 0x10, 0x53, 0xc9, 0x89, 0x8b, - 0x1b, 0xac, 0xaf, 0xb8, 0x20, 0x3f, 0xaf, 0x38, 0x55, 0x48, 0x84, 0x8b, 0xb5, 0x2c, 0x31, 0xa7, - 0x34, 0x15, 0xac, 0x8f, 0x27, 0x08, 0xc2, 0x11, 0x92, 0xe5, 0xe2, 0xca, 0xcd, 0xcc, 0x2b, 0x2d, - 0x49, 0x8d, 0x2f, 0x2c, 0x28, 0x06, 0xeb, 0x66, 0x0c, 0xe2, 0x84, 0x88, 0x04, 0x16, 0x14, 0x1b, - 0x85, 0x72, 0x71, 0xbb, 0x83, 0xcd, 0x77, 0x06, 0x39, 0x46, 0xc8, 0x0d, 0x6c, 0xa4, 0x5b, 0x51, - 0x7e, 0x6e, 0x40, 0x6a, 0x6a, 0x91, 0x90, 0xa4, 0x1e, 0x8a, 0x4b, 0xf5, 0x10, 0xce, 0x94, 0x92, - 0xc2, 0x26, 0x05, 0x71, 0x89, 0x12, 0x43, 0x12, 0x1b, 0xd8, 0xa3, 0xc6, 0x80, 0x00, 0x00, 0x00, - 0xff, 0xff, 0x84, 0x48, 0x7a, 0xc8, 0xfd, 0x00, 0x00, 0x00, +func (x *GetResponse) Reset() { + *x = GetResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_galaxycachepb_galaxycache_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } } -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn +func (x *GetResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 +func (*GetResponse) ProtoMessage() {} -// GalaxyCacheClient is the client API for GalaxyCache service. -// -// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. -type GalaxyCacheClient interface { - GetFromPeer(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) +func (x *GetResponse) ProtoReflect() protoreflect.Message { + mi := &file_galaxycachepb_galaxycache_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) } -type galaxyCacheClient struct { - cc *grpc.ClientConn +// Deprecated: Use GetResponse.ProtoReflect.Descriptor instead. +func (*GetResponse) Descriptor() ([]byte, []int) { + return file_galaxycachepb_galaxycache_proto_rawDescGZIP(), []int{1} } -func NewGalaxyCacheClient(cc *grpc.ClientConn) GalaxyCacheClient { - return &galaxyCacheClient{cc} +func (x *GetResponse) GetValue() []byte { + if x != nil { + return x.Value + } + return nil } -func (c *galaxyCacheClient) GetFromPeer(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { - out := new(GetResponse) - err := c.cc.Invoke(ctx, "/galaxycachepb.GalaxyCache/GetFromPeer", in, out, opts...) - if err != nil { - return nil, err +func (x *GetResponse) GetMinuteQps() float64 { + if x != nil { + return x.MinuteQps } - return out, nil + return 0 } -// GalaxyCacheServer is the server API for GalaxyCache service. -type GalaxyCacheServer interface { - GetFromPeer(context.Context, *GetRequest) (*GetResponse, error) +var File_galaxycachepb_galaxycache_proto protoreflect.FileDescriptor + +var file_galaxycachepb_galaxycache_proto_rawDesc = []byte{ + 0x0a, 0x1f, 0x67, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x63, 0x61, 0x63, 0x68, 0x65, 0x70, 0x62, 0x2f, + 0x67, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x12, 0x0d, 0x67, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x63, 0x61, 0x63, 0x68, 0x65, 0x70, 0x62, + 0x22, 0x36, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x16, + 0x0a, 0x06, 0x67, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x67, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0c, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x42, 0x0a, 0x0b, 0x47, 0x65, 0x74, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1d, 0x0a, + 0x0a, 0x6d, 0x69, 0x6e, 0x75, 0x74, 0x65, 0x5f, 0x71, 0x70, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x01, 0x52, 0x09, 0x6d, 0x69, 0x6e, 0x75, 0x74, 0x65, 0x51, 0x70, 0x73, 0x32, 0x55, 0x0a, 0x0b, + 0x47, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x46, 0x0a, 0x0b, 0x47, + 0x65, 0x74, 0x46, 0x72, 0x6f, 0x6d, 0x50, 0x65, 0x65, 0x72, 0x12, 0x19, 0x2e, 0x67, 0x61, 0x6c, + 0x61, 0x78, 0x79, 0x63, 0x61, 0x63, 0x68, 0x65, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x67, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x63, 0x61, + 0x63, 0x68, 0x65, 0x70, 0x62, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x22, 0x00, 0x42, 0x2c, 0x5a, 0x2a, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, + 0x6d, 0x2f, 0x76, 0x69, 0x6d, 0x65, 0x6f, 0x2f, 0x67, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x63, 0x61, + 0x63, 0x68, 0x65, 0x2f, 0x67, 0x61, 0x6c, 0x61, 0x78, 0x79, 0x63, 0x61, 0x63, 0x68, 0x65, 0x70, + 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_galaxycachepb_galaxycache_proto_rawDescOnce sync.Once + file_galaxycachepb_galaxycache_proto_rawDescData = file_galaxycachepb_galaxycache_proto_rawDesc +) + +func file_galaxycachepb_galaxycache_proto_rawDescGZIP() []byte { + file_galaxycachepb_galaxycache_proto_rawDescOnce.Do(func() { + file_galaxycachepb_galaxycache_proto_rawDescData = protoimpl.X.CompressGZIP(file_galaxycachepb_galaxycache_proto_rawDescData) + }) + return file_galaxycachepb_galaxycache_proto_rawDescData } -func RegisterGalaxyCacheServer(s *grpc.Server, srv GalaxyCacheServer) { - s.RegisterService(&_GalaxyCache_serviceDesc, srv) +var file_galaxycachepb_galaxycache_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_galaxycachepb_galaxycache_proto_goTypes = []interface{}{ + (*GetRequest)(nil), // 0: galaxycachepb.GetRequest + (*GetResponse)(nil), // 1: galaxycachepb.GetResponse +} +var file_galaxycachepb_galaxycache_proto_depIdxs = []int32{ + 0, // 0: galaxycachepb.GalaxyCache.GetFromPeer:input_type -> galaxycachepb.GetRequest + 1, // 1: galaxycachepb.GalaxyCache.GetFromPeer:output_type -> galaxycachepb.GetResponse + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name } -func _GalaxyCache_GetFromPeer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetRequest) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(GalaxyCacheServer).GetFromPeer(ctx, in) +func init() { file_galaxycachepb_galaxycache_proto_init() } +func file_galaxycachepb_galaxycache_proto_init() { + if File_galaxycachepb_galaxycache_proto != nil { + return } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/galaxycachepb.GalaxyCache/GetFromPeer", + if !protoimpl.UnsafeEnabled { + file_galaxycachepb_galaxycache_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_galaxycachepb_galaxycache_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(GalaxyCacheServer).GetFromPeer(ctx, req.(*GetRequest)) - } - return interceptor(ctx, in, info, handler) -} - -var _GalaxyCache_serviceDesc = grpc.ServiceDesc{ - ServiceName: "galaxycachepb.GalaxyCache", - HandlerType: (*GalaxyCacheServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "GetFromPeer", - Handler: _GalaxyCache_GetFromPeer_Handler, + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_galaxycachepb_galaxycache_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "galaxycache.proto", + GoTypes: file_galaxycachepb_galaxycache_proto_goTypes, + DependencyIndexes: file_galaxycachepb_galaxycache_proto_depIdxs, + MessageInfos: file_galaxycachepb_galaxycache_proto_msgTypes, + }.Build() + File_galaxycachepb_galaxycache_proto = out.File + file_galaxycachepb_galaxycache_proto_rawDesc = nil + file_galaxycachepb_galaxycache_proto_goTypes = nil + file_galaxycachepb_galaxycache_proto_depIdxs = nil } diff --git a/galaxycachepb/galaxycache.proto b/galaxycachepb/galaxycache.proto index a30fb340..b47625e8 100644 --- a/galaxycachepb/galaxycache.proto +++ b/galaxycachepb/galaxycache.proto @@ -18,9 +18,11 @@ syntax = "proto3"; package galaxycachepb; +option go_package = "github.com/vimeo/galaxycache/galaxycachepb"; + message GetRequest { string galaxy = 1; - string key = 2; // not actually required/guaranteed to be UTF-8 + bytes key = 2; // not required/guaranteed to be UTF-8 } message GetResponse { @@ -30,4 +32,4 @@ message GetResponse { service GalaxyCache { rpc GetFromPeer(GetRequest) returns (GetResponse) {} -} \ No newline at end of file +} diff --git a/galaxycachepb/galaxycache_grpc.pb.go b/galaxycachepb/galaxycache_grpc.pb.go new file mode 100644 index 00000000..1576b8e4 --- /dev/null +++ b/galaxycachepb/galaxycache_grpc.pb.go @@ -0,0 +1,124 @@ +// +//Copyright 2012 Google Inc. +// +//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. + +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.3.0 +// - protoc v3.21.12 +// source: galaxycachepb/galaxycache.proto + +package galaxycachepb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +const ( + GalaxyCache_GetFromPeer_FullMethodName = "/galaxycachepb.GalaxyCache/GetFromPeer" +) + +// GalaxyCacheClient is the client API for GalaxyCache service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type GalaxyCacheClient interface { + GetFromPeer(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) +} + +type galaxyCacheClient struct { + cc grpc.ClientConnInterface +} + +func NewGalaxyCacheClient(cc grpc.ClientConnInterface) GalaxyCacheClient { + return &galaxyCacheClient{cc} +} + +func (c *galaxyCacheClient) GetFromPeer(ctx context.Context, in *GetRequest, opts ...grpc.CallOption) (*GetResponse, error) { + out := new(GetResponse) + err := c.cc.Invoke(ctx, GalaxyCache_GetFromPeer_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// GalaxyCacheServer is the server API for GalaxyCache service. +// All implementations must embed UnimplementedGalaxyCacheServer +// for forward compatibility +type GalaxyCacheServer interface { + GetFromPeer(context.Context, *GetRequest) (*GetResponse, error) + mustEmbedUnimplementedGalaxyCacheServer() +} + +// UnimplementedGalaxyCacheServer must be embedded to have forward compatible implementations. +type UnimplementedGalaxyCacheServer struct { +} + +func (UnimplementedGalaxyCacheServer) GetFromPeer(context.Context, *GetRequest) (*GetResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetFromPeer not implemented") +} +func (UnimplementedGalaxyCacheServer) mustEmbedUnimplementedGalaxyCacheServer() {} + +// UnsafeGalaxyCacheServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to GalaxyCacheServer will +// result in compilation errors. +type UnsafeGalaxyCacheServer interface { + mustEmbedUnimplementedGalaxyCacheServer() +} + +func RegisterGalaxyCacheServer(s grpc.ServiceRegistrar, srv GalaxyCacheServer) { + s.RegisterService(&GalaxyCache_ServiceDesc, srv) +} + +func _GalaxyCache_GetFromPeer_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(GalaxyCacheServer).GetFromPeer(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: GalaxyCache_GetFromPeer_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(GalaxyCacheServer).GetFromPeer(ctx, req.(*GetRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// GalaxyCache_ServiceDesc is the grpc.ServiceDesc for GalaxyCache service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var GalaxyCache_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "galaxycachepb.GalaxyCache", + HandlerType: (*GalaxyCacheServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetFromPeer", + Handler: _GalaxyCache_GetFromPeer_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "galaxycachepb/galaxycache.proto", +} diff --git a/grpc/grpc_test.go b/grpc/grpc_test.go index 625aee7e..75c367fb 100644 --- a/grpc/grpc_test.go +++ b/grpc/grpc_test.go @@ -124,7 +124,7 @@ func runTestPeerGRPCServer(ctx context.Context, t testing.TB, addresses []string func testKeys(n int) (keys []string) { keys = make([]string, n) for i := range keys { - keys[i] = strconv.Itoa(i) + keys[i] = strconv.Itoa(i) + "\270\201\000\001" } return } diff --git a/grpc/grpcclient.go b/grpc/grpcclient.go index d39f4c94..7235492e 100644 --- a/grpc/grpcclient.go +++ b/grpc/grpcclient.go @@ -19,11 +19,12 @@ package grpc import ( "context" - gc "github.com/vimeo/galaxycache" - pb "github.com/vimeo/galaxycache/galaxycachepb" "go.opencensus.io/plugin/ocgrpc" "go.opencensus.io/trace" + gc "github.com/vimeo/galaxycache" + pb "github.com/vimeo/galaxycache/galaxycachepb" + "google.golang.org/grpc" "google.golang.org/grpc/status" ) @@ -75,7 +76,7 @@ func (g *grpcFetcher) Fetch(ctx context.Context, galaxy string, key string) ([]b span.Annotatef(nil, "fetching from %s; connection state %s", g.address, g.conn.GetState()) resp, err := g.client.GetFromPeer(ctx, &pb.GetRequest{ Galaxy: galaxy, - Key: key, + Key: []byte(key), }) if err != nil { return nil, status.Errorf(status.Code(err), "Failed to fetch from peer over RPC [%q, %q]: %s", galaxy, g.address, err) diff --git a/grpc/grpcserver.go b/grpc/grpcserver.go index f4b8faf9..a14c6cf5 100644 --- a/grpc/grpcserver.go +++ b/grpc/grpcserver.go @@ -30,6 +30,7 @@ import ( // serviceImpl implements the GalaxyCacheServer // interface generated by the GalaxyCache pb service type serviceImpl struct { + pb.UnimplementedGalaxyCacheServer universe *gc.Universe } @@ -53,7 +54,7 @@ func (gp *serviceImpl) GetFromPeer(ctx context.Context, req *pb.GetRequest) (*pb galaxy.Stats.ServerRequests.Add(1) // keep track of the num of req var value unsafeByteCodec - err := galaxy.Get(ctx, req.Key, &value) + err := galaxy.Get(ctx, string(req.Key), &value) if err != nil { return nil, status.Errorf(status.Code(err), "Failed to retrieve [%s]: %v", req, err) }