Skip to content

Commit

Permalink
fix: only retry if unavailable or deadline exceeded
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Aug 21, 2023
1 parent 5710837 commit 6746454
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/meta-client/src/client/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use common_telemetry::{info, warn};
use snafu::{ensure, ResultExt};
use tokio::sync::RwLock;
use tonic::transport::Channel;
use tonic::Code;

use crate::client::ask_leader::AskLeader;
use crate::client::Id;
Expand Down Expand Up @@ -139,11 +140,7 @@ impl Inner {
if let Some(leader) = &ask_leader.get_leader() {
let mut client = self.make_client(leader)?;

match client
.submit_ddl_task(req.clone())
.await
.map_err(error::Error::from)
{
match client.submit_ddl_task(req.clone()).await {
Ok(res) => {
let res = res.into_inner();

Expand All @@ -160,13 +157,17 @@ impl Inner {
}
return Ok(res);
}
// The leader may be unreachable.
Err(err) => {
warn!("Failed to submitting ddl to {leader}, source: {err}");
let leader = ask_leader.ask_leader().await?;
info!("DDL client updated to new leader addr: {leader}");
times += 1;
continue;
// The leader may be unreachable.
if err.code() == Code::Unavailable || err.code() == Code::DeadlineExceeded {
warn!("Failed to submitting ddl to {leader}, source: {err}");
let leader = ask_leader.ask_leader().await?;
info!("DDL client updated to new leader addr: {leader}");
times += 1;
continue;
} else {
return Err(error::Error::from(err));
}
}
}
} else if let Err(err) = ask_leader.ask_leader().await {
Expand All @@ -175,7 +176,7 @@ impl Inner {
}

error::RetryTimesExceededSnafu {
msg: "Failed to submit DDL client",
msg: "Failed to submit DDL task",
}
.fail()
}
Expand Down

0 comments on commit 6746454

Please sign in to comment.