Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: return early in fast_round if the recover_quorum condition is not met #835

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/curp/src/client/unary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tracing::{debug, warn};
use super::{state::State, ClientApi, LeaderStateUpdate, ProposeResponse, RepeatableClientApi};
use crate::{
members::ServerId,
quorum,
quorum, recover_quorum,
rpc::{
connect::ConnectApi, ConfChange, CurpError, FetchClusterRequest, FetchClusterResponse,
FetchReadStateRequest, Member, MoveLeaderRequest, ProposeConfChangeRequest, ProposeId,
Expand Down Expand Up @@ -97,19 +97,27 @@ impl<C: Command> Unary<C> {
})
.await;
let super_quorum = super_quorum(responses.len());
let recover_quorum = recover_quorum(responses.len());

let mut err: Option<CurpError> = None;
let mut execute_result: Option<C::ER> = None;
let mut ok_cnt = 0;
let (mut ok_cnt, mut key_conflict_cnt) = (0, 0);

while let Some((id, resp)) = responses.next().await {
if key_conflict_cnt >= recover_quorum {
return Err(CurpError::KeyConflict(()));
}

let resp = match resp {
Ok(resp) => resp.into_inner(),
Err(e) => {
warn!("propose cmd({propose_id}) to server({id}) error: {e:?}");
if e.should_abort_fast_round() {
return Err(e);
}
if matches!(e, CurpError::KeyConflict(())) {
key_conflict_cnt.add_assign(1);
}
if let Some(old_err) = err.as_ref() {
if old_err.priority() <= e.priority() {
err = Some(e);
Expand Down
Loading