// DialTablet creates and initializes gRPCQueryClient. func DialTablet(ctx context.Context, endPoint *pbt.EndPoint, keyspace, shard string, timeout time.Duration) (tabletconn.TabletConn, error) { // create the RPC client addr := netutil.JoinHostPort(endPoint.Host, endPoint.PortMap["grpc"]) cc, err := grpc.Dial(addr, grpc.WithBlock(), grpc.WithTimeout(timeout)) if err != nil { return nil, err } c := pbs.NewQueryClient(cc) result := &gRPCQueryClient{ endPoint: endPoint, cc: cc, c: c, } if keyspace != "" || shard != "" { gsir, err := c.GetSessionId(ctx, &pb.GetSessionIdRequest{ Keyspace: keyspace, Shard: shard, }) if err != nil { cc.Close() return nil, err } if gsir.Error != nil { cc.Close() return nil, tabletErrorFromRPCError(gsir.Error) } result.sessionID = gsir.SessionId } return result, nil }
// DialTablet creates and initializes gRPCQueryClient. func DialTablet(tablet *topodatapb.Tablet, timeout time.Duration) (tabletconn.TabletConn, error) { // create the RPC client addr := "" if grpcPort, ok := tablet.PortMap["grpc"]; ok { addr = netutil.JoinHostPort(tablet.Hostname, grpcPort) } else { addr = tablet.Hostname } opt, err := grpcutils.ClientSecureDialOption(*cert, *key, *ca, *name) if err != nil { return nil, err } opts := []grpc.DialOption{opt} if timeout > 0 { opts = append(opts, grpc.WithBlock(), grpc.WithTimeout(timeout)) } cc, err := grpc.Dial(addr, opts...) if err != nil { return nil, err } c := queryservicepb.NewQueryClient(cc) result := &gRPCQueryClient{ tablet: tablet, cc: cc, c: c, } return result, nil }
// DialTablet creates and initializes gRPCQueryClient. func DialTablet(ctx context.Context, endPoint topo.EndPoint, keyspace, shard string, timeout time.Duration) (tabletconn.TabletConn, error) { // create the RPC client addr := netutil.JoinHostPort(endPoint.Host, endPoint.NamedPortMap["grpc"]) cc, err := grpc.Dial(addr) if err != nil { return nil, err } c := pbs.NewQueryClient(cc) gsir, err := c.GetSessionId(ctx, &pb.GetSessionIdRequest{ Keyspace: keyspace, Shard: shard, }) if err != nil { cc.Close() return nil, err } if gsir.Error != nil { cc.Close() return nil, tabletErrorFromRPCError(gsir.Error) } return &gRPCQueryClient{ endPoint: endPoint, cc: cc, c: c, sessionID: gsir.SessionId, }, nil }
// DialTablet creates and initializes gRPCQueryClient. func DialTablet(ctx context.Context, tablet *topodatapb.Tablet, timeout time.Duration) (tabletconn.TabletConn, error) { // create the RPC client addr := netutil.JoinHostPort(tablet.Hostname, tablet.PortMap["grpc"]) opt, err := grpcutils.ClientSecureDialOption(*cert, *key, *ca, *name) if err != nil { return nil, err } cc, err := grpc.Dial(addr, opt, grpc.WithBlock(), grpc.WithTimeout(timeout)) if err != nil { return nil, err } c := queryservicepb.NewQueryClient(cc) result := &gRPCQueryClient{ tablet: tablet, cc: cc, c: c, target: &querypb.Target{ Keyspace: tablet.Keyspace, Shard: tablet.Shard, TabletType: tablet.Type, }, } return result, nil }
// DialTablet creates and initializes gRPCQueryClient. func DialTablet(ctx context.Context, endPoint *pbt.EndPoint, keyspace, shard string, tabletType pbt.TabletType, timeout time.Duration) (tabletconn.TabletConn, error) { // create the RPC client addr := netutil.JoinHostPort(endPoint.Host, endPoint.PortMap["grpc"]) cc, err := grpc.Dial(addr, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(timeout)) if err != nil { return nil, err } c := pbs.NewQueryClient(cc) result := &gRPCQueryClient{ endPoint: endPoint, cc: cc, c: c, } if tabletType == pbt.TabletType_UNKNOWN { // we use session gsir, err := c.GetSessionId(ctx, &pb.GetSessionIdRequest{ Keyspace: keyspace, Shard: shard, }) if err != nil { cc.Close() return nil, err } result.sessionID = gsir.SessionId } else { // we use target result.target = &pb.Target{ Keyspace: keyspace, Shard: shard, TabletType: tabletType, } } return result, nil }