mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: ins: []*index -> []index
It could make raft faster, use less storage.
This commit is contained in:
parent
1170c21f89
commit
c1c45575be
11
raft/raft.go
11
raft/raft.go
@ -95,7 +95,7 @@ type stateMachine struct {
|
|||||||
// the log
|
// the log
|
||||||
log *log
|
log *log
|
||||||
|
|
||||||
ins []*index
|
ins []index
|
||||||
|
|
||||||
state stateType
|
state stateType
|
||||||
|
|
||||||
@ -178,9 +178,9 @@ func (sm *stateMachine) reset() {
|
|||||||
sm.lead = none
|
sm.lead = none
|
||||||
sm.vote = none
|
sm.vote = none
|
||||||
sm.votes = make(map[int]bool)
|
sm.votes = make(map[int]bool)
|
||||||
sm.ins = make([]*index, sm.k)
|
sm.ins = make([]index, sm.k)
|
||||||
for i := range sm.ins {
|
for i := range sm.ins {
|
||||||
sm.ins[i] = &index{next: sm.log.lastIndex() + 1}
|
sm.ins[i] = index{next: sm.log.lastIndex() + 1}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,12 +273,11 @@ func (sm *stateMachine) Step(m Message) {
|
|||||||
case stateLeader:
|
case stateLeader:
|
||||||
switch m.Type {
|
switch m.Type {
|
||||||
case msgAppResp:
|
case msgAppResp:
|
||||||
in := sm.ins[m.From]
|
|
||||||
if m.Index < 0 {
|
if m.Index < 0 {
|
||||||
in.decr()
|
sm.ins[m.From].decr()
|
||||||
sm.sendAppend()
|
sm.sendAppend()
|
||||||
} else {
|
} else {
|
||||||
in.update(m.Index)
|
sm.ins[m.From].update(m.Index)
|
||||||
if sm.maybeCommit() {
|
if sm.maybeCommit() {
|
||||||
sm.sendAppend()
|
sm.sendAppend()
|
||||||
}
|
}
|
||||||
|
@ -331,9 +331,9 @@ func TestCommit(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
ins := make([]*index, len(tt.matches))
|
ins := make([]index, len(tt.matches))
|
||||||
for j := 0; j < len(ins); j++ {
|
for j := 0; j < len(ins); j++ {
|
||||||
ins[j] = &index{tt.matches[j], tt.matches[j] + 1}
|
ins[j] = index{tt.matches[j], tt.matches[j] + 1}
|
||||||
}
|
}
|
||||||
sm := &stateMachine{log: &log{ents: tt.logs}, ins: ins, k: len(ins), term: tt.smTerm}
|
sm := &stateMachine{log: &log{ents: tt.logs}, ins: ins, k: len(ins), term: tt.smTerm}
|
||||||
sm.maybeCommit()
|
sm.maybeCommit()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user