Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add retry for flight service #16234

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
706c744
refactor: allow to encode data with arc
dqhl76 Aug 12, 2024
b05ad85
feat: add retry for do_get and do_action
dqhl76 Aug 22, 2024
f2e352f
refactor: change to do_exchange with a request-response flow
dqhl76 Sep 4, 2024
08136be
debug
dqhl76 Sep 11, 2024
76024d4
fixup
dqhl76 Sep 11, 2024
07a150a
fixup
dqhl76 Sep 12, 2024
4255129
fixup
dqhl76 Sep 12, 2024
3fb21c6
fixup
dqhl76 Sep 12, 2024
9630604
fixup
dqhl76 Sep 12, 2024
cd8d856
don't need cas, already mutex lock
dqhl76 Sep 12, 2024
1afe141
try to improve performance by change ack method
dqhl76 Sep 12, 2024
bab36ac
change window size
dqhl76 Sep 14, 2024
f116033
remove ack
dqhl76 Sep 14, 2024
f6ed9d9
Merge branch 'main' into test_remove_flight
dqhl76 Sep 14, 2024
fc6ed14
Merge branch 'main' into test_remove_flight
zhang2014 Sep 18, 2024
ab5afc2
apply review suggestion
dqhl76 Sep 19, 2024
af9a31a
Merge branch 'main' into test_remove_flight
zhang2014 Sep 19, 2024
2d56d33
fixup
dqhl76 Sep 19, 2024
e37a126
chore: use settings to support switch the feature on client side
dqhl76 Sep 20, 2024
2d50a4d
chore: use settings to support switch the feature on server side
dqhl76 Sep 20, 2024
f8aa71e
chore: refine to make clippy happy
dqhl76 Sep 20, 2024
984a62e
Merge branch 'main' into test_remove_flight
dqhl76 Sep 20, 2024
b064790
Merge branch 'main' into test_remove_flight
zhang2014 Sep 22, 2024
612e525
Merge branch 'main' into test_remove_flight
zhang2014 Sep 23, 2024
237725d
Merge branch 'main' into test_remove_flight
zhang2014 Oct 10, 2024
de9c0e4
Merge branch 'main' into test_remove_flight
dqhl76 Oct 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ geos = { version = "8.3", features = ["static", "geo", "geo-types"] }
geozero = { version = "0.13.0", features = ["default", "with-wkb", "with-geos", "with-geojson"] }
hashbrown = { version = "0.14.3", default-features = false }
http = "1"
hyper = "0.14.20"
itertools = "0.10.5"
jsonb = "0.4.1"
jwt-simple = "0.11.0"
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci/ci-run-stateful-tests-cluster-minio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export STORAGE_ALLOW_INSECURE=true

echo "Install dependence"
python3 -m pip install --quiet mysql-connector-python requests
sudo apt-get update -yq
sudo apt-get install -yq dsniff net-tools

echo "calling test suite"
echo "Starting Cluster databend-query"
Expand Down
2 changes: 2 additions & 0 deletions scripts/ci/ci-run-stateful-tests-standalone-minio.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export STORAGE_ALLOW_INSECURE=true

echo "Install dependence"
python3 -m pip install --quiet mysql-connector-python requests
sudo apt-get update -yq
sudo apt-get install -yq dsniff net-tools

