-
Notifications
You must be signed in to change notification settings - Fork 752
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
impl alter database rename #5286
impl alter database rename #5286
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Thanks for the contribution! Please review the labels and make any necessary changes. |
fe3d6bd
to
20f2e73
Compare
20f2e73
to
383f32c
Compare
383f32c
to
b83df89
Compare
b83df89
to
7edcaef
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A great PR!
// TODO(like rename table): if database not exists but sql hint if_exists is true | ||
// the sql must be Ok but should not return database_id | ||
return Ok(RenameDatabaseReply { db_id: 0 }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest removing db_id
in the RenameDatabaseReply
because renaming a db does not change its id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I will have a look.
let (db_id_seq, _db_id) = get_id_value(self, &tenant_newdbname).await?; | ||
db_has_to_not_exist(db_id_seq, &tenant_newdbname, "rename_database")?; | ||
|
||
let new_db_id = fetch_id(self, DatabaseIdGen {}).await?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just use the old_db_id
. We do not need to create a new id. So that the application(databend-query) will always be able to access this db with the same id
.
// rename database | ||
{ | ||
let txn_req = TxnRequest { | ||
condition: vec![txn_cond_seq(&tenant_newdbname, Eq, 0)?], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It requires another txn_cond_seq
to ensure the (tenant, old_db_name) -> (old_db_id_seq, old_db_id)
is not removed before this transaction completes.
7edcaef
to
142de4f
Compare
142de4f
to
f740c94
Compare
@mergify update |
✅ Branch has been successfully updated |
9ff69b9
to
9e33858
Compare
9e33858
to
1cdccac
Compare
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); | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since db_meta
is never used, this part can be simplified to let res = get_id_value(self, tenant_db_name...) ...
, which will save one RPC to metasrv.
But it's not a big deal and can be done in next PR.
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
Support
alter database
.Changelog
Related Issues
Fixes #4839