diff --git a/config/config.md b/config/config.md index d94352ffef..df9d6c3d91 100644 --- a/config/config.md +++ b/config/config.md @@ -100,7 +100,7 @@ | `query` | -- | -- | The query engine options. | | `query.parallelism` | Integer | `0` | Parallelism of the query engine.
Default to 0, which means the number of CPU cores. | | `storage` | -- | -- | The data storage options. | -| `storage.data_home` | String | `./greptimedb_data/` | The working home directory. | +| `storage.data_home` | String | `./greptimedb_data` | The working home directory. | | `storage.type` | String | `File` | The storage type used to store the data.
- `File`: the data is stored in the local file system.
- `S3`: the data is stored in the S3 object storage.
- `Gcs`: the data is stored in the Google Cloud Storage.
- `Azblob`: the data is stored in the Azure Blob Storage.
- `Oss`: the data is stored in the Aliyun OSS. | | `storage.cache_path` | String | Unset | Read cache configuration for object storage such as 'S3' etc, it's configured by default when using object storage. It is recommended to configure it when using object storage for better performance.
A local file directory, defaults to `{data_home}`. An empty string means disabling. | | `storage.cache_capacity` | String | Unset | The local file cache capacity in bytes. If your disk space is sufficient, it is recommended to set it larger. | @@ -314,7 +314,7 @@ | Key | Type | Default | Descriptions | | --- | -----| ------- | ----------- | -| `data_home` | String | `./greptimedb_data/metasrv/` | The working home directory. | +| `data_home` | String | `./greptimedb_data` | The working home directory. | | `bind_addr` | String | `127.0.0.1:3002` | The bind address of metasrv. | | `server_addr` | String | `127.0.0.1:3002` | The communication server address for the frontend and datanode to connect to metasrv.
If left empty or unset, the server will automatically use the IP address of the first network interface
on the host, with the same port number as the one specified in `bind_addr`. | | `store_addrs` | Array | -- | Store server address default to etcd store.
For postgres store, the format is:
"password=password dbname=postgres user=postgres host=localhost port=5432"
For etcd store, the format is:
"127.0.0.1:2379" | @@ -446,7 +446,7 @@ | `query` | -- | -- | The query engine options. | | `query.parallelism` | Integer | `0` | Parallelism of the query engine.
Default to 0, which means the number of CPU cores. | | `storage` | -- | -- | The data storage options. | -| `storage.data_home` | String | `./greptimedb_data/` | The working home directory. | +| `storage.data_home` | String | `./greptimedb_data` | The working home directory. | | `storage.type` | String | `File` | The storage type used to store the data.
- `File`: the data is stored in the local file system.
- `S3`: the data is stored in the S3 object storage.
- `Gcs`: the data is stored in the Google Cloud Storage.
- `Azblob`: the data is stored in the Azure Blob Storage.
- `Oss`: the data is stored in the Aliyun OSS. | | `storage.cache_path` | String | Unset | Read cache configuration for object storage such as 'S3' etc, it's configured by default when using object storage. It is recommended to configure it when using object storage for better performance.
A local file directory, defaults to `{data_home}`. An empty string means disabling. | | `storage.cache_capacity` | String | Unset | The local file cache capacity in bytes. If your disk space is sufficient, it is recommended to set it larger. | diff --git a/config/datanode.example.toml b/config/datanode.example.toml index aa1c5b7c54..cd795fb9d9 100644 --- a/config/datanode.example.toml +++ b/config/datanode.example.toml @@ -252,7 +252,7 @@ parallelism = 0 ## The data storage options. [storage] ## The working home directory. -data_home = "./greptimedb_data/" +data_home = "./greptimedb_data" ## The storage type used to store the data. ## - `File`: the data is stored in the local file system. diff --git a/config/metasrv.example.toml b/config/metasrv.example.toml index 748624b2e2..4befa171ed 100644 --- a/config/metasrv.example.toml +++ b/config/metasrv.example.toml @@ -1,5 +1,5 @@ ## The working home directory. -data_home = "./greptimedb_data/metasrv/" +data_home = "./greptimedb_data" ## The bind address of metasrv. bind_addr = "127.0.0.1:3002" diff --git a/config/standalone.example.toml b/config/standalone.example.toml index 2470ac4775..cf784d2aea 100644 --- a/config/standalone.example.toml +++ b/config/standalone.example.toml @@ -350,7 +350,7 @@ parallelism = 0 ## The data storage options. [storage] ## The working home directory. -data_home = "./greptimedb_data/" +data_home = "./greptimedb_data" ## The storage type used to store the data. ## - `File`: the data is stored in the local file system. diff --git a/src/cmd/src/datanode.rs b/src/cmd/src/datanode.rs index a5ccabe08d..4063ecf183 100644 --- a/src/cmd/src/datanode.rs +++ b/src/cmd/src/datanode.rs @@ -14,12 +14,13 @@ pub mod builder; +use std::path::Path; use std::time::Duration; use async_trait::async_trait; use clap::Parser; use common_config::Configurable; -use common_telemetry::logging::TracingOptions; +use common_telemetry::logging::{TracingOptions, DEFAULT_LOGGING_DIR}; use common_telemetry::{info, warn}; use common_wal::config::DatanodeWalConfig; use datanode::datanode::Datanode; @@ -248,6 +249,14 @@ impl StartCommand { raft_engine_config.dir.replace(wal_dir.clone()); } + // If the logging dir is not set, use the default logs dir in the data home. + if opts.logging.dir.is_empty() { + opts.logging.dir = Path::new(&opts.storage.data_home) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(); + } + if let Some(http_addr) = &self.http_addr { opts.http.addr.clone_from(http_addr); } diff --git a/src/cmd/src/flownode.rs b/src/cmd/src/flownode.rs index 2f235b858e..af695ab539 100644 --- a/src/cmd/src/flownode.rs +++ b/src/cmd/src/flownode.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::path::Path; use std::sync::Arc; use std::time::Duration; @@ -21,7 +22,7 @@ use catalog::kvbackend::{CachedKvBackendBuilder, KvBackendCatalogManager, MetaKv use clap::Parser; use client::client_manager::NodeClients; use common_base::Plugins; -use common_config::Configurable; +use common_config::{Configurable, DEFAULT_DATA_HOME}; use common_grpc::channel_manager::ChannelConfig; use common_meta::cache::{CacheRegistryBuilder, LayeredCacheRegistryBuilder}; use common_meta::heartbeat::handler::invalidate_table_cache::InvalidateCacheHandler; @@ -30,7 +31,7 @@ use common_meta::heartbeat::handler::HandlerGroupExecutor; use common_meta::key::flow::FlowMetadataManager; use common_meta::key::TableMetadataManager; use common_telemetry::info; -use common_telemetry::logging::TracingOptions; +use common_telemetry::logging::{TracingOptions, DEFAULT_LOGGING_DIR}; use common_version::{short_version, version}; use flow::{ get_flow_auth_options, FlownodeBuilder, FlownodeInstance, FlownodeServiceBuilder, @@ -186,6 +187,14 @@ impl StartCommand { opts.logging.dir.clone_from(dir); } + // If the logging dir is not set, use the default logs dir in the data home. + if opts.logging.dir.is_empty() { + opts.logging.dir = Path::new(DEFAULT_DATA_HOME) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(); + } + if global_options.log_level.is_some() { opts.logging.level.clone_from(&global_options.log_level); } diff --git a/src/cmd/src/frontend.rs b/src/cmd/src/frontend.rs index ba02335dff..40154d36a4 100644 --- a/src/cmd/src/frontend.rs +++ b/src/cmd/src/frontend.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::path::Path; use std::sync::Arc; use std::time::Duration; @@ -22,14 +23,14 @@ use catalog::kvbackend::{CachedKvBackendBuilder, KvBackendCatalogManager, MetaKv use clap::Parser; use client::client_manager::NodeClients; use common_base::Plugins; -use common_config::Configurable; +use common_config::{Configurable, DEFAULT_DATA_HOME}; use common_grpc::channel_manager::ChannelConfig; use common_meta::cache::{CacheRegistryBuilder, LayeredCacheRegistryBuilder}; use common_meta::heartbeat::handler::invalidate_table_cache::InvalidateCacheHandler; use common_meta::heartbeat::handler::parse_mailbox_message::ParseMailboxMessageHandler; use common_meta::heartbeat::handler::HandlerGroupExecutor; use common_telemetry::info; -use common_telemetry::logging::TracingOptions; +use common_telemetry::logging::{TracingOptions, DEFAULT_LOGGING_DIR}; use common_time::timezone::set_default_timezone; use common_version::{short_version, version}; use frontend::frontend::Frontend; @@ -194,6 +195,14 @@ impl StartCommand { opts.logging.dir.clone_from(dir); } + // If the logging dir is not set, use the default logs dir in the data home. + if opts.logging.dir.is_empty() { + opts.logging.dir = Path::new(DEFAULT_DATA_HOME) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(); + } + if global_options.log_level.is_some() { opts.logging.level.clone_from(&global_options.log_level); } diff --git a/src/cmd/src/metasrv.rs b/src/cmd/src/metasrv.rs index 8702f0c690..a5f48af523 100644 --- a/src/cmd/src/metasrv.rs +++ b/src/cmd/src/metasrv.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::fmt; +use std::path::Path; use std::time::Duration; use async_trait::async_trait; @@ -20,7 +21,7 @@ use clap::Parser; use common_base::Plugins; use common_config::Configurable; use common_telemetry::info; -use common_telemetry::logging::TracingOptions; +use common_telemetry::logging::{TracingOptions, DEFAULT_LOGGING_DIR}; use common_version::{short_version, version}; use meta_srv::bootstrap::MetasrvInstance; use meta_srv::metasrv::BackendImpl; @@ -274,6 +275,14 @@ impl StartCommand { opts.data_home.clone_from(data_home); } + // If the logging dir is not set, use the default logs dir in the data home. + if opts.logging.dir.is_empty() { + opts.logging.dir = Path::new(&opts.data_home) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(); + } + if !self.store_key_prefix.is_empty() { opts.store_key_prefix.clone_from(&self.store_key_prefix) } diff --git a/src/cmd/src/standalone.rs b/src/cmd/src/standalone.rs index f3bae90628..c5d2954a49 100644 --- a/src/cmd/src/standalone.rs +++ b/src/cmd/src/standalone.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::net::SocketAddr; +use std::path::Path; use std::sync::Arc; use std::{fs, path}; @@ -49,7 +50,9 @@ use common_meta::sequence::SequenceBuilder; use common_meta::wal_options_allocator::{build_wal_options_allocator, WalOptionsAllocatorRef}; use common_procedure::{ProcedureInfo, ProcedureManagerRef}; use common_telemetry::info; -use common_telemetry::logging::{LoggingOptions, SlowQueryOptions, TracingOptions}; +use common_telemetry::logging::{ + LoggingOptions, SlowQueryOptions, TracingOptions, DEFAULT_LOGGING_DIR, +}; use common_time::timezone::set_default_timezone; use common_version::{short_version, version}; use common_wal::config::DatanodeWalConfig; @@ -407,6 +410,14 @@ impl StartCommand { opts.storage.data_home.clone_from(data_home); } + // If the logging dir is not set, use the default logs dir in the data home. + if opts.logging.dir.is_empty() { + opts.logging.dir = Path::new(&opts.storage.data_home) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(); + } + if let Some(addr) = &self.rpc_bind_addr { // frontend grpc addr conflict with datanode default grpc addr let datanode_grpc_addr = DatanodeOptions::default().grpc.bind_addr; diff --git a/src/cmd/tests/load_config_test.rs b/src/cmd/tests/load_config_test.rs index c14417afba..9e495b4662 100644 --- a/src/cmd/tests/load_config_test.rs +++ b/src/cmd/tests/load_config_test.rs @@ -12,13 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::path::Path; use std::time::Duration; use cmd::options::GreptimeOptions; use cmd::standalone::StandaloneOptions; -use common_config::Configurable; +use common_config::{Configurable, DEFAULT_DATA_HOME}; use common_options::datanode::{ClientOptions, DatanodeClientOptions}; -use common_telemetry::logging::{LoggingOptions, DEFAULT_OTLP_ENDPOINT}; +use common_telemetry::logging::{LoggingOptions, DEFAULT_LOGGING_DIR, DEFAULT_OTLP_ENDPOINT}; use common_wal::config::raft_engine::RaftEngineConfig; use common_wal::config::DatanodeWalConfig; use datanode::config::{DatanodeOptions, RegionEngineConfig, StorageConfig}; @@ -32,6 +33,7 @@ use mito2::config::MitoConfig; use servers::export_metrics::ExportMetricsOption; use servers::grpc::GrpcOptions; use servers::http::HttpOptions; +use store_api::path_utils::WAL_DIR; #[allow(deprecated)] #[test] @@ -56,13 +58,18 @@ fn test_load_datanode_example_config() { metadata_cache_tti: Duration::from_secs(300), }), wal: DatanodeWalConfig::RaftEngine(RaftEngineConfig { - dir: Some("./greptimedb_data/wal".to_string()), + dir: Some( + Path::new(DEFAULT_DATA_HOME) + .join(WAL_DIR) + .to_string_lossy() + .to_string(), + ), sync_period: Some(Duration::from_secs(10)), recovery_parallelism: 2, ..Default::default() }), storage: StorageConfig { - data_home: "./greptimedb_data/".to_string(), + data_home: DEFAULT_DATA_HOME.to_string(), ..Default::default() }, region_engine: vec![ @@ -79,6 +86,10 @@ fn test_load_datanode_example_config() { ], logging: LoggingOptions { level: Some("info".to_string()), + dir: Path::new(DEFAULT_DATA_HOME) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(), otlp_endpoint: Some(DEFAULT_OTLP_ENDPOINT.to_string()), tracing_sample_ratio: Some(Default::default()), ..Default::default() @@ -121,6 +132,10 @@ fn test_load_frontend_example_config() { }), logging: LoggingOptions { level: Some("info".to_string()), + dir: Path::new(DEFAULT_DATA_HOME) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(), otlp_endpoint: Some(DEFAULT_OTLP_ENDPOINT.to_string()), tracing_sample_ratio: Some(Default::default()), ..Default::default() @@ -160,10 +175,13 @@ fn test_load_metasrv_example_config() { let expected = GreptimeOptions:: { component: MetasrvOptions { selector: SelectorType::default(), - data_home: "./greptimedb_data/metasrv/".to_string(), + data_home: DEFAULT_DATA_HOME.to_string(), server_addr: "127.0.0.1:3002".to_string(), logging: LoggingOptions { - dir: "./greptimedb_data/logs".to_string(), + dir: Path::new(DEFAULT_DATA_HOME) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(), level: Some("info".to_string()), otlp_endpoint: Some(DEFAULT_OTLP_ENDPOINT.to_string()), tracing_sample_ratio: Some(Default::default()), @@ -198,7 +216,12 @@ fn test_load_standalone_example_config() { component: StandaloneOptions { default_timezone: Some("UTC".to_string()), wal: DatanodeWalConfig::RaftEngine(RaftEngineConfig { - dir: Some("./greptimedb_data/wal".to_string()), + dir: Some( + Path::new(DEFAULT_DATA_HOME) + .join(WAL_DIR) + .to_string_lossy() + .to_string(), + ), sync_period: Some(Duration::from_secs(10)), recovery_parallelism: 2, ..Default::default() @@ -216,11 +239,15 @@ fn test_load_standalone_example_config() { }), ], storage: StorageConfig { - data_home: "./greptimedb_data/".to_string(), + data_home: DEFAULT_DATA_HOME.to_string(), ..Default::default() }, logging: LoggingOptions { level: Some("info".to_string()), + dir: Path::new(DEFAULT_DATA_HOME) + .join(DEFAULT_LOGGING_DIR) + .to_string_lossy() + .to_string(), otlp_endpoint: Some(DEFAULT_OTLP_ENDPOINT.to_string()), tracing_sample_ratio: Some(Default::default()), ..Default::default() diff --git a/src/common/config/src/lib.rs b/src/common/config/src/lib.rs index 899214088f..b806924217 100644 --- a/src/common/config/src/lib.rs +++ b/src/common/config/src/lib.rs @@ -26,6 +26,9 @@ pub fn metadata_store_dir(store_dir: &str) -> String { format!("{store_dir}/metadata") } +/// The default data home directory. +pub const DEFAULT_DATA_HOME: &str = "./greptimedb_data"; + #[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] #[serde(default)] pub struct KvBackendConfig { diff --git a/src/common/telemetry/src/logging.rs b/src/common/telemetry/src/logging.rs index 26239f44f4..0639b6786a 100644 --- a/src/common/telemetry/src/logging.rs +++ b/src/common/telemetry/src/logging.rs @@ -37,6 +37,9 @@ use crate::tracing_sampler::{create_sampler, TracingSampleOptions}; pub const DEFAULT_OTLP_ENDPOINT: &str = "http://localhost:4317"; +/// The default logs directory. +pub const DEFAULT_LOGGING_DIR: &str = "logs"; + // Handle for reloading log level pub static RELOAD_HANDLE: OnceCell> = OnceCell::new(); @@ -133,7 +136,8 @@ impl Eq for LoggingOptions {} impl Default for LoggingOptions { fn default() -> Self { Self { - dir: "./greptimedb_data/logs".to_string(), + // The directory path will be configured at application startup, typically using the data home directory as a base. + dir: "".to_string(), level: None, log_format: LogFormat::Text, enable_otlp_tracing: false, diff --git a/src/datanode/src/config.rs b/src/datanode/src/config.rs index 9c845c5553..d53a4d56f6 100644 --- a/src/datanode/src/config.rs +++ b/src/datanode/src/config.rs @@ -18,7 +18,7 @@ use core::time::Duration; use common_base::readable_size::ReadableSize; use common_base::secrets::{ExposeSecret, SecretString}; -use common_config::Configurable; +use common_config::{Configurable, DEFAULT_DATA_HOME}; pub use common_procedure::options::ProcedureConfig; use common_telemetry::logging::{LoggingOptions, TracingOptions}; use common_wal::config::DatanodeWalConfig; @@ -36,9 +36,6 @@ use servers::http::HttpOptions; pub const DEFAULT_OBJECT_STORE_CACHE_SIZE: ReadableSize = ReadableSize::gb(5); -/// Default data home in file storage -const DEFAULT_DATA_HOME: &str = "./greptimedb_data"; - /// Object storage config #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] #[serde(tag = "type")] diff --git a/src/meta-srv/src/metasrv.rs b/src/meta-srv/src/metasrv.rs index 04042c5c54..a26df4cc96 100644 --- a/src/meta-srv/src/metasrv.rs +++ b/src/meta-srv/src/metasrv.rs @@ -22,7 +22,7 @@ use std::time::Duration; use clap::ValueEnum; use common_base::readable_size::ReadableSize; use common_base::Plugins; -use common_config::Configurable; +use common_config::{Configurable, DEFAULT_DATA_HOME}; use common_greptimedb_telemetry::GreptimeDBTelemetryTask; use common_meta::cache_invalidator::CacheInvalidatorRef; use common_meta::ddl::ProcedureExecutorRef; @@ -73,7 +73,7 @@ use crate::state::{become_follower, become_leader, StateRef}; pub const TABLE_ID_SEQ: &str = "table_id"; pub const FLOW_ID_SEQ: &str = "flow_id"; -pub const METASRV_HOME: &str = "./greptimedb_data/metasrv"; +pub const METASRV_DATA_DIR: &str = "metasrv"; // The datastores that implements metadata kvbackend. #[derive(Clone, Debug, PartialEq, Serialize, Default, Deserialize, ValueEnum)] @@ -217,10 +217,7 @@ impl Default for MetasrvOptions { enable_region_failover: false, allow_region_failover_on_local_wal: false, http: HttpOptions::default(), - logging: LoggingOptions { - dir: format!("{METASRV_HOME}/logs"), - ..Default::default() - }, + logging: LoggingOptions::default(), procedure: ProcedureConfig { max_retry_times: 12, retry_delay: Duration::from_millis(500), @@ -232,7 +229,7 @@ impl Default for MetasrvOptions { failure_detector: PhiAccrualFailureDetectorOptions::default(), datanode: DatanodeClientOptions::default(), enable_telemetry: true, - data_home: METASRV_HOME.to_string(), + data_home: DEFAULT_DATA_HOME.to_string(), wal: MetasrvWalConfig::default(), export_metrics: ExportMetricsOption::default(), store_key_prefix: String::new(), diff --git a/src/meta-srv/src/metasrv/builder.rs b/src/meta-srv/src/metasrv/builder.rs index 902e23fc17..f2112b6c1a 100644 --- a/src/meta-srv/src/metasrv/builder.rs +++ b/src/meta-srv/src/metasrv/builder.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::path::Path; use std::sync::atomic::AtomicBool; use std::sync::{Arc, Mutex, RwLock}; @@ -55,7 +56,7 @@ use crate::handler::{HeartbeatHandlerGroupBuilder, HeartbeatMailbox, Pushers}; use crate::lease::MetaPeerLookupService; use crate::metasrv::{ ElectionRef, Metasrv, MetasrvInfo, MetasrvOptions, RegionStatAwareSelectorRef, SelectTarget, - SelectorContext, SelectorRef, FLOW_ID_SEQ, TABLE_ID_SEQ, + SelectorContext, SelectorRef, FLOW_ID_SEQ, METASRV_DATA_DIR, TABLE_ID_SEQ, }; use crate::procedure::region_migration::manager::RegionMigrationManager; use crate::procedure::region_migration::DefaultContextFactory; @@ -436,7 +437,10 @@ impl MetasrvBuilder { }; let enable_telemetry = options.enable_telemetry; - let metasrv_home = options.data_home.to_string(); + let metasrv_home = Path::new(&options.data_home) + .join(METASRV_DATA_DIR) + .to_string_lossy() + .to_string(); Ok(Metasrv { state, diff --git a/src/store-api/src/path_utils.rs b/src/store-api/src/path_utils.rs index 4585e4b505..241b4a6118 100644 --- a/src/store-api/src/path_utils.rs +++ b/src/store-api/src/path_utils.rs @@ -18,7 +18,7 @@ use crate::storage::{RegionId, RegionNumber, TableId}; /// WAL dir for local file storage -pub const WAL_DIR: &str = "wal/"; +pub const WAL_DIR: &str = "wal"; /// Data dir for table engines pub const DATA_DIR: &str = "data/";