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 23, 2024
1 parent c4f1dcb commit 313b819
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
2 changes: 2 additions & 0 deletions workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ clap = { version = "4", features = ["derive"] }
crypto-common = { version = "0.1", default-features = false, features = ["std"] }
digest = { version = "0.10", features = ["mac", "std"] }
either = { version = "1", default-features = false, features = ["use_std"] }
etcd-client = { version = "0.13", default-features = false, features = ["tls"] }
futures-channel = { version = "0.3", features = ["sink"] }
futures-util = { version = "0.3", features = ["channel", "io", "sink"] }
getrandom = { version = "0.2", default-features = false, features = ["js", "rdrand", "std"] }
Expand Down Expand Up @@ -57,5 +58,6 @@ predicates = { version = "3", default-features = false, features = ["diff"] }
syn-dff4ba8e3ae991db = { package = "syn", version = "1", features = ["extra-traits", "full"] }
syn-f595c2ba2a3f28df = { package = "syn", version = "2", features = ["extra-traits", "full", "visit", "visit-mut"] }
tokio = { version = "1", features = ["fs", "io-std", "io-util", "macros", "net", "rt-multi-thread", "signal", "sync", "time"] }
tonic-build = { version = "0.11" }

### END HAKARI SECTION

0 comments on commit 313b819

Please sign in to comment.