Skip to content

Commit

Permalink
feat: enhanced the retry logic by adding a random noise (#4320)
Browse files Browse the repository at this point in the history
feat: enhanced the retry logic by adding a random noise to the retry delay to avoid retry storms
  • Loading branch information
WenyXu authored Jul 9, 2024
1 parent 23bb9d9 commit 1a9314a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions src/common/procedure/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ common-telemetry.workspace = true
futures.workspace = true
humantime-serde.workspace = true
object-store.workspace = true
rand.workspace = true
serde.workspace = true
serde_json.workspace = true
smallvec.workspace = true
Expand Down
7 changes: 7 additions & 0 deletions src/common/procedure/src/local/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::ops::Add;
use std::sync::Arc;
use std::time::Duration;

use backon::{BackoffBuilder, ExponentialBuilder};
use common_telemetry::{debug, error, info};
use rand::Rng;
use tokio::time;

use super::rwlock::OwnedKeyRwLockGuard;
Expand Down Expand Up @@ -198,6 +200,11 @@ impl Runner {
ProcedureState::Retrying { error } => {
retry_times += 1;
if let Some(d) = retry.next() {
let millis = d.as_millis() as u64;
// Add random noise to the retry delay to avoid retry storms.
let noise = rand::thread_rng().gen_range(0..(millis / 4) + 1);
let d = d.add(Duration::from_millis(noise));

self.wait_on_err(d, retry_times).await;
} else {
self.meta
Expand Down

0 comments on commit 1a9314a

Please sign in to comment.