Skip to content

Commit e3fb645

Browse files
authored
[rust/rqd] Optimize retry mechanism and add logging info (#1881)
* When rqd fails to connect, don't swallow the failure message. * When on Retrying state, avoid cycling back to Initializing but start a new request immediatly and transition to Cloning.
1 parent 2a38e18 commit e3fb645

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

rust/config/rqd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ grpc:
5656
# Default: 10.0
5757
# backoff_jitter_percentage: 10.0
5858

59+
# Number of attempts to retry on Transport Error
60+
# Default: 20
61+
# backoff_retry_attempts: 10
62+
5963
# =============================================================================
6064
# MACHINE CONFIGURATION
6165
# =============================================================================

rust/crates/rqd/src/config/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct GrpcConfig {
4444
#[serde(with = "humantime_serde")]
4545
pub backoff_delay_max: Duration,
4646
pub backoff_jitter_percentage: f64,
47+
pub backoff_retry_attempts: usize,
4748
}
4849

4950
impl Default for GrpcConfig {
@@ -56,6 +57,7 @@ impl Default for GrpcConfig {
5657
backoff_delay_min: Duration::from_millis(10),
5758
backoff_delay_max: Duration::from_secs(60),
5859
backoff_jitter_percentage: 10.0,
60+
backoff_retry_attempts: 20,
5961
}
6062
}
6163
}

rust/crates/rqd/src/report/report_client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl ReportClient {
8989

9090
// Requests will retry indefinitely
9191
let retry_policy = BackoffPolicy {
92-
attempts: None,
92+
attempts: Some(config.backoff_retry_attempts),
9393
backoff,
9494
};
9595
let retry_layer = RetryLayer::new(retry_policy);

rust/crates/rqd/src/report/retry/backoff_policy.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ impl BackoffPolicy {
4545
pub fn has_attempts_left(&mut self) -> bool {
4646
match self.attempts {
4747
Some(0) => false,
48-
Some(ref mut attemps_left) => {
49-
*attemps_left -= 1;
48+
Some(ref mut attempts_left) => {
49+
*attempts_left -= 1;
5050
true
5151
}
5252
None => true,
5353
}
5454
}
5555
}
5656

57-
impl<E> Policy<Req, Res, E> for BackoffPolicy {
57+
impl<E: std::fmt::Display> Policy<Req, Res, E> for BackoffPolicy {
5858
type Future = tokio::time::Sleep;
5959
type ClonedOutput = ClonedReq<Req>;
6060
type ClonedFuture = Pin<Box<dyn std::future::Future<Output = Self::ClonedOutput> + Send>>;
@@ -78,9 +78,9 @@ impl<E> Policy<Req, Res, E> for BackoffPolicy {
7878
Outcome::Return(result)
7979
}
8080
}
81-
Err(_err) => {
81+
Err(err) => {
8282
if self.has_attempts_left() {
83-
warn!("Retrying for Transport error.");
83+
warn!("Retrying for Transport error. {}", err);
8484
// Retry all transport errors
8585
Outcome::Retry(self.backoff.next_backoff())
8686
} else {
@@ -110,7 +110,6 @@ pub struct ClonedReq<Req> {
110110
pub original_req: Req,
111111
pub cloned_req: Req,
112112
}
113-
114113
impl ClonedRequest<Req> for ClonedReq<Req> {
115114
fn inner(self) -> (Req, Req) {
116115
(self.original_req, self.cloned_req)

rust/crates/rqd/src/report/retry/future.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,17 @@ where
136136

137137
StateProj::Retrying => {
138138
ready!(this.retry.as_mut().project().service.poll_ready(cx))?;
139-
trace!("Retrying");
140-
this.state.set(State::Initialized);
139+
trace!("Retrying - making fresh call");
140+
141+
// Take the request and clone it for retry
142+
let req = this
143+
.request
144+
.take()
145+
.expect("request should be available for retry");
146+
let clone_future = this.retry.policy.clone_request(req);
147+
this.state.set(State::Cloning {
148+
future: clone_future,
149+
});
141150
}
142151
}
143152
}

0 commit comments

Comments
 (0)