Beispiel #1
0
// SendCopReq sends a Request to co-processor and receives Response.
func (c *rpcClient) SendCopReq(req *coprocessor.Request) (*coprocessor.Response, error) {
	conn, err := c.pool.Get()
	if err != nil {
		return nil, errors.Trace(err)
	}
	defer conn.Close()
	msg := msgpb.Message{
		MsgType: msgpb.MessageType_CopReq.Enum(),
		CopReq:  req,
	}
	err = c.doSend(conn, &msg)
	if err == nil {
		if msg.GetMsgType() != msgpb.MessageType_CopResp || msg.GetCopResp() == nil {
			err = errors.Trace(errInvalidResponse)
		}
	}
	if err != nil {
		// This connection is not valid any more, so close its underlying conn.
		if poolConn, ok := conn.(*pool.PoolConn); ok {
			poolConn.MarkUnusable()
		}
		return nil, errors.Trace(err)
	}
	return msg.GetCopResp(), nil
}
Beispiel #2
0
// SendCopReq sends a Request to co-processor and receives Response.
func (c *rpcClient) SendCopReq(addr string, req *coprocessor.Request, timeout time.Duration) (*coprocessor.Response, error) {
	sendReqCounter.WithLabelValues("cop").Inc()
	start := time.Now()
	defer func() { sendReqHistogram.WithLabelValues("cop").Observe(time.Since(start).Seconds()) }()

	conn, err := c.p.GetConn(addr)
	if err != nil {
		return nil, errors.Trace(err)
	}
	defer c.p.PutConn(conn)
	msg := msgpb.Message{
		MsgType: msgpb.MessageType_CopReq,
		CopReq:  req,
	}
	err = c.doSend(conn, &msg, writeTimeout, timeout)
	if err != nil {
		conn.Close()
		return nil, errors.Trace(err)
	}
	if msg.GetMsgType() != msgpb.MessageType_CopResp || msg.GetCopResp() == nil {
		conn.Close()
		return nil, errors.Trace(errInvalidResponse)
	}
	return msg.GetCopResp(), nil
}
Beispiel #3
0
// SendCopReq sends a Request to co-processor and receives Response.
func (c *rpcClient) SendCopReq(addr string, req *coprocessor.Request) (*coprocessor.Response, error) {
	conn, err := c.p.GetConn(addr)
	if err != nil {
		return nil, errors.Trace(err)
	}
	defer c.p.PutConn(conn)
	msg := msgpb.Message{
		MsgType: msgpb.MessageType_CopReq.Enum(),
		CopReq:  req,
	}
	err = c.doSend(conn, &msg)
	if err != nil {
		return nil, errors.Trace(err)
	}
	if msg.GetMsgType() != msgpb.MessageType_CopResp || msg.GetCopResp() == nil {
		return nil, errors.Trace(errInvalidResponse)
	}
	return msg.GetCopResp(), nil
}