fix fail test cases
@@ -91,7 +91,7 @@ pub struct MetaNodeStatus {
pub last_applied: LogId,
- pub leader: NodeId,
+ pub leader: Option<Node>,
pub voters: Vec<Node>,
@@ -651,7 +651,7 @@ impl MetaNode {
.map_err(|_| MetaError::MetaServiceError("get db_size failed".to_string()))?;
let metrics = self.raft.metrics().borrow().clone();
-
+ if let Some(leader_id) = metrics.current_leader {
Ok(MetaNodeStatus {
id: self.sto.id,
endpoint: self.sto.endpoint.to_string(),
@@ -664,10 +664,15 @@ impl MetaNode {
Some(id) => id,
None => LogId::new(0, 0),
},
- leader: metrics.current_leader.unwrap_or(0),
+ leader: self.get_node(&leader_id).await?,
voters,
non_voters,
})
+ } else {
+ Err(MetaError::MetaServiceError(
+ "failed to get leader".to_string(),
+ ))
+ }
}
#[tracing::instrument(level = "debug", skip(self))]
