From 73090e05c8ebe0cdf50d3233ced3eb04c791f411 Mon Sep 17 00:00:00 2001 From: Travis Date: Tue, 24 Dec 2019 11:25:08 -0600 Subject: [PATCH] Add StatusError to RowResponse for better error handling. This PR adds a `StatusError` to the `pproto.RowResponse` type, which allows a stream to pass an error on the stream (encoded into the `RowResponse.StatusError`). This can be checked downstream for matching `EOF` or `err != nil` and handled appropriately. This is helpful mainly with the `RowResponse` reducers which run in goroutines. Instead of trying to manage a separate channel of errors from those goroutines, we just follow the grpc model and send the error with the stream. --- proto/interface.go | 69 ++++++++++++++++++++++ proto/pilosa.pb.go | 141 ++++++++++++++++++++++++++++++++------------- proto/pilosa.proto | 5 ++ server/grpc.go | 9 ++- 4 files changed, 181 insertions(+), 43 deletions(-) diff --git a/proto/interface.go b/proto/interface.go index 0a3913921..f2157efe9 100644 --- a/proto/interface.go +++ b/proto/interface.go @@ -14,10 +14,79 @@ package pilosa +import ( + "fmt" + + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// StreamClient is an interface for a stream +// which can return a RowResponse sent to a +// stream via Send(). type StreamClient interface { Recv() (*RowResponse, error) } +// StreamServer is an interface for a stream +// which can accept a RowResponse to be later +// returned by the stream via Recv(). type StreamServer interface { Send(*RowResponse) error } + +// EOF acts as an io.EOF encoded into a RowResponse. +var EOF *RowResponse = &RowResponse{ + StatusError: &StatusError{ + Code: 0, + Message: "EOF", + }, +} + +// Error is a helper function to create a RowResponse +// based on an error message. If the error is a grpc +// Status, then the status code is passed through. +func Error(err error) *RowResponse { + status, _ := status.FromError(err) + return &RowResponse{ + StatusError: &StatusError{ + Code: uint32(status.Code()), + Message: status.Err().Error(), + }, + } +} + +// ErrorWrap prepends a message to the existing status +// error message. +func ErrorWrap(err error, message string) *RowResponse { + status, _ := status.FromError(err) + return &RowResponse{ + StatusError: &StatusError{ + Code: uint32(status.Code()), + Message: message + ": " + status.Err().Error(), + }, + } +} + +// ErrorWrapf prepends a message to the existing status +// error message with the format specifier. +func ErrorWrapf(err error, format string, args ...interface{}) *RowResponse { + status, _ := status.FromError(err) + return &RowResponse{ + StatusError: &StatusError{ + Code: uint32(status.Code()), + Message: fmt.Sprintf(format, args...) + ": " + status.Err().Error(), + }, + } +} + +// ErrorCode is a helper function to create a RowResponse +// based on a grpc status code and an error message. +func ErrorCode(err error, c codes.Code) *RowResponse { + return &RowResponse{ + StatusError: &StatusError{ + Code: uint32(c), + Message: err.Error(), + }, + } +} diff --git a/proto/pilosa.pb.go b/proto/pilosa.pb.go index 1a5bfca49..2cec94582 100644 --- a/proto/pilosa.pb.go +++ b/proto/pilosa.pb.go @@ -72,9 +72,57 @@ func (m *QueryPQLRequest) GetPql() string { return "" } +type StatusError struct { + Code uint32 `protobuf:"varint,1,opt,name=Code,proto3" json:"Code,omitempty"` + Message string `protobuf:"bytes,2,opt,name=Message,proto3" json:"Message,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *StatusError) Reset() { *m = StatusError{} } +func (m *StatusError) String() string { return proto.CompactTextString(m) } +func (*StatusError) ProtoMessage() {} +func (*StatusError) Descriptor() ([]byte, []int) { + return fileDescriptor_ef0691a44d1e275c, []int{1} +} + +func (m *StatusError) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_StatusError.Unmarshal(m, b) +} +func (m *StatusError) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_StatusError.Marshal(b, m, deterministic) +} +func (m *StatusError) XXX_Merge(src proto.Message) { + xxx_messageInfo_StatusError.Merge(m, src) +} +func (m *StatusError) XXX_Size() int { + return xxx_messageInfo_StatusError.Size(m) +} +func (m *StatusError) XXX_DiscardUnknown() { + xxx_messageInfo_StatusError.DiscardUnknown(m) +} + +var xxx_messageInfo_StatusError proto.InternalMessageInfo + +func (m *StatusError) GetCode() uint32 { + if m != nil { + return m.Code + } + return 0 +} + +func (m *StatusError) GetMessage() string { + if m != nil { + return m.Message + } + return "" +} + type RowResponse struct { Headers []*ColumnInfo `protobuf:"bytes,1,rep,name=headers,proto3" json:"headers,omitempty"` Columns []*ColumnResponse `protobuf:"bytes,2,rep,name=columns,proto3" json:"columns,omitempty"` + StatusError *StatusError `protobuf:"bytes,3,opt,name=StatusError,proto3" json:"StatusError,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -84,7 +132,7 @@ func (m *RowResponse) Reset() { *m = RowResponse{} } func (m *RowResponse) String() string { return proto.CompactTextString(m) } func (*RowResponse) ProtoMessage() {} func (*RowResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ef0691a44d1e275c, []int{1} + return fileDescriptor_ef0691a44d1e275c, []int{2} } func (m *RowResponse) XXX_Unmarshal(b []byte) error { @@ -119,6 +167,13 @@ func (m *RowResponse) GetColumns() []*ColumnResponse { return nil } +func (m *RowResponse) GetStatusError() *StatusError { + if m != nil { + return m.StatusError + } + return nil +} + type ColumnInfo struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Datatype string `protobuf:"bytes,2,opt,name=datatype,proto3" json:"datatype,omitempty"` @@ -131,7 +186,7 @@ func (m *ColumnInfo) Reset() { *m = ColumnInfo{} } func (m *ColumnInfo) String() string { return proto.CompactTextString(m) } func (*ColumnInfo) ProtoMessage() {} func (*ColumnInfo) Descriptor() ([]byte, []int) { - return fileDescriptor_ef0691a44d1e275c, []int{2} + return fileDescriptor_ef0691a44d1e275c, []int{3} } func (m *ColumnInfo) XXX_Unmarshal(b []byte) error { @@ -186,7 +241,7 @@ func (m *ColumnResponse) Reset() { *m = ColumnResponse{} } func (m *ColumnResponse) String() string { return proto.CompactTextString(m) } func (*ColumnResponse) ProtoMessage() {} func (*ColumnResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_ef0691a44d1e275c, []int{3} + return fileDescriptor_ef0691a44d1e275c, []int{4} } func (m *ColumnResponse) XXX_Unmarshal(b []byte) error { @@ -501,7 +556,7 @@ func (m *InspectRequest) Reset() { *m = InspectRequest{} } func (m *InspectRequest) String() string { return proto.CompactTextString(m) } func (*InspectRequest) ProtoMessage() {} func (*InspectRequest) Descriptor() ([]byte, []int) { - return fileDescriptor_ef0691a44d1e275c, []int{4} + return fileDescriptor_ef0691a44d1e275c, []int{5} } func (m *InspectRequest) XXX_Unmarshal(b []byte) error { @@ -568,7 +623,7 @@ func (m *Uint64Array) Reset() { *m = Uint64Array{} } func (m *Uint64Array) String() string { return proto.CompactTextString(m) } func (*Uint64Array) ProtoMessage() {} func (*Uint64Array) Descriptor() ([]byte, []int) { - return fileDescriptor_ef0691a44d1e275c, []int{5} + return fileDescriptor_ef0691a44d1e275c, []int{6} } func (m *Uint64Array) XXX_Unmarshal(b []byte) error { @@ -607,7 +662,7 @@ func (m *StringArray) Reset() { *m = StringArray{} } func (m *StringArray) String() string { return proto.CompactTextString(m) } func (*StringArray) ProtoMessage() {} func (*StringArray) Descriptor() ([]byte, []int) { - return fileDescriptor_ef0691a44d1e275c, []int{6} + return fileDescriptor_ef0691a44d1e275c, []int{7} } func (m *StringArray) XXX_Unmarshal(b []byte) error { @@ -649,7 +704,7 @@ func (m *IdsOrKeys) Reset() { *m = IdsOrKeys{} } func (m *IdsOrKeys) String() string { return proto.CompactTextString(m) } func (*IdsOrKeys) ProtoMessage() {} func (*IdsOrKeys) Descriptor() ([]byte, []int) { - return fileDescriptor_ef0691a44d1e275c, []int{7} + return fileDescriptor_ef0691a44d1e275c, []int{8} } func (m *IdsOrKeys) XXX_Unmarshal(b []byte) error { @@ -783,6 +838,7 @@ func _IdsOrKeys_OneofSizer(msg proto.Message) (n int) { func init() { proto.RegisterType((*QueryPQLRequest)(nil), "pilosa.QueryPQLRequest") + proto.RegisterType((*StatusError)(nil), "pilosa.StatusError") proto.RegisterType((*RowResponse)(nil), "pilosa.RowResponse") proto.RegisterType((*ColumnInfo)(nil), "pilosa.ColumnInfo") proto.RegisterType((*ColumnResponse)(nil), "pilosa.ColumnResponse") @@ -954,38 +1010,41 @@ var _Pilosa_serviceDesc = grpc.ServiceDesc{ func init() { proto.RegisterFile("pilosa.proto", fileDescriptor_ef0691a44d1e275c) } var fileDescriptor_ef0691a44d1e275c = []byte{ - // 524 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xdd, 0x8a, 0xd3, 0x40, - 0x14, 0xce, 0x34, 0xd9, 0xb4, 0x39, 0x2d, 0x55, 0x8f, 0xb2, 0x96, 0x22, 0x12, 0x73, 0x63, 0x44, - 0x59, 0x96, 0x2a, 0x82, 0xb2, 0x5e, 0xb8, 0x82, 0xb4, 0x28, 0xb8, 0x3b, 0xe2, 0xde, 0x4f, 0x37, - 0xd3, 0x35, 0x38, 0xcd, 0x64, 0x33, 0x53, 0xb5, 0xb7, 0xbe, 0x8b, 0x4f, 0xe4, 0x0b, 0xc9, 0x4c, - 0x7e, 0x9a, 0x2c, 0x74, 0xef, 0x72, 0xbe, 0xef, 0x3b, 0x67, 0xce, 0x6f, 0x60, 0x94, 0xa7, 0x42, - 0x2a, 0x76, 0x94, 0x17, 0x52, 0x4b, 0xf4, 0x4b, 0x2b, 0x7a, 0x03, 0x77, 0xce, 0x37, 0xbc, 0xd8, - 0x9e, 0x9d, 0x7f, 0xa6, 0xfc, 0x7a, 0xc3, 0x95, 0xc6, 0x07, 0x70, 0x90, 0x66, 0x09, 0xff, 0x3d, - 0x21, 0x21, 0x89, 0x03, 0x5a, 0x1a, 0x78, 0x17, 0xdc, 0xfc, 0x5a, 0x4c, 0x7a, 0x16, 0x33, 0x9f, - 0xd1, 0x1a, 0x86, 0x54, 0xfe, 0xa2, 0x5c, 0xe5, 0x32, 0x53, 0x1c, 0x5f, 0x40, 0xff, 0x3b, 0x67, - 0x09, 0x2f, 0xd4, 0x84, 0x84, 0x6e, 0x3c, 0x9c, 0xe1, 0x51, 0xf5, 0xe2, 0x07, 0x29, 0x36, 0xeb, - 0x6c, 0x91, 0xad, 0x24, 0xad, 0x25, 0x78, 0x0c, 0xfd, 0x4b, 0x0b, 0xab, 0x49, 0xcf, 0xaa, 0x0f, - 0xbb, 0xea, 0x3a, 0x2c, 0xad, 0x65, 0xd1, 0x09, 0xc0, 0x2e, 0x10, 0x22, 0x78, 0x19, 0x5b, 0xf3, - 0x2a, 0x47, 0xfb, 0x8d, 0x53, 0x18, 0x24, 0x4c, 0x33, 0xbd, 0xcd, 0x79, 0x95, 0x67, 0x63, 0x47, - 0xff, 0x7a, 0x30, 0xee, 0x46, 0xc6, 0xc7, 0x10, 0x28, 0x5d, 0xa4, 0xd9, 0xd5, 0x05, 0x13, 0x65, - 0x9c, 0xb9, 0x43, 0x77, 0x90, 0xe1, 0x37, 0x69, 0xa6, 0x5f, 0xbf, 0x32, 0xbc, 0x89, 0xe7, 0x19, - 0xbe, 0x81, 0xf0, 0x11, 0x0c, 0x1a, 0xda, 0x0d, 0x49, 0xec, 0xce, 0x1d, 0xda, 0x20, 0x38, 0x85, - 0xfe, 0x52, 0x4a, 0x61, 0x48, 0x2f, 0x24, 0xf1, 0x60, 0xee, 0xd0, 0x1a, 0xb0, 0x9c, 0x90, 0x4b, - 0xc3, 0x1d, 0x84, 0x24, 0x1e, 0x59, 0xae, 0x04, 0xf0, 0x1d, 0x8c, 0xcb, 0x27, 0xde, 0x17, 0x05, - 0xdb, 0x1a, 0x89, 0x1f, 0x92, 0x78, 0x38, 0xbb, 0x5f, 0xf7, 0xe7, 0xdb, 0x8e, 0x9d, 0x3b, 0xf4, - 0x86, 0xd8, 0xb8, 0x97, 0x15, 0x34, 0xee, 0xfd, 0xae, 0xfb, 0xd7, 0x1d, 0x6b, 0xdc, 0xbb, 0x62, - 0x0c, 0x01, 0x56, 0x42, 0xb2, 0xaa, 0xaa, 0x41, 0x48, 0x62, 0x32, 0x77, 0x68, 0x0b, 0x3b, 0x1d, - 0x42, 0x50, 0x4e,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, 0x38, 0x04, 0x00, 0x00, + // 568 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x54, 0xdd, 0x6e, 0xd3, 0x30, + 0x14, 0x8e, 0x97, 0x2c, 0x69, 0x4e, 0xc6, 0x00, 0x83, 0x46, 0x54, 0x21, 0x14, 0x72, 0x43, 0x10, + 0x68, 0x9a, 0xca, 0x8f, 0x04, 0x8c, 0x0b, 0x36, 0x81, 0x5a, 0x01, 0x62, 0x33, 0x62, 0xf7, 0xee, + 0xe2, 0x96, 0x08, 0x37, 0xce, 0x62, 0x17, 0xe8, 0x2d, 0xcf, 0x02, 0x4f, 0xc4, 0x0b, 0x21, 0x3b, + 0x3f, 0x4d, 0x2a, 0x95, 0x3b, 0x9f, 0xef, 0xfb, 0xce, 0xf1, 0xf9, 0xb3, 0x61, 0xaf, 0xc8, 0xb8, + 0x90, 0xf4, 0xb0, 0x28, 0x85, 0x12, 0xd8, 0xad, 0xac, 0xf8, 0x05, 0x5c, 0x3f, 0x5f, 0xb2, 0x72, + 0x75, 0x76, 0xfe, 0x81, 0xb0, 0xab, 0x25, 0x93, 0x0a, 0xdf, 0x86, 0xdd, 0x2c, 0x4f, 0xd9, 0xcf, + 0x10, 0x45, 0x28, 0xf1, 0x49, 0x65, 0xe0, 0x1b, 0x60, 0x17, 0x57, 0x3c, 0xdc, 0x31, 0x98, 0x3e, + 0xc6, 0xaf, 0x20, 0xf8, 0xac, 0xa8, 0x5a, 0xca, 0xb7, 0x65, 0x29, 0x4a, 0x8c, 0xc1, 0x39, 0x15, + 0x29, 0x33, 0x5e, 0xd7, 0x88, 0x39, 0xe3, 0x10, 0xbc, 0x8f, 0x4c, 0x4a, 0x3a, 0x67, 0xb5, 0x63, + 0x63, 0xc6, 0xbf, 0x11, 0x04, 0x44, 0xfc, 0x20, 0x4c, 0x16, 0x22, 0x97, 0x0c, 0x3f, 0x06, 0xef, + 0x2b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e, 0x0f, 0x6e, 0x9f, + 0x65, 0x7f, 0x5e, 0x5b, 0x7d, 0xa7, 0xae, 0xf9, 0x9d, 0x9e, 0xfc, 0x0b, 0x00, 0x00, 0xff, 0xff, + 0x9e, 0xd3, 0x7d, 0xab, 0xad, 0x04, 0x00, 0x00, } diff --git a/proto/pilosa.proto b/proto/pilosa.proto index 9a5828624..b7b30d521 100644 --- a/proto/pilosa.proto +++ b/proto/pilosa.proto @@ -6,10 +6,15 @@ message QueryPQLRequest { string pql = 2; } +message StatusError{ + uint32 Code = 1; + string Message = 2; +} message RowResponse{ repeated ColumnInfo headers = 1; repeated ColumnResponse columns = 2; + StatusError StatusError = 3; } message ColumnInfo { diff --git a/server/grpc.go b/server/grpc.go index a0ef90cbe..f4f0648e8 100644 --- a/server/grpc.go +++ b/server/grpc.go @@ -42,10 +42,16 @@ type grpcHandler struct { // to the error (returning it as a status.Error). It is // assumed that the input err is non-nil. func errToStatusError(err error) error { + // Check error string. switch errors.Cause(err) { case pilosa.ErrIndexNotFound, pilosa.ErrFieldNotFound: return status.Error(codes.NotFound, err.Error()) } + // Check error type. + switch errors.Cause(err).(type) { + case pilosa.NotFoundError: + return status.Error(codes.NotFound, err.Error()) + } return status.Error(codes.Unknown, err.Error()) } @@ -75,7 +81,7 @@ func (h grpcHandler) Inspect(req *pb.InspectRequest, stream pb.Pilosa_InspectSer index, err := h.api.Index(context.Background(), req.Index) if err != nil { - return errors.Wrap(err, "getting index") + return errToStatusError(err) } var fields []*pilosa.Field @@ -315,7 +321,6 @@ func (h grpcHandler) Inspect(req *pb.InspectRequest, stream pb.Pilosa_InspectSer } resp, err := h.api.Query(context.Background(), &query) if err != nil { - fmt.Println("GOT ERROR trying to get ALL():", err) return errors.Wrapf(err, "querying for all: %s", pql) }