Skip to content

Commit

Permalink
Improve: Use Unreachable error in examples/raft-kv-rocksdb
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Mar 19, 2024
1 parent a2a2b91 commit 0557895
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/raft-kv-memstore/src/network/raft_network_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Network {
tracing::debug!("client is created for: {}", url);

let resp = client.post(url).json(&req).send().await.map_err(|e| {
// If the error is a connection error, we return Unreachable so that connection isn't retried
// If the error is a connection error, we return `Unreachable` so that connection isn't retried
// immediately.
if e.is_connect() {
return openraft::error::RPCError::Unreachable(Unreachable::new(&e));
Expand Down
9 changes: 8 additions & 1 deletion examples/raft-kv-rocksdb/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::sync::Mutex;
use openraft::error::NetworkError;
use openraft::error::RPCError;
use openraft::error::RemoteError;
use openraft::error::Unreachable;
use openraft::RaftMetrics;
use openraft::TryAsRef;
use reqwest::Client;
Expand Down Expand Up @@ -143,7 +144,13 @@ impl ExampleClient {
}
.send()
.await
.map_err(|e| RPCError::Network(NetworkError::new(&e)))?;
.map_err(|e| {
if e.is_connect() {
// `Unreachable` informs the caller to backoff for a short while to avoid error log flush.
return RPCError::Unreachable(Unreachable::new(&e));
}
RPCError::Network(NetworkError::new(&e))
})?;

let res: Result<Resp, Err> = resp.json().await.map_err(|e| RPCError::Network(NetworkError::new(&e)))?;
println!(
Expand Down

0 comments on commit 0557895

Please sign in to comment.