Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions common/meta/api/src/meta_api_test_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use common_exception::ErrorCode;
use common_meta_types::CreateDatabaseReply;
use common_meta_types::CreateDatabaseReq;
use common_meta_types::CreateTableReq;
use common_meta_types::DatabaseMeta;
use common_meta_types::DropDatabaseReq;
use common_meta_types::DropTableReq;
use common_meta_types::GetDatabaseReq;
Expand Down Expand Up @@ -50,8 +51,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: "db1".to_string(),
engine: "github".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "github".to_string(),
..Default::default()
},
};

let res = mt.create_database(req).await;
Expand All @@ -65,8 +68,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: "db1".to_string(),
engine: "".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "".to_string(),
..Default::default()
},
};

let res = mt.create_database(req).await;
Expand All @@ -80,8 +85,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: "db1".to_string(),
engine: "".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "".to_string(),
..DatabaseMeta::default()
},
};

let res = mt.create_database(req).await;
Expand All @@ -104,8 +111,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: "db2".to_string(),
engine: "".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "".to_string(),
..DatabaseMeta::default()
},
};

let res = mt.create_database(req).await;
Expand Down Expand Up @@ -191,8 +200,10 @@ impl MetaApiTestSuite {
let plan = CreateDatabaseReq {
if_not_exists: false,
db: db_name.to_string(),
engine: "".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "".to_string(),
..DatabaseMeta::default()
},
};

let res = mt.create_database(plan).await?;
Expand Down Expand Up @@ -223,6 +234,7 @@ impl MetaApiTestSuite {
engine: "JSON".to_string(),
options: options.clone(),
created_on,
..TableMeta::default()
},
};

Expand All @@ -241,6 +253,7 @@ impl MetaApiTestSuite {
engine: "JSON".to_owned(),
options: options.clone(),
created_on,
..Default::default()
},
};
assert_eq!(want, got.as_ref().clone(), "get created table");
Expand All @@ -262,6 +275,7 @@ impl MetaApiTestSuite {
engine: "JSON".to_owned(),
options: options.clone(),
created_on,
..Default::default()
},
};
assert_eq!(want, got.as_ref().clone(), "get created table");
Expand Down Expand Up @@ -292,6 +306,7 @@ impl MetaApiTestSuite {
engine: "JSON".to_owned(),
options: options.clone(),
created_on,
..Default::default()
},
};
assert_eq!(want, got.as_ref().clone(), "get old table");
Expand Down Expand Up @@ -451,8 +466,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: db_name.to_string(),
engine: "".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "".to_string(),
..Default::default()
},
};

let res = mt.create_database(req).await?;
Expand All @@ -475,8 +492,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: "db1".to_string(),
engine: "github".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "github".to_string(),
..Default::default()
},
};

let res = node_a.create_database(req).await;
Expand Down Expand Up @@ -522,8 +541,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: db_name.to_string(),
engine: "github".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "github".to_string(),
..Default::default()
},
};
let res = node_a.create_database(req).await;
tracing::info!("create database res: {:?}", res);
Expand Down Expand Up @@ -558,8 +579,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: db_name.to_string(),
engine: "github".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "github".to_string(),
..Default::default()
},
};
let res = node_a.create_database(req).await;
tracing::info!("create database res: {:?}", res);
Expand Down Expand Up @@ -618,8 +641,10 @@ impl MetaApiTestSuite {
let req = CreateDatabaseReq {
if_not_exists: false,
db: db_name.to_string(),
engine: "github".to_string(),
options: Default::default(),
meta: DatabaseMeta {
engine: "github".to_string(),
..Default::default()
},
};
let res = node_a.create_database(req).await;
tracing::info!("create database res: {:?}", res);
Expand Down
9 changes: 2 additions & 7 deletions common/meta/raft-store/src/state_machine/sm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,10 +348,7 @@ impl StateMachine {
}
}

