Skip to content

Commit

Permalink
fix: missing file engine with default options (#2519)
Browse files Browse the repository at this point in the history
Signed-off-by: Zhenchi <[email protected]>
  • Loading branch information
zhongzc authored Sep 28, 2023
1 parent 04dbd83 commit 201acd1
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 18 deletions.
9 changes: 9 additions & 0 deletions src/cmd/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ pub enum Error {
error: etcd_client::Error,
location: Location,
},

#[snafu(display("Failed to serde json"))]
SerdeJson {
#[snafu(source)]
error: serde_json::error::Error,
location: Location,
},
}

pub type Result<T> = std::result::Result<T, Error>;
Expand Down Expand Up @@ -214,6 +221,8 @@ impl ErrorExt for Error {
}
Error::SubstraitEncodeLogicalPlan { source, .. } => source.status_code(),
Error::StartCatalogManager { source, .. } => source.status_code(),

Error::SerdeJson { .. } => StatusCode::Unexpected,
}
}

Expand Down
11 changes: 9 additions & 2 deletions src/cmd/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use meta_srv::metasrv::MetaSrvOptions;
use serde::{Deserialize, Serialize};
use snafu::ResultExt;

use crate::error::{LoadLayeredConfigSnafu, Result};
use crate::error::{LoadLayeredConfigSnafu, Result, SerdeJsonSnafu};

pub const ENV_VAR_SEP: &str = "__";
pub const ENV_LIST_SEP: &str = ",";
Expand Down Expand Up @@ -94,9 +94,16 @@ impl Options {
.ignore_empty(true)
};

// Workaround: Replacement for `Config::try_from(&default_opts)` due to
// `ConfigSerializer` cannot handle the case of an empty struct contained
// within an iterative structure.
// See: https://github.com/mehcode/config-rs/issues/461
let json_str = serde_json::to_string(&default_opts).context(SerdeJsonSnafu)?;
let default_config = File::from_str(&json_str, FileFormat::Json);

// Add default values and environment variables as the sources of the configuration.
let mut layered_config = Config::builder()
.add_source(Config::try_from(&default_opts).context(LoadLayeredConfigSnafu)?)
.add_source(default_config)
.add_source(env_source);

// Add config file as the source of the configuration if it is specified.
Expand Down
21 changes: 21 additions & 0 deletions src/cmd/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,25 @@ mod tests {
},
);
}

#[test]
fn test_load_default_standalone_options() {
let options: StandaloneOptions =
Options::load_layered_options(None, "GREPTIMEDB_FRONTEND", None).unwrap();
let default_options = StandaloneOptions::default();
assert_eq!(options.mode, default_options.mode);
assert_eq!(options.enable_telemetry, default_options.enable_telemetry);
assert_eq!(options.http, default_options.http);
assert_eq!(options.grpc, default_options.grpc);
assert_eq!(options.mysql, default_options.mysql);
assert_eq!(options.postgres, default_options.postgres);
assert_eq!(options.opentsdb, default_options.opentsdb);
assert_eq!(options.influxdb, default_options.influxdb);
assert_eq!(options.prom_store, default_options.prom_store);
assert_eq!(options.wal, default_options.wal);
assert_eq!(options.kv_store, default_options.kv_store);
assert_eq!(options.procedure, default_options.procedure);
assert_eq!(options.logging, default_options.logging);
assert_eq!(options.region_engine, default_options.region_engine);
}
}
4 changes: 2 additions & 2 deletions src/common/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::time::Duration;
use common_base::readable_size::ReadableSize;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct WalConfig {
// wal file size in bytes
Expand Down Expand Up @@ -49,7 +49,7 @@ pub fn kv_store_dir(store_dir: &str) -> String {
format!("{store_dir}/kv")
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct KvStoreConfig {
// Kv file size in bytes
Expand Down
4 changes: 2 additions & 2 deletions src/datanode/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl Default for StorageConfig {
}
}

#[derive(Debug, Clone, Serialize, Default, Deserialize)]
#[derive(Debug, Clone, Serialize, Default, Deserialize, Eq, PartialEq)]
#[serde(default)]
pub struct FileConfig {}

Expand Down Expand Up @@ -378,7 +378,7 @@ impl DatanodeOptions {
}
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub enum RegionEngineConfig {
#[serde(rename = "mito")]
Mito(MitoConfig),
Expand Down
2 changes: 1 addition & 1 deletion src/file-engine/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq, Eq)]
pub struct EngineConfig {}
2 changes: 1 addition & 1 deletion src/frontend/src/frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::service_config::{
PostgresOptions, PromStoreOptions,
};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct FrontendOptions {
pub mode: Mode,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/service_config/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use common_grpc::channel_manager::{
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct GrpcOptions {
pub addr: String,
pub runtime_size: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/service_config/influxdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct InfluxdbOptions {
pub enable: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/service_config/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use serde::{Deserialize, Serialize};
use servers::tls::TlsOption;

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct MysqlOptions {
pub enable: bool,
pub addr: String,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/service_config/opentsdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct OpentsdbOptions {
pub enable: bool,
pub addr: String,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/service_config/otlp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct OtlpOptions {
pub enable: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/service_config/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use serde::{Deserialize, Serialize};
use servers::tls::TlsOption;

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct PostgresOptions {
pub enable: bool,
pub addr: String,
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/service_config/prom_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct PromStoreOptions {
pub enable: bool,
}
Expand Down
2 changes: 1 addition & 1 deletion src/meta-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub mod client;
pub mod error;

// Options for meta client in datanode instance.
#[derive(Clone, Debug, Serialize, Deserialize)]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct MetaClientOptions {
pub metasrv_addrs: Vec<String>,
pub timeout_millis: u64,
Expand Down
2 changes: 1 addition & 1 deletion src/mito2/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const DEFAULT_NUM_WORKERS: usize = 1;
const DEFAULT_MAX_BG_JOB: usize = 4;

/// Configuration for [MitoEngine](crate::engine::MitoEngine).
#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct MitoConfig {
// Worker configs:
/// Number of region workers (default 1).
Expand Down
2 changes: 1 addition & 1 deletion src/servers/src/heartbeat_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use common_meta::distributed_time_constants;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct HeartbeatOptions {
pub interval_millis: u64,
Expand Down

0 comments on commit 201acd1

Please sign in to comment.