Skip to content

Commit

Permalink
fixup! rename some variables
Browse files Browse the repository at this point in the history
  • Loading branch information
tbg committed Jun 19, 2019
1 parent cf8615d commit a08826c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
34 changes: 17 additions & 17 deletions raft/quorum/datadriven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,20 +168,20 @@ func TestDataDriven(t *testing.T) {
// Branch based on whether this is a majority or joint quorum
// test case.
if !joint {
cr := c.CommittedIndex(l)
idx := c.CommittedIndex(l)
fmt.Fprintf(&buf, c.Describe(l))
// These alternative computations should return the same
// result. If not, print to the output.
if acr := alternativeMajorityCommittedIndex(c, l); acr != cr {
fmt.Fprintf(&buf, "%s <-- via alternative computation\n", acr)
if aIdx := alternativeMajorityCommittedIndex(c, l); aIdx != idx {
fmt.Fprintf(&buf, "%s <-- via alternative computation\n", aIdx)
}
// Joining a majority with the empty majority should give same result.
if acr := JointConfig([2]MajorityConfig{c, {}}).CommittedIndex(l); acr != cr {
fmt.Fprintf(&buf, "%s <-- via zero-joint quorum\n", acr)
if aIdx := JointConfig([2]MajorityConfig{c, {}}).CommittedIndex(l); aIdx != idx {
fmt.Fprintf(&buf, "%s <-- via zero-joint quorum\n", aIdx)
}
// Joining a majority with itself should give same result.
if acr := JointConfig([2]MajorityConfig{c, c}).CommittedIndex(l); acr != cr {
fmt.Fprintf(&buf, "%s <-- via self-joint quorum\n", acr)
if aIdx := JointConfig([2]MajorityConfig{c, c}).CommittedIndex(l); aIdx != idx {
fmt.Fprintf(&buf, "%s <-- via self-joint quorum\n", aIdx)
}
overlay := func(c MajorityConfig, l AckedIndexer, id uint64, idx Index) AckedIndexer {
ll := mapAckIndexer{}
Expand All @@ -196,30 +196,30 @@ func TestDataDriven(t *testing.T) {
}
for id := range c {
idx, _ := l.AckedIndex(id)
if cr > idx && idx > 0 {
if idx > idx && idx > 0 {
// If the committed index was definitely above the currently
// inspected idx, the result shouldn't change if we lower it
// further.
lo := overlay(c, l, id, idx-1)
if cro := c.CommittedIndex(lo); cro != cr {
fmt.Fprintf(&buf, "%s <-- overlaying %d->%d", cro, id, idx)
if aIdx := c.CommittedIndex(lo); aIdx != idx {
fmt.Fprintf(&buf, "%s <-- overlaying %d->%d", aIdx, id, idx)
}
lo = overlay(c, l, id, 0)
if cro := c.CommittedIndex(lo); cro != cr {
fmt.Fprintf(&buf, "%s <-- overlaying %d->0", cro, id)
if aIdx := c.CommittedIndex(lo); aIdx != idx {
fmt.Fprintf(&buf, "%s <-- overlaying %d->0", aIdx, id)
}
}
}
fmt.Fprintf(&buf, "%s\n", cr)
fmt.Fprintf(&buf, "%s\n", idx)
} else {
cc := JointConfig([2]MajorityConfig{c, cj})
fmt.Fprintf(&buf, cc.Describe(l))
cr := cc.CommittedIndex(l)
idx := cc.CommittedIndex(l)
// Interchanging the majorities shouldn't make a difference. If it does, print.
if acr := JointConfig([2]MajorityConfig{c, cj}).CommittedIndex(l); acr != cr {
fmt.Fprintf(&buf, "%s <-- via symmetry\n", acr)
if aIdx := JointConfig([2]MajorityConfig{c, cj}).CommittedIndex(l); aIdx != idx {
fmt.Fprintf(&buf, "%s <-- via symmetry\n", aIdx)
}
fmt.Fprintf(&buf, "%s\n", cr)
fmt.Fprintf(&buf, "%s\n", idx)
}
case "vote":
ll := makeLookuper(votes, ids, idsj)
Expand Down
10 changes: 5 additions & 5 deletions raft/quorum/joint.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func (c JointConfig) Describe(l AckedIndexer) string {
// quorum. An index is jointly committed if it is committed in both constituent
// majorities.
func (c JointConfig) CommittedIndex(l AckedIndexer) Index {
cl := c[0].CommittedIndex(l)
cr := c[1].CommittedIndex(l)
if cl < cr {
return cl
idx0 := c[0].CommittedIndex(l)
idx1 := c[1].CommittedIndex(l)
if idx0 < idx1 {
return idx0
}
return cr
return idx1
}

// VoteResult takes a mapping of voters to yes/no (true/false) votes and returns
Expand Down

0 comments on commit a08826c

Please sign in to comment.