Skip to content

Commit

Permalink
fix: generate propose id inside client retry closure
Browse files Browse the repository at this point in the history
Because client id may change during retry, the propose id generation must be called for each retry

Signed-off-by: bsbds <[email protected]>
  • Loading branch information
bsbds committed Aug 15, 2024
1 parent a00ccb8 commit 124cca4
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions crates/curp/src/client/retry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,9 @@ where
token: Option<&String>,
use_fast_path: bool,
) -> Result<ProposeResponse<Self::Cmd>, tonic::Status> {
let propose_id = self.inner.gen_propose_id()?;
self.retry::<_, _>(|client| {
RepeatableClientApi::propose(client, *propose_id, cmd, token, use_fast_path)
self.retry::<_, _>(|client| async move {
let propose_id = self.inner.gen_propose_id()?;
RepeatableClientApi::propose(client, *propose_id, cmd, token, use_fast_path).await
})
.await
}
Expand All @@ -236,19 +236,23 @@ where
&self,
changes: Vec<ConfChange>,
) -> Result<Vec<Member>, tonic::Status> {
let propose_id = self.inner.gen_propose_id()?;
self.retry::<_, _>(|client| {
let changes_c = changes.clone();
RepeatableClientApi::propose_conf_change(client, *propose_id, changes_c)
async move {
let propose_id = self.inner.gen_propose_id()?;
RepeatableClientApi::propose_conf_change(client, *propose_id, changes_c).await
}
})
.await
}

/// Send propose to shutdown cluster
async fn propose_shutdown(&self) -> Result<(), tonic::Status> {
let propose_id = self.inner.gen_propose_id()?;
self.retry::<_, _>(|client| RepeatableClientApi::propose_shutdown(client, *propose_id))
.await
self.retry::<_, _>(|client| async move {
let propose_id = self.inner.gen_propose_id()?;
RepeatableClientApi::propose_shutdown(client, *propose_id).await
})
.await
}

/// Send propose to publish a node id and name
Expand All @@ -258,17 +262,20 @@ where
node_name: String,
node_client_urls: Vec<String>,
) -> Result<(), Self::Error> {
let propose_id = self.inner.gen_propose_id()?;
self.retry::<_, _>(|client| {
let name_c = node_name.clone();
let node_client_urls_c = node_client_urls.clone();
RepeatableClientApi::propose_publish(
client,
*propose_id,
node_id,
name_c,
node_client_urls_c,
)
async move {
let propose_id = self.inner.gen_propose_id()?;
RepeatableClientApi::propose_publish(
client,
*propose_id,
node_id,
name_c,
node_client_urls_c,
)
.await
}
})
.await
}
Expand Down

0 comments on commit 124cca4

Please sign in to comment.