// SplitQueryPartsToproto transforms a SplitQueryResponse into proto func SplitQueryPartsToProto(sqp []SplitQueryPart) *pb.SplitQueryResponse { result := &pb.SplitQueryResponse{} if len(sqp) == 0 { return result } result.Splits = make([]*pb.SplitQueryResponse_Part, len(sqp)) for i, split := range sqp { result.Splits[i] = &pb.SplitQueryResponse_Part{ Size: split.Size, } if split.Query != nil { result.Splits[i].Query = tproto.BoundQueryToProto3(split.Query.Sql, split.Query.BindVariables) result.Splits[i].KeyRangePart = &pb.SplitQueryResponse_KeyRangePart{ Keyspace: split.Query.Keyspace, KeyRanges: key.KeyRangesToProto(split.Query.KeyRanges), } } if split.QueryShard != nil { result.Splits[i].Query = tproto.BoundQueryToProto3(split.QueryShard.Sql, split.QueryShard.BindVariables) result.Splits[i].ShardPart = &pb.SplitQueryResponse_ShardPart{ Keyspace: split.QueryShard.Keyspace, Shards: split.QueryShard.Shards, } } } return result }
// StreamExecuteKeyRanges2 is the RPC version of // vtgateservice.VTGateService method func (vtg *VTGate) StreamExecuteKeyRanges2(ctx context.Context, request *proto.KeyRangeQuery, sendReply func(interface{}) error) (err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(ctx, callerid.GoRPCEffectiveCallerID(request.CallerID), callerid.NewImmediateCallerID("gorpc client")) vtgErr := vtg.server.StreamExecuteKeyRanges(ctx, request.Sql, request.BindVariables, request.Keyspace, key.KeyRangesToProto(request.KeyRanges), topo.TabletTypeToProto(request.TabletType), func(value *proto.QueryResult) error { return sendReply(value) }) if vtgErr == nil { return nil } if *vtgate.RPCErrorOnlyInReply { // If there was an app error, send a QueryResult back with it. qr := new(proto.QueryResult) vtgate.AddVtGateErrorToQueryResult(vtgErr, qr) // Sending back errors this way is not backwards compatible. If a (new) server sends an additional // QueryResult with an error, and the (old) client doesn't know how to read it, it will cause // problems where the client will get out of sync with the number of QueryResults sent. // That's why this the error is only sent this way when the --rpc_errors_only_in_reply flag is set // (signalling that all clients are able to handle new-style errors). return sendReply(qr) } return vtgErr }
func (conn *vtgateConn) StreamExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []key.KeyRange, bindVars map[string]interface{}, tabletType topo.TabletType) (<-chan *mproto.QueryResult, vtgateconn.ErrFunc, error) { req := &pb.StreamExecuteKeyRangesRequest{ Query: tproto.BoundQueryToProto3(query, bindVars), Keyspace: keyspace, KeyRanges: key.KeyRangesToProto(keyRanges), TabletType: topo.TabletTypeToProto(tabletType), } stream, err := conn.c.StreamExecuteKeyRanges(ctx, req) if err != nil { return nil, nil, err } sr := make(chan *mproto.QueryResult, 10) var finalError error go func() { for { ser, err := stream.Recv() if err != nil { if err != io.EOF { finalError = err } close(sr) return } if ser.Error != nil { finalError = vterrors.FromVtRPCError(ser.Error) close(sr) return } sr <- mproto.Proto3ToQueryResult(ser.Result) } }() return sr, func() error { return finalError }, nil }
// StreamExecuteKeyRanges is the RPC version of // vtgateservice.VTGateService method func (vtg *VTGate) StreamExecuteKeyRanges(ctx context.Context, request *proto.KeyRangeQuery, sendReply func(interface{}) error) (err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(ctx, callerid.GoRPCEffectiveCallerID(request.CallerID), callerid.NewImmediateCallerID("gorpc client")) return vtg.server.StreamExecuteKeyRanges(ctx, request.Sql, request.BindVariables, request.Keyspace, key.KeyRangesToProto(request.KeyRanges), topo.TabletTypeToProto(request.TabletType), func(value *proto.QueryResult) error { return sendReply(value) }) }
// ExecuteKeyRanges is the RPC version of vtgateservice.VTGateService method func (vtg *VTGate) ExecuteKeyRanges(ctx context.Context, request *proto.KeyRangeQuery, reply *proto.QueryResult) (err error) { defer vtg.server.HandlePanic(&err) ctx, cancel := context.WithDeadline(ctx, time.Now().Add(*rpcTimeout)) defer cancel() ctx = callerid.NewContext(ctx, callerid.GoRPCEffectiveCallerID(request.CallerID), callerid.NewImmediateCallerID("gorpc client")) vtgErr := vtg.server.ExecuteKeyRanges(ctx, request.Sql, request.BindVariables, request.Keyspace, key.KeyRangesToProto(request.KeyRanges), topo.TabletTypeToProto(request.TabletType), request.Session, request.NotInTransaction, reply) vtgate.AddVtGateError(vtgErr, &reply.Err) return nil }
func (conn *vtgateConn) ExecuteKeyRanges(ctx context.Context, query string, keyspace string, keyRanges []key.KeyRange, bindVars map[string]interface{}, tabletType topo.TabletType, notInTransaction bool, session interface{}) (*mproto.QueryResult, interface{}, error) { var s *pb.Session if session != nil { s = session.(*pb.Session) } request := &pb.ExecuteKeyRangesRequest{ Session: s, Query: tproto.BoundQueryToProto3(query, bindVars), Keyspace: keyspace, KeyRanges: key.KeyRangesToProto(keyRanges), TabletType: topo.TabletTypeToProto(tabletType), NotInTransaction: notInTransaction, } response, err := conn.c.ExecuteKeyRanges(ctx, request) if err != nil { return nil, session, err } if response.Error != nil { return nil, response.Session, vterrors.FromVtRPCError(response.Error) } return mproto.Proto3ToQueryResult(response.Result), response.Session, nil }
// StreamExecuteKeyRanges2 is the RPC version of // vtgateservice.VTGateService method func (vtg *VTGate) StreamExecuteKeyRanges2(ctx context.Context, request *proto.KeyRangeQuery, sendReply func(interface{}) error) (err error) { defer vtg.server.HandlePanic(&err) ctx = callerid.NewContext(ctx, callerid.GoRPCEffectiveCallerID(request.CallerID), callerid.NewImmediateCallerID("gorpc client")) vtgErr := vtg.server.StreamExecuteKeyRanges(ctx, request.Sql, request.BindVariables, request.Keyspace, key.KeyRangesToProto(request.KeyRanges), topo.TabletTypeToProto(request.TabletType), func(value *proto.QueryResult) error { return sendReply(value) }) if vtgErr == nil { return nil } // If there was an app error, send a QueryResult back with it. qr := new(proto.QueryResult) vtgate.AddVtGateError(vtgErr, &qr.Err) return sendReply(qr) }