Skip to content

Commit

Permalink
autoleave take two
Browse files Browse the repository at this point in the history
  • Loading branch information
tbg committed Jul 22, 2019
1 parent d60d905 commit a92983a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions raft/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -1445,8 +1445,8 @@ func (r *raft) applyConfChange(cc pb.ConfChangeV2) pb.ConfState {
}
if cc.LeaveJoint() {
return changer.LeaveJoint()
} else if autoLeave := cc.EnterJoint(); autoLeave != nil {
return changer.EnterJoint(*autoLeave, cc.Changes...)
} else if autoLeave, ok := cc.EnterJoint(); ok {
return changer.EnterJoint(autoLeave, cc.Changes...)
}
return changer.Simple(cc.Changes...)
}()
Expand Down
16 changes: 8 additions & 8 deletions raft/raftpb/confchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (c ConfChangeV2) AsV2() ConfChangeV2 { return c }
// AsV1 returns ConfChange{} and false.
func (c ConfChangeV2) AsV1() (ConfChange, bool) { return ConfChange{}, false }

// EnterJoint returns a pointer to a bool if the configuration change will use
// Joint Consensus, which is the case if it contains more than one change or the
// use of Joint Consensus was requested explicitly. The bool is true if the
// Joint State will be left automatically, and false otherwise.
// If Joint Consensus will not be used, this method returns nil.
func (c *ConfChangeV2) EnterJoint() *bool {
// EnterJoint returns two bools. The second bool is true if and only if this
// config change will use Joint Consensus, which is the case if it contains more
// than one change or if the use of Joint Consensus was requested explicitly.
// The first bool can only be true if second one is, and indicates whether the
// Joint State will be left automatically.
func (c *ConfChangeV2) EnterJoint() (autoLeave bool, ok bool) {
// NB: in theory, more config changes could qualify for the "simple"
// protocol but it depends on the config on top of which the changes apply.
// For example, adding two learners is not OK if both nodes are part of the
Expand All @@ -90,9 +90,9 @@ func (c *ConfChangeV2) EnterJoint() *bool {
default:
panic(fmt.Sprintf("unknown transition: %+v", c))
}
return &autoLeave
return autoLeave, true
}
return nil
return false, false
}

// LeaveJoint is true if the configuration change leaves a joint configuration.
Expand Down

0 comments on commit a92983a

Please sign in to comment.