Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add meta_type config #8571

Merged
merged 14 commits into from
Nov 3, 2022
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions src/query/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ hex = "0.4.3"
once_cell = "1.15.0"
semver = "1.0.14"
serde = { workspace = true }
serde_json = { workspace = true }
serfig = "0.0.3"

[build-dependencies]
Expand Down
9 changes: 2 additions & 7 deletions src/query/config/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,19 +291,14 @@ impl Default for MetaConfig {
auto_sync_interval: 10,
rpc_tls_meta_server_root_ca_cert: "".to_string(),
rpc_tls_meta_service_domain_name: "localhost".to_string(),
meta_type: MetaType::Remote.to_str().to_string(),
meta_type: serde_json::to_string(&MetaType::Embedded).unwrap(),
lichuang marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

impl MetaConfig {
pub fn is_embedded_meta(&self) -> Result<bool> {
lichuang marked this conversation as resolved.
Show resolved Hide resolved
let t = MetaType::from_str(&self.meta_type)?;
if t == MetaType::Embedded && self.embedded_dir.is_empty() {
return Err(ErrorCode::InvalidConfig(
"Embedded Meta but embedded_dir is empty",
));
}
let t: MetaType = serde_json::from_str(&self.meta_type)?;
Ok(t == MetaType::Embedded)
}

Expand Down
47 changes: 16 additions & 31 deletions src/query/config/src/outer_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1258,41 +1258,25 @@ impl From<InnerHiveCatalogConfig> for HiveCatalogConfig {
}
}

#[derive(Debug, PartialEq, Eq)]
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq)]
pub enum MetaType {
#[serde(rename = "remote")]
Remote,
Embedded,
}

impl MetaType {
pub fn to_str(&self) -> &str {
match self {
Self::Remote => "remote",
Self::Embedded => "embedded",
}
}
}

impl FromStr for MetaType {
type Err = ErrorCode;

fn from_str(s: &str) -> Result<Self> {
let s = s.to_lowercase();
match s.as_str() {
"remote" => Ok(Self::Remote),
"embedded" => Ok(Self::Embedded),
_ => Err(ErrorCode::InvalidConfig(String::from(
"invalid MetaType, MUST be 'remote' or 'embedded'",
))),
}
}
#[serde(rename = "embedded")]
Embedded,
}

/// Meta config group.
/// TODO(xuanwo): All meta_xxx should be rename to xxx.
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Args)]
#[serde(default)]
pub struct MetaConfig {
/// MetaStore type: remote or embedded
#[clap(long = "meta-type", default_value = "embedded")]
#[serde(alias = "meta_type")]
pub meta_type: String,
drmingdrmer marked this conversation as resolved.
Show resolved Hide resolved

/// The dir to store persisted meta state for a embedded meta store
#[clap(
long = "meta-embedded-dir",
Expand Down Expand Up @@ -1336,11 +1320,6 @@ pub struct MetaConfig {

#[clap(long = "meta-rpc-tls-meta-service-domain-name", default_value_t)]
pub rpc_tls_meta_service_domain_name: String,

/// MetaStore type: remote or embedded
#[clap(long = "meta-type", default_value = MetaType::Remote.to_str())]
#[serde(alias = "meta_type")]
pub meta_type: String,
}

impl Default for MetaConfig {
Expand All @@ -1353,6 +1332,12 @@ impl TryInto<InnerMetaConfig> for MetaConfig {
type Error = ErrorCode;

fn try_into(self) -> Result<InnerMetaConfig> {
let t: MetaType = serde_json::from_str(&self.meta_type)?;
if t == MetaType::Embedded && self.embedded_dir.is_empty() {
lichuang marked this conversation as resolved.
Show resolved Hide resolved
return Err(ErrorCode::InvalidConfig(
"Embedded Meta but embedded_dir is empty",
));
}
Ok(InnerMetaConfig {
embedded_dir: self.embedded_dir,
address: self.address,
Expand Down Expand Up @@ -1388,6 +1373,7 @@ impl From<InnerMetaConfig> for MetaConfig {
impl Debug for MetaConfig {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
f.debug_struct("MetaConfig")
.field("meta_type", &self.meta_type)
.field("address", &self.address)
.field("endpoints", &self.endpoints)
.field("username", &self.username)
Expand All @@ -1403,7 +1389,6 @@ impl Debug for MetaConfig {
"rpc_tls_meta_service_domain_name",
&self.rpc_tls_meta_service_domain_name,
)
.field("meta_type", &self.meta_type)
.finish()
}
}
Expand Down