Skip to content

Commit

Permalink
Merge pull request #5345 from TCeason/ISSUE-5303/save_one_rpc_to_metasrv
Browse files Browse the repository at this point in the history
save one rpc to metasrv
  • Loading branch information
BohuTANG authored May 13, 2022
2 parents 4aab38c + f08c6e8 commit 08b6be1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions common/ast/tests/it/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ fn test_statement_error() {
r#"truncate a"#,
r#"drop a"#,
r#"insert into t format"#,
r#"alter database system x rename to db"#,
];

for case in cases {
Expand Down
12 changes: 12 additions & 0 deletions common/ast/tests/it/testdata/statement-error.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,15 @@ error:
| while parsing `INSERT INTO [TABLE] <table> [(<column>, ...)] (FORMAT <format> | VALUES <values> | <query>)`


---------- Input ----------
alter database system x rename to db
---------- Output ---------
error:
--> SQL:1:23
|
1 | alter database system x rename to db
| ----- ^ expected `RENAME`
| |
| while parsing `ALTER DATABASE [IF EXISTS] <action>`


24 changes: 7 additions & 17 deletions common/meta/api/src/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,24 +206,14 @@ impl<KV: KVApi> SchemaApi for KV {

loop {
// get old db, not exists return err
let res = get_db_or_err(
self,
tenant_dbname,
format!("rename_database: {}", &tenant_dbname),
)
.await;

let (old_db_id_seq, old_db_id, _, _) = match res {
Ok(x) => x,
Err(e) => {
if let MetaError::AppError(AppError::UnknownDatabase(_)) = e {
if req.if_exists {
return Ok(RenameDatabaseReply {});
}
}
return Err(e);
let (old_db_id_seq, old_db_id) = get_id_value(self, tenant_dbname).await?;
if req.if_exists {
if old_db_id_seq == 0 {
return Ok(RenameDatabaseReply {});
}
};
} else {
db_has_to_exist(old_db_id_seq, tenant_dbname, "rename_database: src (db)")?;
}

tracing::debug!(
old_db_id,
Expand Down

0 comments on commit 08b6be1

Please sign in to comment.