mirror of https://github.com/tikv/client-rust.git
pd: handle get members with error (#452)
Signed-off-by: Ping Yu <yuping@pingcap.com>
This commit is contained in:
parent
ac9542152f
commit
bf8241e9c5
|
@ -111,6 +111,8 @@ pub enum Error {
|
||||||
},
|
},
|
||||||
#[error("Transaction not found error: {:?}", _0)]
|
#[error("Transaction not found error: {:?}", _0)]
|
||||||
TxnNotFound(kvrpcpb::TxnNotFound),
|
TxnNotFound(kvrpcpb::TxnNotFound),
|
||||||
|
#[error("PD has no leader")]
|
||||||
|
PdNoLeader,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<crate::proto::errorpb::Error> for Error {
|
impl From<crate::proto::errorpb::Error> for Error {
|
||||||
|
|
|
@ -16,6 +16,7 @@ use tonic::Request;
|
||||||
use super::timestamp::TimestampOracle;
|
use super::timestamp::TimestampOracle;
|
||||||
use crate::internal_err;
|
use crate::internal_err;
|
||||||
use crate::proto::pdpb;
|
use crate::proto::pdpb;
|
||||||
|
use crate::Error;
|
||||||
use crate::Result;
|
use crate::Result;
|
||||||
use crate::SecurityManager;
|
use crate::SecurityManager;
|
||||||
use crate::Timestamp;
|
use crate::Timestamp;
|
||||||
|
@ -46,7 +47,7 @@ impl Cluster {
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
) -> Result<pdpb::GetRegionResponse> {
|
) -> Result<pdpb::GetRegionResponse> {
|
||||||
let mut req = pd_request!(self.id, pdpb::GetRegionRequest);
|
let mut req = pd_request!(self.id, pdpb::GetRegionRequest);
|
||||||
req.region_key = key.clone();
|
req.region_key = key;
|
||||||
req.send(&mut self.client, timeout).await
|
req.send(&mut self.client, timeout).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,6 +204,16 @@ impl Connection {
|
||||||
.get_members(pdpb::GetMembersRequest::default())
|
.get_members(pdpb::GetMembersRequest::default())
|
||||||
.await?
|
.await?
|
||||||
.into_inner();
|
.into_inner();
|
||||||
|
if let Some(err) = resp
|
||||||
|
.header
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|header| header.error.as_ref())
|
||||||
|
{
|
||||||
|
return Err(internal_err!("failed to get PD members, err {:?}", err));
|
||||||
|
}
|
||||||
|
if resp.leader.is_none() {
|
||||||
|
return Err(Error::PdNoLeader);
|
||||||
|
}
|
||||||
Ok((client, resp))
|
Ok((client, resp))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue