Skip to content

Commit

Permalink
raftstore: attach peer tag to box errors (#6073)
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Shen <overvenus@gmail.com>
  • Loading branch information
sre-bot authored and overvenus committed Nov 27, 2019
1 parent 9eb8e98 commit f1aacba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
14 changes: 11 additions & 3 deletions src/raftstore/store/fsm/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,10 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> {
if self.fsm.peer.mut_store().check_applying_snap() {
self.ctx.raft_metrics.invalid_proposal.is_applying_snapshot += 1;
// TODO: replace to a more suitable error.
return Err(Error::Other(box_err!("peer is applying snapshot.")));
return Err(Error::Other(box_err!(
"{} peer is applying snapshot",
self.fsm.peer.tag
)));
}
// Check whether the term is stale.
if let Err(e) = util::check_term(msg, self.fsm.peer.term()) {
Expand Down Expand Up @@ -2602,7 +2605,10 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> {
);
match t {
PdTask::AskBatchSplit { callback, .. } => {
callback.invoke_with_response(new_error(box_err!("failed to split: Stopped")));
callback.invoke_with_response(new_error(box_err!(
"{} failed to split: Stopped",
self.fsm.peer.tag
)));
}
_ => unreachable!(),
}
Expand Down Expand Up @@ -3052,7 +3058,9 @@ impl<'a, T: Transport, C: PdClient> PeerFsmDelegate<'a, T, C> {
let mut response = match cmd_type {
StatusCmdType::RegionLeader => self.execute_region_leader(),
StatusCmdType::RegionDetail => self.execute_region_detail(request),
StatusCmdType::InvalidStatus => Err(box_err!("invalid status command!")),
StatusCmdType::InvalidStatus => {
Err(box_err!("{} invalid status command!", self.fsm.peer.tag))
}
}?;
response.set_cmd_type(cmd_type);

Expand Down
32 changes: 22 additions & 10 deletions src/raftstore/store/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ impl Peer {
"peer_id" => self.peer.get_id(),
"request" => ?change_peer,
);
return Err(box_err!("invalid conf change request"));
return Err(box_err!("{} invalid conf change request", self.tag));
}
_ => {}
}
Expand All @@ -1768,7 +1768,7 @@ impl Peer {
"peer_id" => self.peer.get_id(),
"request" => ?change_peer,
);
return Err(box_err!("ignore remove leader"));
return Err(box_err!("{} ignore remove leader", self.tag));
}

let status = self.raft_group.status_ref();
Expand Down Expand Up @@ -1882,16 +1882,19 @@ impl Peer {
|s| if s.map_or(true, |s| s.parse().unwrap_or(true)) {
Ok(())
} else {
Err(box_err!("can not read due to injected failure"))
Err(box_err!(
"{} can not read due to injected failure",
self.tag
))
}
);

// See more in ready_to_handle_read().
if self.is_splitting() {
return Err(box_err!("can not read index due to split"));
return Err(box_err!("{} can not read index due to split", self.tag));
}
if self.is_merging() {
return Err(box_err!("can not read index due to merge"));
return Err(box_err!("{} can not read index due to merge", self.tag));
}
Ok(())
}
Expand Down Expand Up @@ -1951,7 +1954,7 @@ impl Peer {
if !self.is_leader() && self.leader_id() == INVALID_ID {
cmd_resp::bind_error(
&mut err_resp,
box_err!("can not read index due to no leader"),
box_err!("{} can not read index due to no leader", self.tag),
);
poll_ctx.raft_metrics.invalid_proposal.read_index_no_leader += 1;
cb.invoke_with_response(err_resp);
Expand Down Expand Up @@ -2029,7 +2032,10 @@ impl Peer {
for entry in self.raft_group.raft.raft_log.entries(min_index, NO_LIMIT)? {
entry_size += entry.get_data().len();
if entry.get_entry_type() == EntryType::EntryConfChange {
return Err(box_err!("log gap contains conf change, skip merging."));
return Err(box_err!(
"{} log gap contains conf change, skip merging.",
self.tag
));
}
if entry.get_data().is_empty() {
continue;
Expand Down Expand Up @@ -2101,7 +2107,10 @@ impl Peer {
if self.pending_merge_state.is_some()
&& req.get_admin_request().get_cmd_type() != AdminCmdType::RollbackMerge
{
return Err(box_err!("peer in merging mode, can't do proposal."));
return Err(box_err!(
"{} peer in merging mode, can't do proposal.",
self.tag
));
}

poll_ctx.raft_metrics.propose.normal += 1;
Expand Down Expand Up @@ -2188,7 +2197,10 @@ impl Peer {
req: &RaftCmdRequest,
) -> Result<u64> {
if self.pending_merge_state.is_some() {
return Err(box_err!("peer in merging mode, can't do proposal."));
return Err(box_err!(
"{} peer in merging mode, can't do proposal.",
self.tag
));
}
if self.raft_group.raft.pending_conf_index > self.get_store().applied_index() {
info!(
Expand Down Expand Up @@ -2440,7 +2452,7 @@ pub trait RequestInspector {
}

if has_read && has_write {
return Err(box_err!("read and write can't be mixed in one batch."));
return Err(box_err!("read and write can't be mixed in one batch"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/raftstore/store/peer_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ pub fn do_snapshot(
let state: RegionLocalState = kv_snap
.get_msg_cf(CF_RAFT, &keys::region_state_key(key.region_id))
.and_then(|res| match res {
None => Err(box_err!("could not find region info")),
None => Err(box_err!("region {} could not find region info", region_id)),
Some(state) => Ok(state),
})?;

Expand Down

0 comments on commit f1aacba

Please sign in to comment.