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

impl alter database rename #4984

Closed

Conversation

TCeason
Copy link
Collaborator

@TCeason TCeason commented Apr 21, 2022

I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/

Summary

Support alter database .

Changelog

  • New Feature
  • Build/Testing/CI
  • Documentation

Related Issues

Fixes #4839

@vercel
Copy link

vercel bot commented Apr 21, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
databend ✅ Ready (Inspect) Visit Preview Apr 21, 2022 at 8:09AM (UTC)

@mergify
Copy link
Contributor

mergify bot commented Apr 21, 2022

Thanks for the contribution!
I have applied any labels matching special text in your PR Changelog.

Please review the labels and make any necessary changes.

@mergify mergify bot added pr-feature this PR introduces a new feature to the codebase pr-build this PR changes build/testing/ci steps pr-doc-fix labels Apr 21, 2022
@@ -451,6 +453,110 @@ impl StateMachine {
Ok(AppliedState::DatabaseMeta(Change::new(None, None)))
}

fn apply_rename_database_cmd(
Copy link
Contributor

@junnplus junnplus Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we reuse apply_drop_database_cmd and apply_create_database_cmd code? Like apply_rename_table_cmd.

Copy link
Collaborator Author

@TCeason TCeason Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we reuse apply_drop_database_cmd and apply_create_database_cmd code? Like apply_rename_table_cmd.

I think renamed database should use old database's db_id.

create database old;
alter database old rename to new 

not equal with:

create database old;
drop database old;
create database new;

But maybe we can try to extract the same part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think renamed database should use old database's db_id.

I'm not sure, it seems that the id and name are bound now.

cc @drmingdrmer @ariesdevil

Copy link
Collaborator Author

@TCeason TCeason Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, actually in apply_rename_database_cmd

https://github.com/datafuselabs/databend/blob/a21fb5bb7da6579c0a80a5d2ead3d8f073b33e77/common/meta/raft-store/src/state_machine/sm.rs#L622

table_id is table_name's id and table_meta also from old table( &prev.as_ref().unwrap().data).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think renamed database should use old database's db_id.

I'm not sure, it seems that the id and name are bound now.

cc @drmingdrmer @ariesdevil

The db_id and table_id need to remain the same when changing the db/table meta

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The db_id and table_id need to remain the same when changing the db/table meta

Thanks, I found it #4838

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TCeason It looks like there is no conflict between reusing the code and not changing the db_id, It can also be refactored in another PR.

Copy link
Collaborator Author

@TCeason TCeason Apr 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TCeason It looks like there is no conflict between reusing the code and not changing the db_id, It can also be refactored in another PR.

Agree with you.

@BohuTANG
Copy link
Member

BohuTANG commented Apr 21, 2022

@TCeason
Suggest to do the rename after our meta api refactor finished, it will easy to do that, then we will use KV api instead of the meta api, no need to change the metasrv code.

@BohuTANG
Copy link
Member

@TCeason
I will convert this PR to draft, you can restart this task when our new API is ready after a few days, will be very easy to do it.

@BohuTANG BohuTANG marked this pull request as draft April 21, 2022 09:31
@TCeason
Copy link
Collaborator Author

TCeason commented Apr 21, 2022

@TCeason I will convert this PR to draft, you can restart this task when our new API is ready after a few days, will be very easy to do it.

Got. By the way, does the refactor have PR or ISSUE? I want to link it here.

@BohuTANG BohuTANG mentioned this pull request Apr 24, 2022
@BohuTANG
Copy link
Member

BohuTANG commented May 8, 2022

@TCeason
The Databend meta API is deprecated with the new KVAPI, and I think we can close this PR and start a new one for it.

@TCeason
Copy link
Collaborator Author

TCeason commented May 8, 2022

@TCeason
The Databend meta API is deprecated with the new KVAPI, and I think we can close this PR and start a new one for it.

Okay, I got it

@TCeason TCeason closed this May 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need-review pr-build this PR changes build/testing/ci steps pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support: ALTER DATABASE [ IF EXISTS ] <name> RENAME TO <new_db_name>
5 participants