Cmd::CreateDatabase {
ref name,
ref engine,
} => {
Cmd::CreateDatabase { ref name, ref meta } => {
let db_id = self.txn_incr_seq(SEQ_DATABASE_ID, txn_tree).map_err(|e| {
let e: ConflictableTransactionError<Infallible> = e.into();
ErrorCode::from(e)
Expand Down Expand Up @@ -403,9 +400,7 @@ impl StateMachine {
&dbs,
&db_id,
&MatchSeq::Exact(0),
Operation::Update(DatabaseMeta {
engine: engine.clone(),
}),
Operation::Update(meta.clone()),
None,
)
.map_err(|e| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl MetaApi for StateMachine {
) -> Result<CreateDatabaseReply, ErrorCode> {
let cmd = Cmd::CreateDatabase {
name: req.db.clone(),
engine: req.engine.clone(),
meta: req.meta.clone(),
};

let res = self.sm_tree.txn(true, |t| {
Expand Down
10 changes: 8 additions & 2 deletions common/meta/raft-store/tests/it/state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ async fn test_state_machine_apply_add_database() -> anyhow::Result<()> {
Ok(m.apply_cmd(
&Cmd::CreateDatabase {
name: c.name.to_string(),
engine: c.engine.to_string(),
meta: DatabaseMeta {
engine: c.engine.to_string(),
..Default::default()
},
},
&t,
)
Expand Down Expand Up @@ -200,7 +203,10 @@ async fn test_state_machine_apply_upsert_table_option() -> anyhow::Result<()> {
Ok(m.apply_cmd(
&Cmd::CreateDatabase {
name: "db1".to_string(),
engine: "default".to_string(),
meta: DatabaseMeta {
engine: "defeault".to_string(),
..Default::default()
},
},
&t,
)
Expand Down
7 changes: 4 additions & 3 deletions common/meta/types/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use async_raft::NodeId;
use serde::Deserialize;
use serde::Serialize;

use crate::DatabaseMeta;
use crate::KVMeta;
use crate::MatchSeq;
use crate::Node;
Expand All @@ -37,7 +38,7 @@ pub enum Cmd {
AddNode { node_id: NodeId, node: Node },

/// Add a database if absent
CreateDatabase { name: String, engine: String },
CreateDatabase { name: String, meta: DatabaseMeta },

/// Drop a database if absent
DropDatabase { name: String },
Expand Down Expand Up @@ -88,8 +89,8 @@ impl fmt::Display for Cmd {
Cmd::AddNode { node_id, node } => {
write!(f, "add_node:{}={}", node_id, node)
}
Cmd::CreateDatabase { name, engine } => {
write!(f, "create_db:{} engine: {}", name, engine)
Cmd::CreateDatabase { name, meta } => {
write!(f, "create_db:{}={}", name, meta)
}
Cmd::DropDatabase { name } => {
write!(f, "drop_db:{}", name)
Expand Down
17 changes: 15 additions & 2 deletions common/meta/types/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
//

use std::collections::HashMap;
use std::fmt::Display;
use std::fmt::Formatter;
use std::ops::Deref;

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default, Eq, PartialEq)]
Expand All @@ -32,6 +34,18 @@ pub struct DatabaseInfo {
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default, Eq, PartialEq)]
pub struct DatabaseMeta {
pub engine: String,
pub engine_options: HashMap<String, String>,
pub options: HashMap<String, String>,
}

impl Display for DatabaseMeta {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Engine: {}={:?}, Options: {:?}",
self.engine, self.engine_options, self.options
)
}
}

impl DatabaseInfo {
Expand All @@ -44,8 +58,7 @@ impl DatabaseInfo {
pub struct CreateDatabaseReq {
pub if_not_exists: bool,
pub db: String,
pub engine: String,
pub options: HashMap<String, String>,
pub meta: DatabaseMeta,
}

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq)]
Expand Down
10 changes: 8 additions & 2 deletions common/meta/types/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub struct TableInfo {
pub struct TableMeta {
pub schema: Arc<DataSchema>,
pub engine: String,
pub engine_options: HashMap<String, String>,
pub options: HashMap<String, String>,
pub created_on: DateTime<Utc>,
}
Expand Down Expand Up @@ -138,6 +139,10 @@ impl TableInfo {
&self.meta.engine
}

pub fn engine_options(&self) -> &HashMap<String, String> {
&self.meta.engine_options
}

pub fn set_schema(mut self, schema: Arc<DataSchema>) -> TableInfo {
self.meta.schema = schema;
self
Expand All @@ -149,6 +154,7 @@ impl Default for TableMeta {
TableMeta {
schema: Arc::new(DataSchema::empty()),
engine: "".to_string(),
engine_options: HashMap::new(),
options: HashMap::new(),
created_on: Utc::now(),
}
Expand All @@ -159,8 +165,8 @@ impl Display for TableMeta {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(
f,
"Engine: {}, Schema: {}, Options: {:?} CreatedOn: {:?}",
self.engine, self.schema, self.options, self.created_on
"Engine: {}={:?}, Schema: {}, Options: {:?} CreatedOn: {:?}",
self.engine, self.engine_options, self.schema, self.options, self.created_on
)
}
}
Expand Down
10 changes: 4 additions & 6 deletions common/planners/src/plan_database_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,23 @@ use std::sync::Arc;
use common_datavalues::DataSchema;
use common_datavalues::DataSchemaRef;
use common_meta_types::CreateDatabaseReq;
use common_meta_types::DatabaseMeta;

pub type DatabaseOptions = HashMap<String, String>;

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq)]
pub struct CreateDatabasePlan {
pub if_not_exists: bool,
pub db: String,
pub engine: String,
pub options: DatabaseOptions,
pub meta: DatabaseMeta,
}

impl From<CreateDatabasePlan> for CreateDatabaseReq {
fn from(p: CreateDatabasePlan) -> Self {
CreateDatabaseReq {
if_not_exists: p.if_not_exists,
db: p.db.clone(),
engine: p.engine.to_string(),
options: p.options,
meta: p.meta,
}
}
}
Expand All @@ -45,8 +44,7 @@ impl From<&CreateDatabasePlan> for CreateDatabaseReq {
CreateDatabaseReq {
if_not_exists: p.if_not_exists,
db: p.db.clone(),
engine: p.engine.clone(),
options: p.options.clone(),
meta: p.meta.clone(),
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion common/planners/src/plan_display_indent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,14 @@ impl<'a> PlanNodeIndentFormatDisplay<'a> {
fn format_create_database(f: &mut Formatter, plan: &CreateDatabasePlan) -> fmt::Result {
write!(f, "Create database {:},", plan.db)?;
write!(f, " if_not_exists:{:},", plan.if_not_exists)?;
write!(f, " option: {:?}", plan.options)
if !plan.meta.engine.is_empty() {
write!(
f,
" engine: {}={:?},",
plan.meta.engine, plan.meta.engine_options
)?;
}
write!(f, " option: {:?}", plan.meta.options)
}

fn format_drop_database(f: &mut Formatter, plan: &DropDatabasePlan) -> fmt::Result {
Expand Down
Loading