echo "calling test suite"
echo "Starting standalone DatabendQuery(debug)"
Expand Down
1 change: 1 addition & 0 deletions src/common/exception/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ bincode = { workspace = true }
geos = { workspace = true }
geozero = { workspace = true }
http = { workspace = true }
hyper = { workspace = true }
opendal = { workspace = true }
parquet = { workspace = true }
paste = { workspace = true }
Expand Down
7 changes: 7 additions & 0 deletions src/common/exception/src/exception_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ impl From<tonic::Status> for ErrorCode {
tonic::Code::Unknown => {
let details = status.details();
if details.is_empty() {
if status.source().map_or(false, |e| e.is::<hyper::Error>()) {
return ErrorCode::CannotConnectNode(format!(
"{}, source: {:?}",
status.message(),
status.source()
));
}
return ErrorCode::UnknownException(format!(
"{}, source: {:?}",
status.message(),
Expand Down
39 changes: 31 additions & 8 deletions src/query/service/src/clusters/cluster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ use futures::future::Either;
use futures::Future;
use futures::StreamExt;
use log::error;
use log::info;
use log::warn;
use rand::thread_rng;
use rand::Rng;
use serde::Deserialize;
use serde::Serialize;
use tokio::time::sleep;

use crate::servers::flight::FlightClient;

Expand All @@ -79,7 +81,7 @@ pub trait ClusterHelper {

fn get_nodes(&self) -> Vec<Arc<NodeInfo>>;

async fn do_action<T: Serialize + Send, Res: for<'de> Deserialize<'de> + Send>(
async fn do_action<T: Serialize + Send + Clone, Res: for<'de> Deserialize<'de> + Send>(
&self,
path: &str,
message: HashMap<String, T>,
Expand Down Expand Up @@ -116,7 +118,7 @@ impl ClusterHelper for Cluster {
self.nodes.to_vec()
}

async fn do_action<T: Serialize + Send, Res: for<'de> Deserialize<'de> + Send>(
async fn do_action<T: Serialize + Send + Clone, Res: for<'de> Deserialize<'de> + Send>(
&self,
path: &str,
message: HashMap<String, T>,
Expand Down Expand Up @@ -145,12 +147,33 @@ impl ClusterHelper for Cluster {
let node_secret = node.secret.clone();

async move {
let mut conn = create_client(&config, &flight_address).await?;
Ok::<_, ErrorCode>((
id,
conn.do_action::<_, Res>(path, node_secret, message, timeout)
.await?,
))
let mut attempt = 0;
let max_attempts = 2;
dqhl76 marked this conversation as resolved.
Show resolved Hide resolved

loop {
let mut conn = create_client(&config, &flight_address).await?;
match conn
.do_action::<_, Res>(
path,
node_secret.clone(),
message.clone(),
timeout,
)
.await
{
Ok(result) => return Ok((id, result)),
Err(e)
if e.code() == ErrorCode::CANNOT_CONNECT_NODE
&& attempt < max_attempts =>
{
// only retry when error is network problem
info!("retry do_action, attempt: {}", attempt);
attempt += 1;
sleep(Duration::from_secs(1)).await;
}
Err(e) => return Err(e),
}
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ where
DataPacket::MutationStatus { .. } => unreachable!(),
DataPacket::DataCacheMetrics(_) => unreachable!(),
DataPacket::FragmentData(v) => Ok(vec![self.recv_data(meta.packet, v)?]),
DataPacket::FlightControl(_) => unreachable!(),
}
}
}
Expand Down
72 changes: 72 additions & 0 deletions src/query/service/src/servers/flight/codec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright 2021 Datafuse Labs
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::marker::PhantomData;
use std::sync::Arc;

use prost::Message;
use tonic::codec::Codec;
use tonic::codec::DecodeBuf;
use tonic::codec::Decoder;
use tonic::codec::EncodeBuf;
use tonic::codec::Encoder;
use tonic::Status;

#[derive(Default)]
pub struct MessageCodec<E, D>(PhantomData<(E, D)>);

impl<E: Message + 'static, D: Message + Default + 'static> Codec for MessageCodec<E, D> {
type Encode = Arc<E>;
type Decode = D;
type Encoder = ArcEncoder<E>;
type Decoder = DefaultDecoder<D>;

fn encoder(&mut self) -> Self::Encoder {
ArcEncoder(PhantomData)
}

fn decoder(&mut self) -> Self::Decoder {
DefaultDecoder(PhantomData)
}
}

pub struct ArcEncoder<E>(PhantomData<E>);

impl<T: Message> Encoder for ArcEncoder<T> {
type Item = Arc<T>;

type Error = Status;

fn encode(&mut self, item: Self::Item, dst: &mut EncodeBuf<'_>) -> Result<(), Self::Error> {
item.as_ref()
.encode(dst)
.map_err(|e| Status::internal(e.to_string()))
}
}

pub struct DefaultDecoder<D>(PhantomData<D>);

impl<T: Message + Default> Decoder for DefaultDecoder<T> {
type Item = T;

type Error = Status;

fn decode(&mut self, buf: &mut DecodeBuf<'_>) -> Result<Option<Self::Item>, Self::Error> {
let item = Message::decode(buf)
.map(Some)
.map_err(|e| Status::internal(e.to_string()))?;

Ok(item)
}
}
Loading
Loading