-
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
Feature: add metasrv time travel functions #5468
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Thanks for the contribution! Please review the labels and make any necessary changes. |
common/meta/api/src/schema_api.rs
Outdated
use common_meta_types::UpdateTableMetaReply; | ||
use common_meta_types::UpdateTableMetaReq; |
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.
Is this gonna replace the UpsertTableOption RPC?
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.
Is this gonna replace the UpsertTableOption RPC?
I have no idea, this type is not from this PR, may be ask @dantengsky
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.
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![], |
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.
shall we check the status of name_key
in the else
branch? so that if name conflict detected, just break out the loop?
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.
Oh, pls ignore it, I miss-interpreted the code
/LGTM |
#[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 | ||
} | ||
|
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.
Need test of database_dorp_undrop_list_history
?
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.
fixed in #5566
#[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 | ||
} | ||
|
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.
Need test of database_dorp_undrop_list_history
?
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.
fixed in #5566
return Err(MetaError::AppError(AppError::UndropDbAlreadyExists( | ||
UndropDbAlreadyExists::new(&name_key.db_name), | ||
))); |
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.
Would it be simpler if just using DatabaseAlreadyExists
instead of UndropDbAlreadyExists
?
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.
fixed in #5566
} | ||
}; | ||
|
||
// get tb_meta of the last db 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.
// get tb_meta of the last db id | |
// get db_meta of the last db 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.
fixed in #5566
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); |
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.
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.
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.
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.
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(); |
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.
The same as the previous comment.
db_id_list.pop(); | ||
new_db_id_list.append(old_db_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.
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
.
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.
currently, undrop only the top in db_id_list
.
match db_id_list_opt { | ||
Some(list) => list, | ||
None => { | ||
return Err(MetaError::AppError(AppError::UndropDbHasNoHistory( | ||
UndropDbHasNoHistory::new(&name_key.db_name), | ||
))) | ||
} | ||
} |
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.
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.
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
get_{db|table}_history
in schema API.Changelog
Related Issues
Part of #5572