// SendKVReq sends a Request to kv server and receives Response. func (c *rpcClient) SendKVReq(req *kvrpcpb.Request) (*kvrpcpb.Response, error) { conn, err := c.pool.Get() if err != nil { return nil, errors.Trace(err) } defer conn.Close() msg := msgpb.Message{ MsgType: msgpb.MessageType_KvReq.Enum(), KvReq: req, } err = c.doSend(conn, &msg) if err == nil { if msg.GetMsgType() != msgpb.MessageType_KvResp || msg.GetKvResp() == 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.GetKvResp(), nil }
// SendKVReq sends a Request to kv server and receives Response. func (c *rpcClient) SendKVReq(addr string, req *kvrpcpb.Request, timeout time.Duration) (*kvrpcpb.Response, error) { sendReqCounter.WithLabelValues("kv").Inc() start := time.Now() defer func() { sendReqHistogram.WithLabelValues("kv").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_KvReq, KvReq: req, } err = c.doSend(conn, &msg, writeTimeout, timeout) if err != nil { conn.Close() return nil, errors.Trace(err) } if msg.GetMsgType() != msgpb.MessageType_KvResp || msg.GetKvResp() == nil { conn.Close() return nil, errors.Trace(errInvalidResponse) } return msg.GetKvResp(), nil }
// SendKVReq sends a Request to kv server and receives Response. func (c *rpcClient) SendKVReq(addr string, req *kvrpcpb.Request) (*kvrpcpb.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_KvReq.Enum(), KvReq: req, } err = c.doSend(conn, &msg) if err != nil { return nil, errors.Trace(err) } if msg.GetMsgType() != msgpb.MessageType_KvResp || msg.GetKvResp() == nil { return nil, errors.Trace(errInvalidResponse) } return msg.GetKvResp(), nil }