diff --git a/Cargo.lock b/Cargo.lock index eb8a6f7db406..deed7dd233d8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1840,6 +1840,7 @@ dependencies = [ "common-grpc", "common-macro", "common-meta", + "common-options", "common-procedure", "common-query", "common-recordbatch", @@ -2239,6 +2240,15 @@ dependencies = [ "uuid", ] +[[package]] +name = "common-options" +version = "0.9.5" +dependencies = [ + "common-grpc", + "humantime-serde", + "serde", +] + [[package]] name = "common-plugins" version = "0.9.5" @@ -4173,6 +4183,7 @@ dependencies = [ "common-grpc", "common-macro", "common-meta", + "common-options", "common-procedure", "common-query", "common-recordbatch", @@ -6485,6 +6496,7 @@ dependencies = [ "common-grpc", "common-macro", "common-meta", + "common-options", "common-procedure", "common-procedure-test", "common-runtime", diff --git a/Cargo.toml b/Cargo.toml index a23e77d2576a..1b727aa4d704 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,23 +2,25 @@ members = [ "src/api", "src/auth", - "src/catalog", "src/cache", + "src/catalog", "src/client", "src/cmd", "src/common/base", "src/common/catalog", "src/common/config", "src/common/datasource", + "src/common/decimal", "src/common/error", "src/common/frontend", "src/common/function", - "src/common/macro", "src/common/greptimedb-telemetry", "src/common/grpc", "src/common/grpc-expr", + "src/common/macro", "src/common/mem-prof", "src/common/meta", + "src/common/options", "src/common/plugins", "src/common/pprof", "src/common/procedure", @@ -30,7 +32,6 @@ members = [ "src/common/telemetry", "src/common/test-util", "src/common/time", - "src/common/decimal", "src/common/version", "src/common/wal", "src/datanode", @@ -38,6 +39,7 @@ members = [ "src/file-engine", "src/flow", "src/frontend", + "src/index", "src/log-store", "src/meta-client", "src/meta-srv", @@ -57,7 +59,6 @@ members = [ "src/sql", "src/store-api", "src/table", - "src/index", "tests-fuzz", "tests-integration", "tests/runner", @@ -214,6 +215,7 @@ common-grpc-expr = { path = "src/common/grpc-expr" } common-macro = { path = "src/common/macro" } common-mem-prof = { path = "src/common/mem-prof" } common-meta = { path = "src/common/meta" } +common-options = { path = "src/common/options" } common-plugins = { path = "src/common/plugins" } common-pprof = { path = "src/common/pprof" } common-procedure = { path = "src/common/procedure" } diff --git a/src/cmd/Cargo.toml b/src/cmd/Cargo.toml index 6309d64294f7..95937567c371 100644 --- a/src/cmd/Cargo.toml +++ b/src/cmd/Cargo.toml @@ -33,6 +33,7 @@ common-error.workspace = true common-grpc.workspace = true common-macro.workspace = true common-meta.workspace = true +common-options.workspace = true common-procedure.workspace = true common-query.workspace = true common-recordbatch.workspace = true diff --git a/src/cmd/tests/load_config_test.rs b/src/cmd/tests/load_config_test.rs index bf4871e0bd5d..9f6857203f5e 100644 --- a/src/cmd/tests/load_config_test.rs +++ b/src/cmd/tests/load_config_test.rs @@ -20,13 +20,13 @@ use common_config::Configurable; use common_grpc::channel_manager::{ DEFAULT_MAX_GRPC_RECV_MESSAGE_SIZE, DEFAULT_MAX_GRPC_SEND_MESSAGE_SIZE, }; +use common_options::datanode::{ChannelOptions, DatanodeClientOptions}; use common_telemetry::logging::{LoggingOptions, SlowQueryOptions, DEFAULT_OTLP_ENDPOINT}; use common_wal::config::raft_engine::RaftEngineConfig; use common_wal::config::DatanodeWalConfig; use datanode::config::{DatanodeOptions, RegionEngineConfig, StorageConfig}; use file_engine::config::EngineConfig; use frontend::frontend::FrontendOptions; -use frontend::service_config::datanode::DatanodeClientOptions; use meta_client::MetaClientOptions; use meta_srv::metasrv::MetasrvOptions; use meta_srv::selector::SelectorType; @@ -126,10 +126,11 @@ fn test_load_frontend_example_config() { tracing_sample_ratio: Some(Default::default()), ..Default::default() }, - datanode: frontend::service_config::DatanodeOptions { - client: DatanodeClientOptions { + datanode: DatanodeClientOptions { + client: ChannelOptions { connect_timeout: Duration::from_secs(10), tcp_nodelay: true, + ..Default::default() }, }, export_metrics: ExportMetricsOption { @@ -166,8 +167,8 @@ fn test_load_metasrv_example_config() { }, ..Default::default() }, - datanode: meta_srv::metasrv::DatanodeOptions { - client: meta_srv::metasrv::DatanodeClientOptions { + datanode: DatanodeClientOptions { + client: ChannelOptions { timeout: Duration::from_secs(10), connect_timeout: Duration::from_secs(10), tcp_nodelay: true, diff --git a/src/common/options/Cargo.toml b/src/common/options/Cargo.toml new file mode 100644 index 000000000000..0a61c687c26f --- /dev/null +++ b/src/common/options/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "common-options" +version.workspace = true +edition.workspace = true +license.workspace = true + +[dependencies] +common-grpc.workspace = true +humantime-serde.workspace = true +serde.workspace = true + +[lints] +workspace = true diff --git a/src/frontend/src/service_config/datanode.rs b/src/common/options/src/datanode.rs similarity index 82% rename from src/frontend/src/service_config/datanode.rs rename to src/common/options/src/datanode.rs index 3b4de67b48c1..e68c80c14cee 100644 --- a/src/frontend/src/service_config/datanode.rs +++ b/src/common/options/src/datanode.rs @@ -18,20 +18,23 @@ use common_grpc::channel_manager; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] -pub struct DatanodeOptions { - pub client: DatanodeClientOptions, +pub struct DatanodeClientOptions { + pub client: ChannelOptions, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct DatanodeClientOptions { +pub struct ChannelOptions { + #[serde(with = "humantime_serde")] + pub timeout: Duration, #[serde(with = "humantime_serde")] pub connect_timeout: Duration, pub tcp_nodelay: bool, } -impl Default for DatanodeClientOptions { +impl Default for ChannelOptions { 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, ), diff --git a/src/common/options/src/lib.rs b/src/common/options/src/lib.rs new file mode 100644 index 000000000000..6c77623b7684 --- /dev/null +++ b/src/common/options/src/lib.rs @@ -0,0 +1,15 @@ +// 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. + +pub mod datanode; diff --git a/src/frontend/Cargo.toml b/src/frontend/Cargo.toml index 555a20128033..01f06eb03338 100644 --- a/src/frontend/Cargo.toml +++ b/src/frontend/Cargo.toml @@ -30,6 +30,7 @@ common-function.workspace = true common-grpc.workspace = true common-macro.workspace = true common-meta.workspace = true +common-options.workspace = true common-procedure.workspace = true common-query.workspace = true common-recordbatch.workspace = true diff --git a/src/frontend/src/frontend.rs b/src/frontend/src/frontend.rs index 91ee443af7a8..55f2dae3c386 100644 --- a/src/frontend/src/frontend.rs +++ b/src/frontend/src/frontend.rs @@ -13,6 +13,7 @@ // limitations under the License. use common_config::config::Configurable; +use common_options::datanode::DatanodeClientOptions; use common_telemetry::logging::{LoggingOptions, TracingOptions}; use meta_client::MetaClientOptions; use serde::{Deserialize, Serialize}; @@ -22,8 +23,7 @@ use servers::heartbeat_options::HeartbeatOptions; use servers::http::HttpOptions; use crate::service_config::{ - DatanodeOptions, InfluxdbOptions, MysqlOptions, OpentsdbOptions, OtlpOptions, PostgresOptions, - PromStoreOptions, + InfluxdbOptions, MysqlOptions, OpentsdbOptions, OtlpOptions, PostgresOptions, PromStoreOptions, }; #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] @@ -42,7 +42,7 @@ pub struct FrontendOptions { pub otlp: OtlpOptions, pub meta_client: Option, pub logging: LoggingOptions, - pub datanode: DatanodeOptions, + pub datanode: DatanodeClientOptions, pub user_provider: Option, pub export_metrics: ExportMetricsOption, pub tracing: TracingOptions, @@ -64,7 +64,7 @@ impl Default for FrontendOptions { otlp: OtlpOptions::default(), meta_client: None, logging: LoggingOptions::default(), - datanode: DatanodeOptions::default(), + datanode: DatanodeClientOptions::default(), user_provider: None, export_metrics: ExportMetricsOption::default(), tracing: TracingOptions::default(), diff --git a/src/frontend/src/service_config.rs b/src/frontend/src/service_config.rs index 1ee3833df8aa..a3fa7ad180d1 100644 --- a/src/frontend/src/service_config.rs +++ b/src/frontend/src/service_config.rs @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -pub mod datanode; pub mod influxdb; pub mod mysql; pub mod opentsdb; @@ -26,5 +25,3 @@ pub use opentsdb::OpentsdbOptions; pub use otlp::OtlpOptions; pub use postgres::PostgresOptions; pub use prom_store::PromStoreOptions; - -pub use self::datanode::DatanodeOptions; diff --git a/src/meta-srv/Cargo.toml b/src/meta-srv/Cargo.toml index d43686758271..71430ee992af 100644 --- a/src/meta-srv/Cargo.toml +++ b/src/meta-srv/Cargo.toml @@ -24,6 +24,7 @@ common-greptimedb-telemetry.workspace = true common-grpc.workspace = true common-macro.workspace = true common-meta.workspace = true +common-options.workspace = true common-procedure.workspace = true common-runtime.workspace = true common-telemetry.workspace = true diff --git a/src/meta-srv/src/metasrv.rs b/src/meta-srv/src/metasrv.rs index c9c9522d7bbb..11c41a58da7d 100644 --- a/src/meta-srv/src/metasrv.rs +++ b/src/meta-srv/src/metasrv.rs @@ -24,7 +24,6 @@ use common_base::readable_size::ReadableSize; use common_base::Plugins; use common_config::Configurable; use common_greptimedb_telemetry::GreptimeDBTelemetryTask; -use common_grpc::channel_manager; use common_meta::cache_invalidator::CacheInvalidatorRef; use common_meta::ddl::ProcedureExecutorRef; use common_meta::key::TableMetadataManagerRef; @@ -36,6 +35,7 @@ use common_meta::peer::Peer; use common_meta::region_keeper::MemoryRegionKeeperRef; use common_meta::wal_options_allocator::WalOptionsAllocatorRef; use common_meta::{distributed_time_constants, ClusterId}; +use common_options::datanode::DatanodeClientOptions; use common_procedure::options::ProcedureConfig; use common_procedure::ProcedureManagerRef; use common_telemetry::logging::{LoggingOptions, TracingOptions}; @@ -107,7 +107,7 @@ pub struct MetasrvOptions { /// The failure detector options. pub failure_detector: PhiAccrualFailureDetectorOptions, /// The datanode options. - pub datanode: DatanodeOptions, + pub datanode: DatanodeClientOptions, /// Whether to enable telemetry. pub enable_telemetry: bool, /// The data home directory. @@ -162,7 +162,7 @@ impl Default for MetasrvOptions { max_metadata_value_size: Some(ReadableSize::kb(1500)), }, failure_detector: PhiAccrualFailureDetectorOptions::default(), - datanode: DatanodeOptions::default(), + datanode: DatanodeClientOptions::default(), enable_telemetry: true, data_home: METASRV_HOME.to_string(), wal: MetasrvWalConfig::default(), @@ -185,35 +185,6 @@ impl Configurable for MetasrvOptions { pub struct MetasrvInfo { pub server_addr: String, } - -// Options for datanode. -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Default)] -pub struct DatanodeOptions { - pub client: DatanodeClientOptions, -} - -// Options for datanode client. -#[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, - } - } -} - #[derive(Clone)] pub struct Context { pub server_addr: String,