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

Feature: add metasrv time travel functions #5468

Merged
merged 6 commits into from
May 24, 2022
Merged

Feature: add metasrv time travel functions #5468

merged 6 commits into from
May 24, 2022

Conversation

lichuang
Copy link
Contributor

@lichuang lichuang commented May 19, 2022

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

Summary

  1. add metasrv time travel functions
  2. add get_{db|table}_history in schema API.

Changelog

  • New Feature

Related Issues

Part of #5572

@vercel
Copy link

vercel bot commented May 19, 2022

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

1 Ignored Deployment
Name Status Preview Updated
databend ⬜️ Ignored (Inspect) May 24, 2022 at 8:31AM (UTC)

@mergify
Copy link
Contributor

mergify bot commented May 19, 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 the pr-feature this PR introduces a new feature to the codebase label May 19, 2022
@lichuang lichuang requested a review from drmingdrmer May 19, 2022 09:58
@lichuang lichuang added the A-meta Area: databend meta serive label May 19, 2022
@lichuang lichuang requested a review from dantengsky May 19, 2022 10:07
Comment on lines 44 to 45
use common_meta_types::UpdateTableMetaReply;
use common_meta_types::UpdateTableMetaReq;
Copy link
Member

Choose a reason for hiding this comment

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

Is this gonna replace the UpsertTableOption RPC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this gonna replace the UpsertTableOption RPC?

I have no idea, this type is not from this PR, may be ask @dantengsky

Copy link
Member

Choose a reason for hiding this comment

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

Yes, update_table_meta is added in #5476.

txn_op_put(name_key, serialize_id(db_id)?)?, // (tenant, db_name) -> db_id
txn_op_put(&dbid, serialize_struct(&db_meta)?)?, // (db_id) -> db_meta
],
else_then: vec![],
Copy link
Member

Choose a reason for hiding this comment

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

shall we check the status of name_key in the else branch? so that if name conflict detected, just break out the loop?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, pls ignore it, I miss-interpreted the code

@dantengsky
Copy link
Member

/LGTM

@BohuTANG BohuTANG merged commit b80625e into databendlabs:main May 24, 2022
Comment on lines +105 to +116
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_meta_embedded_table_drop_undrop_list_history() -> anyhow::Result<()> {
let (_log_guards, ut_span) = init_raft_store_ut!();
let _ent = ut_span.enter();
let tc = new_raft_test_context();
let sm = StateMachine::open(&tc.raft_config, 1).await?;

SchemaApiTestSuite {}
.table_drop_undrop_list_history(&sm)
.await
}

Copy link
Member

Choose a reason for hiding this comment

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

Need test of database_dorp_undrop_list_history?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in #5566

Comment on lines +71 to +78
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
async fn test_meta_embedded_table_drop_undrop_list_history() -> anyhow::Result<()> {
let mt = MetaEmbedded::new_temp().await?;
SchemaApiTestSuite {}
.table_drop_undrop_list_history(&mt)
.await
}

Copy link
Member

Choose a reason for hiding this comment

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

Need test of database_dorp_undrop_list_history?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in #5566

Comment on lines +277 to +279
return Err(MetaError::AppError(AppError::UndropDbAlreadyExists(
UndropDbAlreadyExists::new(&name_key.db_name),
)));
Copy link
Member

Choose a reason for hiding this comment

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

Would it be simpler if just using DatabaseAlreadyExists instead of UndropDbAlreadyExists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in #5566

}
};

// get tb_meta of the last db id
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// get tb_meta of the last db id
// get db_meta of the last db id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in #5566

Comment on lines +397 to +402
let (db_id_list_seq, db_id_list_opt): (_, Option<DbIdList>) =
get_struct_value(self, &dbid_idlist).await?;
let mut db_id_list: DbIdList;
if db_id_list_seq == 0 {
db_id_list = DbIdList::new();
db_id_list.append(old_db_id);
Copy link
Member

Choose a reason for hiding this comment

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

If the db exists but the db_id_list does not, it must be a bug and an error should be returned. Unless metasrv allows removing a db_id_list record while the db it belongs to still exists.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is a case that: already create a {db|table} before we add time travel related function, thus these {db|table} is not in id list, so we must handle this case.

Comment on lines +435 to +439
let (new_db_id_list_seq, new_db_id_list_opt): (_, Option<DbIdList>) =
get_struct_value(self, &new_dbid_idlist).await?;
let mut new_db_id_list: DbIdList;
if new_db_id_list_seq == 0 {
new_db_id_list = DbIdList::new();
Copy link
Member

Choose a reason for hiding this comment

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

The same as the previous comment.

Comment on lines +452 to +453
db_id_list.pop();
new_db_id_list.append(old_db_id);
Copy link
Member

Choose a reason for hiding this comment

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

db_id_list feels like a hash-map, but not a list, if it is allowed to undrop a db whose id is not at the top in db_id_list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently, undrop only the top in db_id_list.

Comment on lines +295 to +302
match db_id_list_opt {
Some(list) => list,
None => {
return Err(MetaError::AppError(AppError::UndropDbHasNoHistory(
UndropDbHasNoHistory::new(&name_key.db_name),
)))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Reading the db_id and reading the db_id_list is not guaranteed to happen in a snapshot.
Thus there is a chance db_id_list is inconsistent and in such a case it should retry in next loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-meta Area: databend meta serive need-review pr-feature this PR introduces a new feature to the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants