Skip to content

Commit

Permalink
quorum: add joint group commit (#401)
Browse files Browse the repository at this point in the history
Signed-off-by: accelsao <jayzhan211@gmail.com>
  • Loading branch information
jayzhan211 authored Oct 19, 2020
1 parent 06c5ab7 commit 6998aed
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/quorum/datadriven_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ fn test_quorum(data: &TestData) -> String {
// quorum test instead of a majority quorum test for cfg only).
let mut idxs: Vec<Index> = Vec::new();

// group id of each nodes in the config.
let mut gids: Vec<u64> = Vec::new();

// Votes. These are initialized similar to idxs except the only values
// used are 1 (voted against) and 2 (voted for). This looks awkward,
// but is convenient because it allows sharing code between the two.
Expand Down Expand Up @@ -58,6 +61,16 @@ fn test_quorum(data: &TestData) -> String {
group_id: 0,
});
}
"gid" => {
let mut n: u64 = 0;
if val != "_" {
n = val.parse().expect("type of n should be u64");
if n == 0 {
panic!("use '_' as 0, check {}", data.pos)
}
}
gids.push(n);
}
"votes" => match val.as_str() {
"y" => votes.push(Index {
index: 2,
Expand Down Expand Up @@ -127,6 +140,22 @@ fn test_quorum(data: &TestData) -> String {
);
}

// verify length of group ids
if !gids.is_empty() {
if gids.len() != voters {
return format!(
"error: mismatched input (explicit or _) for group ids {:?}: {:?}",
voters,
gids.len()
);
} else {
// assign group ids to idxs
for (idx, gid) in idxs.iter_mut().zip(gids) {
idx.group_id = gid;
}
}
}

// buffer for expected value
let mut buf = String::new();

Expand Down Expand Up @@ -223,6 +252,35 @@ fn test_quorum(data: &TestData) -> String {
}
));
}
"group_committed" => {
let use_group_commit = true;

let l = make_lookuper(&idxs, &ids, &idsj);

let mut idx = (0, false);

if joint {
let cc = JointConfig::new_joint_from_majorities(c.clone(), cj.clone());
// `describe` doesn't seem to be useful for group commit.
// buf.push_str(&cc.describe(&l));
idx = cc.committed_index(use_group_commit, &l);
// Interchanging the majorities shouldn't make a difference. If it does, print.
let a_idx = JointConfig::new_joint_from_majorities(cj, c)
.committed_index(use_group_commit, &l);
if a_idx != idx {
buf.push_str(&format!("{} <-- via symmetry\n", a_idx.0));
}
} else {
// TODO: majority group commit
}
buf.push_str(&format!(
"{}\n",
Index {
index: idx.0,
group_id: 0
}
));
}
"vote" => {
let ll = make_lookuper(&votes, &ids, &idsj);
let mut l = HashMap::default();
Expand Down
76 changes: 76 additions & 0 deletions src/quorum/testdata/joint_group_commit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# the same result of joint single group commit
group_committed cfg=(1,2,3) cfgj=zero idx=(100,101,99) gid=(1,1,1)
----
100

# min(quorum_commit_index = 100, first index that appears in second group = 99)
group_committed cfg=(1,2,3) cfgj=zero idx=(100,101,99) gid=(1,1,2)
----
99

# min(quorum_commit_index = 100, first index that appears in second group = 101)
group_committed cfg=(1,2,3) cfgj=zero idx=(100,101,99) gid=(2,1,1)
----
100

# minimum index = 99
group_committed cfg=(1,2,3) cfgj=zero idx=(100,101,99) gid=(_,1,1)
----
99

# min(quorum_commit_index = 100, first index that appears in second group = 99)
group_committed cfg=(1,2,3) cfgj=zero idx=(100,101,99) gid=(_,1,2)
----
99

# minimum index = 98
group_committed cfg=(1,2,3,4,5) cfgj=zero idx=(100,101,99,102,98) gid=(_,_,_,_,1)
----
98

# cfg 1 = min(quorum_commit_index = 100, first index that appears in second group = 99)
# cfg 2 = min(quorum_commit_index = 100, first index that appears in second group = 1)
group_committed cfg=(1,2,3,4) cfgj=(3,4,5,6) idx=(101,99,100,102,103,1) gid=(1,_,1,1,_,2)
----
1

# cfg 1 = min(quorum_commit_index = 100, first index that appears in second group = 101)
# cfg 2 = min(quorum_commit_index = 100, first index that appears in second group = 101)
group_committed cfg=(1,2,3) cfgj=(4,5,6) idx=(99,100,101,99,100,101) gid=(1,1,2,1,2,1)
----
100

# cfg 1 = min(quorum_commit_index = 100, first index that appears in second group = 101)
# cfg 2 = minimum index = 99
group_committed cfg=(1,2,3) cfgj=(4,5,6) idx=(99,100,101,99,100,101) gid=(1,1,2,1,1,_)
----
99

# min(quorum_commit_index = 101, first index that appears in second group = 103)
group_committed cfg=(1,2,3,4,5) cfgj=zero idx=(99,100,101,102,103) gid=(1,1,1,1,2)
----
101

# cfg 1 = minimum index = 1
# cfg 2 = minimum index = 2
group_committed cfg=(1,2,3,4,5) cfgj=(2,3,4,5,6) idx=(1,100,101,102,103,2) gid=(1,_,1,1,1,1)
----
1

# cfg 1 = minimum index = 3
# cfg 2 = quorum_commit_index = 101
group_committed cfg=(1,2,3,4,5) cfgj=(2,3,4,5,6) idx=(3,100,101,102,103,2) gid=(_,1,1,1,1,1)
----
3

# cfg 1 = min(quorum_commit_index = 101, first index that appears in second group = 103)
# cfg 2 = min(quorum_commit_index = 101, first index that appears in second group = 103)
group_committed cfg=(1,2,3,4,5) cfgj=(2,3,4,5,6) idx=(3,100,101,102,103,2) gid=(_,1,1,1,3,1)
----
101

# cfg 1 = minimum index = 3
# cfg 2 = min(quorum_commit_index = 101, first index that appears in second group = 2)
group_committed cfg=(1,2,3,4,5) cfgj=(2,3,4,5,6) idx=(3,100,101,102,103,2) gid=(_,1,1,1,1,3)
----
2

0 comments on commit 6998aed

Please sign in to comment.