Raft: fix problems reported by golint.
parent
fe0e168b3b
commit
3ad0df3722
|
@ -11,6 +11,8 @@ import (
|
|||
|
||||
var (
|
||||
emptyState = pb.HardState{}
|
||||
|
||||
// ErrStopped is returned by methods on Nodes that have been stopped.
|
||||
ErrStopped = errors.New("raft: stopped")
|
||||
)
|
||||
|
||||
|
@ -68,10 +70,12 @@ func isHardStateEqual(a, b pb.HardState) bool {
|
|||
return a.Term == b.Term && a.Vote == b.Vote && a.Commit == b.Commit
|
||||
}
|
||||
|
||||
// IsEmptyHardState returns true if the given HardState is empty.
|
||||
func IsEmptyHardState(st pb.HardState) bool {
|
||||
return isHardStateEqual(st, emptyState)
|
||||
}
|
||||
|
||||
// IsEmptySnap returns true if the given Snapshot is empty.
|
||||
func IsEmptySnap(sp pb.Snapshot) bool {
|
||||
return sp.Index == 0
|
||||
}
|
||||
|
@ -81,6 +85,7 @@ func (rd Ready) containsUpdates() bool {
|
|||
len(rd.Entries) > 0 || len(rd.CommittedEntries) > 0 || len(rd.Messages) > 0
|
||||
}
|
||||
|
||||
// Node represents a node in a raft cluster.
|
||||
type Node interface {
|
||||
// Tick increments the internal logical clock for the Node by a single tick. Election
|
||||
// timeouts and heartbeat timeouts are in units of ticks.
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
pb "github.com/coreos/etcd/raft/raftpb"
|
||||
)
|
||||
|
||||
// None is a placeholder node ID used when there is no leader.
|
||||
const None int64 = 0
|
||||
|
||||
type messageType int64
|
||||
|
@ -42,12 +43,14 @@ func (mt messageType) String() string {
|
|||
|
||||
var errNoLeader = errors.New("no leader")
|
||||
|
||||
// Possible values for StateType.
|
||||
const (
|
||||
StateFollower StateType = iota
|
||||
StateCandidate
|
||||
StateLeader
|
||||
)
|
||||
|
||||
// StateType represents the role of a node in a cluster.
|
||||
type StateType int64
|
||||
|
||||
var stmap = [...]string{
|
||||
|
|
|
@ -91,13 +91,13 @@ func TestLogReplication(t *testing.T) {
|
|||
t.Errorf("#%d.%d: committed = %d, want %d", i, j, sm.raftLog.committed, tt.wcommitted)
|
||||
}
|
||||
|
||||
ents := make([]pb.Entry, 0)
|
||||
ents := []pb.Entry{}
|
||||
for _, e := range nextEnts(sm) {
|
||||
if e.Data != nil {
|
||||
ents = append(ents, e)
|
||||
}
|
||||
}
|
||||
props := make([]pb.Message, 0)
|
||||
props := []pb.Message{}
|
||||
for _, m := range tt.msgs {
|
||||
if m.Type == msgProp {
|
||||
props = append(props, m)
|
||||
|
@ -1237,7 +1237,7 @@ func (nw *network) recover() {
|
|||
}
|
||||
|
||||
func (nw *network) filter(msgs []pb.Message) []pb.Message {
|
||||
mm := make([]pb.Message, 0)
|
||||
mm := []pb.Message{}
|
||||
for _, m := range msgs {
|
||||
if nw.ignorem[m.Type] {
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue