-
Notifications
You must be signed in to change notification settings - Fork 753
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: metasrv has to be compatible with 20220413-34e89c99e4e35632718e9227f6549b3090eb0fb9 #4901
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. |
223e6cf
to
78097ba
Compare
Is it possible set a version for the metadata, default is version_0, if the metadata changed upgrade it to version_1, and we handle the versions? |
i wonder if there is more elegant way to do compatible in Rust enum type, like protobuf In this PR's way, the next time Cmd upgrade, it will has a new cmd_xxxx type to compatible, it is boring.... |
or, IMHO, if the CMD type may be upgrade in the future and it is the key data of meta API, we can define it as a protobuf type, to make it compatible easily? |
how about reduce the business logics like CreateDatabase / CreateShare into the raft command, instead make them depends on some generic K/V operations like PutWriteBatch / CommitTx? this may reduce the possbility of changes about low level raft commands |
emm, good idea. |
Right. It is the second part of the plan.
|
The compatible intermediate struct Using
It does not have to be, if we can limit the oldest version that is backward compatible with, e.g.: the publish metasvr version could be:
And there probably is not another |
Compatibility is not an issue in such a case. Actually, rust serde provides more flexible ser/de ability. Such as Field attributes The dirty job is how to avoid using |
This solution is considered before but we were facing the fact that CreatDatabase and else are not pure batch write but conditional updates. fn create_table() {
let xx = dbs.get((args.db_name, args.table_name));
if xx.is_ok() {
return Ok();
} else {
let id = new_id();
dbs.insert((args.db_name, args.table_name), id);
tables.insert((args.db_name, id), args.table);
return Ok();
}
} pub enum Cmd {
/// Conditional evaluate:
/// - first evaluate `condition`, it has to be a bool value.
/// - then evaluate then_cmd or else_cmd
Cmd::IfThenElse {
condition: Cmd,
then_cmd: Cmd,
else_cmd: Cmd,
}
/// Assign a Cmd and save the output into a temporary variable with name `var`.
///
///
Cmd::Assign {
var: String,
cmd: Cmd
}
/// A series of Cmd that will be evaluated one by one.
Cmd::Statements(Vec<Cmd>),
/// Return true if a variable is `None`.
Cmd::IsNull(String),
/// Return the value of a variable, the value type is `AppliedState`.
Cmd::Var(String),
/// Generate a new unique id in a specified name space.
Cmd::NewId(String),
// Tree operations
/// alias of BTreeMap.get()
///
Cmd::GetKV{
/// The tree to acces.
/// Only predefined trees are provided, such as:
/// table, db,
tree: String,
key: impl IntoTreeKey,
}
}
///
Statements(vec![
Assign {
var: "curr",
cmd: GetKV{
tree: "db_tbl_id",
key: (args.db_name, args.table_name)
}
},
IfThenElse {
condition: IsNull("curr"),
then_cmd: Var("curr"),
else_cmd: Statements(vec![
Assign {
var: "id",
cmd: NewId("table"),
},
Upsert {
tree: "db_tbl_id",
key: (args.db_name, args.table_name),
value: Var("id"),
},
Upsert {
tree: "db_tbl_t",
key: (args.db_name, Var("id")),
value: args.table,
},
Var(id)
])
}
]) |
Converted to draft because several test should be added before merge.:( |
Let metasvr be able to load the log-entry format before commit 34e89c9, in which the `Cmd` format changed. To solve th compatible issue, an intermedia type is introduced, which is a super set of the old and new type. When loading a record, first load it into the superset type, then reduce to the latest type. - fix: databendlabs#4890
78097ba
to
62b501a
Compare
@lichuang @ariesdevil anything need to improve? |
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.
lgtm
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
feature: metasrv has to be compatible with 20220413-34e89c99e4e35632718e9227f6549b3090eb0fb9
Let metasvr be able to load the log-entry format before commit
34e89c9,
in which the
Cmd
format changed.To solve th compatible issue, an intermedia type is introduced, which is
a super set of the old and new type.
When loading a record, first load it into the superset type, then reduce
to the latest type.
Changelog
Related Issues