-
Notifications
You must be signed in to change notification settings - Fork 399
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
quorum: port single group joint commit #394
Conversation
Signed-off-by: accelsao <bebe8277@gmail.com>
src/quorum/testdata/joint_commit.txt
Outdated
committed cfg=(1,2,3) cfgj=zero idx=(100,101,99) | ||
---- | ||
idx | ||
x> [0]100 (id=1) |
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 it group id? How about hiding 0 by default? So that the file is the same as etcd.
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 set the width larger for the space of group 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.
Can they be removed?
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.
Can they be removed?
Which one? space, group id or this describe?
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.
Space. Better make the file identical with etcd's.
src/quorum/majority.rs
Outdated
/// Describe returns a (multi-line) representation of the commit indexes for the | ||
/// given lookuper. | ||
pub fn describe(&self, l: &impl AckedIndexer) -> String { |
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.
Prefer to add a sample output
src/quorum/datadriven_test.rs
Outdated
use datadriven::{run_test, TestData}; | ||
|
||
#[test] | ||
fn test_data_driven_quorum() -> anyhow::Result<()> { |
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 the returning value necessary?
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, we return lots of Result
in run_test
, such as read_to_string
, OpenOptions::new()
Signed-off-by: accelsao <bebe8277@gmail.com>
src/quorum/majority.rs
Outdated
/// > 99 (id=3) | ||
/// 100 | ||
/// ``` | ||
pub fn describe(&self, l: &impl AckedIndexer) -> String { |
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.
Could you add an unit test for it?
Signed-off-by: accelsao <bebe8277@gmail.com>
Signed-off-by: accelsao <bebe8277@gmail.com>
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, thanks!
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
@BusyJay PTAL, thanks |
Signed-off-by: accelsao <bebe8277@gmail.com>
Signed-off-by: accelsao <bebe8277@gmail.com>
src/quorum/majority.rs
Outdated
r#" idx | ||
? 0 (id=1) | ||
x> 120 (id=2) | ||
> [1]120 (id=3) |
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.
Because the width in etcd
is 5, so this cant be aligned if the width of id is over 5 (including group id information)
@BusyJay PTAL, thanks |
src/quorum/joint.rs
Outdated
@@ -23,6 +23,11 @@ impl Configuration { | |||
} | |||
} | |||
|
|||
/// Creates a new configuration using the given MajorityConfigs. | |||
pub fn new_joint_from_majorities(incoming: MajorityConfig, outgoing: MajorityConfig) -> Self { |
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.
Should be pub(crate)
.
src/quorum/majority.rs
Outdated
/// > 99 (id=3) | ||
/// 100 | ||
/// ``` | ||
pub fn describe(&self, l: &impl AckedIndexer) -> String { |
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.
Should be pub(crate)
.
src/quorum/majority.rs
Outdated
// plot this as sort of a progress bar). The actual code is a bit more | ||
// complicated and also makes sure that equal index => equal bar. | ||
|
||
let mut info = 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.
You can use Vec::with_capacity(n)
.
src/quorum/majority.rs
Outdated
|
||
let mut info = vec![]; | ||
|
||
for id in self.raw_slice() { |
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.
Why not for id in &self.voters
?
src/quorum/majority.rs
Outdated
info.push(Tup { id, idx, bar: 0 }) | ||
} | ||
|
||
info.sort_by(|a, b| match a.idx.cmp(&b.idx) { |
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.
You mean (a.idx, a.id).cmp(&(b.idx, b.id))
?
src/quorum/majority.rs
Outdated
for tup in info { | ||
let string; | ||
if let Some(idx) = tup.idx { | ||
string = "x".repeat(tup.bar) |
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.
How about using buf
directly instead of creating a temporary string?
src/quorum/majority.rs
Outdated
string = "x".repeat(tup.bar) | ||
+ ">" | ||
+ " ".repeat(n - tup.bar).as_str() | ||
+ format!(" {:>5} (id={})\n", format!("{}", idx), tup.id).as_str(); |
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.
Redundant code, can be extracted as write!(buf, " {:>5} (id={})\n", tup.idx.unwrap_or_default(), tup.id).unwrap()
.
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 still use branch to determine the prefix of the string
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 fail to get width with
writeln!(buf, " {:>5} (id={})", idx, tup.id) .expect("Error occurred while trying to write in String");
and
writeln!(buf, " {:>5} (id={})", Index::default(), tup.id) .expect("Error occurred while trying to write in String");
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.
Can you talk more about the error you meet? Or you can show me a picture in slack.
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 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.
with this code writeln!(buf, " {:>5} (id={})", format!("{}", idx), tup.id)
, I can get the green output
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 seems the problem may be in Index::Display
https://stackoverflow.com/questions/56826464/why-is-the-width-ignored-for-my-custom-formatter-implementation.
And I prefer using format!()
instead rewriting Display
:D
Signed-off-by: accelsao <jayzhan211@gmail.com>
src/quorum/joint.rs
Outdated
|
||
/// Describe returns a (multi-line) representation of the commit indexes for the | ||
/// given lookuper. | ||
pub fn describe(&self, l: &impl AckedIndexer) -> String { |
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.
Should be pub(crate)
.
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.
Any updates?
src/quorum/majority.rs
Outdated
match tup.idx { | ||
Some(idx) => write!( | ||
buf, | ||
"x".repeat(tup.bar) |
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.
Don't mix write!
and +
. Just use write!
is easy to read.
src/quorum.rs
Outdated
pub struct Index { | ||
pub index: u64, | ||
pub group_id: u64, | ||
} | ||
|
||
impl PartialEq for Index { |
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 doesn't feel right to implement PartialEq
and its family traits for the Index
. As the same index with different group id should not be treat as the same Index
. The comparison rule is limited to context and should not apply universally.
Signed-off-by: accelsao <jayzhan211@gmail.com>
src/quorum/joint.rs
Outdated
@@ -23,6 +23,15 @@ impl Configuration { | |||
} | |||
} | |||
|
|||
// use in test only | |||
#[allow(dead_code)] |
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.
You can use #[cfg(test)]
instead.
src/quorum/datadriven_test.rs
Outdated
// be empty) and the second one is used iff joint is true. | ||
let mut joint = false; | ||
|
||
// The committed indexes for the nodes in the config in the order in |
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 think the comment is for idxs
.
src/quorum/datadriven_test.rs
Outdated
let mut l = AckIndexer::default(); | ||
// next to consume from idxs | ||
let mut p: usize = 0; | ||
let mut ids = ids.to_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.
How about for id in ids.iter().chain(idsj)
?
src/quorum/datadriven_test.rs
Outdated
}; | ||
|
||
let input = idxs.clone(); | ||
let voters: HashSet<u64> = JointConfig::new_joint_from_majorities(c.clone(), cj.clone()) |
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.
.ids().len()
should be enough.
src/quorum/datadriven_test.rs
Outdated
#[test] | ||
fn test_data_driven_quorum() -> anyhow::Result<()> { | ||
let logger = default_logger(); | ||
fn test_quorum(data: &TestData) -> String { |
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.
Better move it out of function for readability.
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.
resolved.
Signed-off-by: accelsao <jayzhan211@gmail.com>
Signed-off-by: accelsao <jayzhan211@gmail.com>
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.
Rest LGTM
src/quorum/joint.rs
Outdated
|
||
/// Describe returns a (multi-line) representation of the commit indexes for the | ||
/// given lookuper. | ||
pub fn describe(&self, l: &impl AckedIndexer) -> String { |
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.
Any updates?
/// > 99 (id=3) | ||
/// 100 | ||
/// ``` | ||
pub(crate) fn describe(&self, l: &impl AckedIndexer) -> String { |
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.
Perhaps we can mark it with #[cfg(test)]
so that we don't need another test case to test it.
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.
Resolved
Signed-off-by: accelsao <jayzhan211@gmail.com>
Signed-off-by: accelsao bebe8277@gmail.com