Skip to content

Commit

Permalink
refactor!: consolidate DatanodeClientOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Nov 11, 2024
1 parent ac387bd commit 0c7b853
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 52 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -30,14 +32,14 @@ members = [
"src/common/telemetry",
"src/common/test-util",
"src/common/time",
"src/common/decimal",
"src/common/version",
"src/common/wal",
"src/datanode",
"src/datatypes",
"src/file-engine",
"src/flow",
"src/frontend",
"src/index",
"src/log-store",
"src/meta-client",
"src/meta-srv",
Expand All @@ -57,7 +59,6 @@ members = [
"src/sql",
"src/store-api",
"src/table",
"src/index",
"tests-fuzz",
"tests-integration",
"tests/runner",
Expand Down Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions src/cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions src/cmd/tests/load_config_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
13 changes: 13 additions & 0 deletions src/common/options/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
15 changes: 15 additions & 0 deletions src/common/options/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions src/frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/frontend/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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)]
Expand All @@ -42,7 +42,7 @@ pub struct FrontendOptions {
pub otlp: OtlpOptions,
pub meta_client: Option<MetaClientOptions>,
pub logging: LoggingOptions,
pub datanode: DatanodeOptions,
pub datanode: DatanodeClientOptions,
pub user_provider: Option<String>,
pub export_metrics: ExportMetricsOption,
pub tracing: TracingOptions,
Expand All @@ -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(),
Expand Down
3 changes: 0 additions & 3 deletions src/frontend/src/service_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
1 change: 1 addition & 0 deletions src/meta-srv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 3 additions & 32 deletions src/meta-srv/src/metasrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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(),
Expand All @@ -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,
Expand Down

0 comments on commit 0c7b853

Please sign in to comment.