From 090b7e61ca7996f0cac5ccc2d3d525b065936e1d Mon Sep 17 00:00:00 2001 From: Sunray Ley Date: Tue, 1 Aug 2023 18:49:41 +0800 Subject: [PATCH] feat: make the gRPC channel between Frontend and Datanode configurable (#2044) * feat: expose frontend datanode_client_options * chore: add configuration options to the configuration file * refactor(frontend): extract DatanodeOptions to service_config * refactor(frontend): extract DatanodeOptions to service_config * style: remove unnecessary suffix in variable name Co-authored-by: Yingwen * feat: use humantime_serde for readable duration --------- Co-authored-by: Yingwen --- Cargo.lock | 1 + config/frontend.example.toml | 8 ++++ src/frontend/Cargo.toml | 1 + src/frontend/src/frontend.rs | 6 ++- src/frontend/src/service_config.rs | 3 ++ src/frontend/src/service_config/datanode.rs | 44 +++++++++++++++++++++ 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 src/frontend/src/service_config/datanode.rs diff --git a/Cargo.lock b/Cargo.lock index 6c868476ea..4751b4251c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3284,6 +3284,7 @@ dependencies = [ "file-table-engine", "futures", "futures-util", + "humantime-serde", "itertools 0.10.5", "meta-client", "meta-srv", diff --git a/config/frontend.example.toml b/config/frontend.example.toml index 7980b1bf26..fc0f7a14f7 100644 --- a/config/frontend.example.toml +++ b/config/frontend.example.toml @@ -70,3 +70,11 @@ tcp_nodelay = true # [logging] # dir = "/tmp/greptimedb/logs" # level = "info" + +# Datanode options. +[datanode] +# Datanode client options. +[datanode.client] +timeout = "10s" +connect_timeout = "10s" +tcp_nodelay = true diff --git a/src/frontend/Cargo.toml b/src/frontend/Cargo.toml index 3dccd48ca2..a22f9465b2 100644 --- a/src/frontend/Cargo.toml +++ b/src/frontend/Cargo.toml @@ -38,6 +38,7 @@ datatypes = { path = "../datatypes" } file-table-engine = { path = "../file-table-engine" } futures = "0.3" futures-util.workspace = true +humantime-serde = "1.1" itertools.workspace = true meta-client = { path = "../meta-client" } meter-macros.workspace = true diff --git a/src/frontend/src/frontend.rs b/src/frontend/src/frontend.rs index caebeb6654..a0c10c6f64 100644 --- a/src/frontend/src/frontend.rs +++ b/src/frontend/src/frontend.rs @@ -20,8 +20,8 @@ use servers::http::HttpOptions; use servers::Mode; use crate::service_config::{ - GrpcOptions, InfluxdbOptions, MysqlOptions, OpentsdbOptions, OtlpOptions, PostgresOptions, - PromStoreOptions, PrometheusOptions, + DatanodeOptions, GrpcOptions, InfluxdbOptions, MysqlOptions, OpentsdbOptions, OtlpOptions, + PostgresOptions, PromStoreOptions, PrometheusOptions, }; #[derive(Clone, Debug, Serialize, Deserialize)] @@ -41,6 +41,7 @@ pub struct FrontendOptions { pub otlp_options: Option, pub meta_client_options: Option, pub logging: LoggingOptions, + pub datanode: DatanodeOptions, } impl Default for FrontendOptions { @@ -60,6 +61,7 @@ impl Default for FrontendOptions { otlp_options: Some(OtlpOptions::default()), meta_client_options: None, logging: LoggingOptions::default(), + datanode: DatanodeOptions::default(), } } } diff --git a/src/frontend/src/service_config.rs b/src/frontend/src/service_config.rs index 6102b0c37d..c23edbc159 100644 --- a/src/frontend/src/service_config.rs +++ b/src/frontend/src/service_config.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +pub mod datanode; pub mod grpc; pub mod influxdb; pub mod mysql; @@ -29,3 +30,5 @@ pub use otlp::OtlpOptions; pub use postgres::PostgresOptions; pub use prom_store::PromStoreOptions; pub use prometheus::PrometheusOptions; + +pub use self::datanode::DatanodeOptions; diff --git a/src/frontend/src/service_config/datanode.rs b/src/frontend/src/service_config/datanode.rs new file mode 100644 index 0000000000..1b01c4a942 --- /dev/null +++ b/src/frontend/src/service_config/datanode.rs @@ -0,0 +1,44 @@ +// Copyright 2023 Greptime Team +// +// 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::time::Duration; + +use common_grpc::channel_manager; +use serde::{Deserialize, Serialize}; + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] +pub struct DatanodeOptions { + client: DatanodeClientOptions, +} + +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct DatanodeClientOptions { + #[serde(with = "humantime_serde")] + pub timeout: Duration, + #[serde(with = "humantime_serde")] + pub connect_timeout: Duration, + pub tcp_nodelay: bool, +} + +impl Default for DatanodeClientOptions { + fn default() -> Self { + Self { + timeout: Duration::from_secs(channel_manager::DEFAULT_GRPC_REQUEST_TIMEOUT_SECS), + connect_timeout: Duration::from_secs( + channel_manager::DEFAULT_GRPC_CONNECT_TIMEOUT_SECS, + ), + tcp_nodelay: true, + } + } +}