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

quorum: port single group joint commit #394

Merged
merged 11 commits into from
Sep 17, 2020
Merged

Conversation

jayzhan211
Copy link
Contributor

Signed-off-by: accelsao bebe8277@gmail.com

Signed-off-by: accelsao <bebe8277@gmail.com>
committed cfg=(1,2,3) cfgj=zero idx=(100,101,99)
----
idx
x> [0]100 (id=1)
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

Choose a reason for hiding this comment

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

Can they be removed?

Copy link
Contributor Author

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?

Copy link
Member

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.

@BusyJay BusyJay requested a review from NingLin-P August 26, 2020 05:50
Comment on lines 135 to 137
/// Describe returns a (multi-line) representation of the commit indexes for the
/// given lookuper.
pub fn describe(&self, l: &impl AckedIndexer) -> String {
Copy link
Member

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

use datadriven::{run_test, TestData};

#[test]
fn test_data_driven_quorum() -> anyhow::Result<()> {
Copy link
Member

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?

Copy link
Contributor Author

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>
/// > 99 (id=3)
/// 100
/// ```
pub fn describe(&self, l: &impl AckedIndexer) -> String {
Copy link
Member

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>
NingLin-P
NingLin-P previously approved these changes Aug 28, 2020
Copy link
Member

@NingLin-P NingLin-P left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Fullstop000
Fullstop000 previously approved these changes Aug 28, 2020
Copy link
Member

@Fullstop000 Fullstop000 left a comment

Choose a reason for hiding this comment

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

LGTM

@jayzhan211
Copy link
Contributor Author

@BusyJay PTAL, thanks

Signed-off-by: accelsao <bebe8277@gmail.com>
Signed-off-by: accelsao <bebe8277@gmail.com>
r#" idx
? 0 (id=1)
x> 120 (id=2)
> [1]120 (id=3)
Copy link
Contributor Author

@jayzhan211 jayzhan211 Aug 31, 2020

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)

@jayzhan211
Copy link
Contributor Author

@BusyJay PTAL, thanks

@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

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

Should be pub(crate).

/// > 99 (id=3)
/// 100
/// ```
pub fn describe(&self, l: &impl AckedIndexer) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

Should be pub(crate).

// 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![];
Copy link
Member

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).


let mut info = vec![];

for id in self.raw_slice() {
Copy link
Member

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?

info.push(Tup { id, idx, bar: 0 })
}

info.sort_by(|a, b| match a.idx.cmp(&b.idx) {
Copy link
Member

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))?

for tup in info {
let string;
if let Some(idx) = tup.idx {
string = "x".repeat(tup.bar)
Copy link
Member

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?

string = "x".repeat(tup.bar)
+ ">"
+ " ".repeat(n - tup.bar).as_str()
+ format!(" {:>5} (id={})\n", format!("{}", idx), tup.id).as_str();
Copy link
Member

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().

Copy link
Contributor Author

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

Copy link
Contributor Author

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");

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the following is the result with this code writeln!(buf, " {:>5} (id={})", idx, tup.id),
the green one is the expected output.

Copy link
Contributor Author

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

Copy link
Contributor Author

@jayzhan211 jayzhan211 Sep 15, 2020

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>

/// Describe returns a (multi-line) representation of the commit indexes for the
/// given lookuper.
pub fn describe(&self, l: &impl AckedIndexer) -> String {
Copy link
Member

Choose a reason for hiding this comment

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

Should be pub(crate).

Copy link
Member

Choose a reason for hiding this comment

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

Any updates?

match tup.idx {
Some(idx) => write!(
buf,
"x".repeat(tup.bar)
Copy link
Member

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 {
Copy link
Member

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>
@@ -23,6 +23,15 @@ impl Configuration {
}
}

// use in test only
#[allow(dead_code)]
Copy link
Member

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.

// 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
Copy link
Member

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.

let mut l = AckIndexer::default();
// next to consume from idxs
let mut p: usize = 0;
let mut ids = ids.to_vec();
Copy link
Member

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)?

};

let input = idxs.clone();
let voters: HashSet<u64> = JointConfig::new_joint_from_majorities(c.clone(), cj.clone())
Copy link
Member

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.

#[test]
fn test_data_driven_quorum() -> anyhow::Result<()> {
let logger = default_logger();
fn test_quorum(data: &TestData) -> String {
Copy link
Member

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.

Copy link
Contributor Author

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>
Copy link
Member

@BusyJay BusyJay left a comment

Choose a reason for hiding this comment

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

Rest LGTM


/// Describe returns a (multi-line) representation of the commit indexes for the
/// given lookuper.
pub fn describe(&self, l: &impl AckedIndexer) -> String {
Copy link
Member

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 {
Copy link
Member

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.

Copy link
Contributor Author

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>
@BusyJay BusyJay merged commit 0c53e7b into tikv:master Sep 17, 2020
@jayzhan211 jayzhan211 deleted the single-commit branch September 17, 2020 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants