mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
raft: seperate dequeuing from slicing
This commit is contained in:
parent
e17f79ee70
commit
f03c3bce05
31
raft/log.go
31
raft/log.go
@ -85,9 +85,26 @@ func (l *raftLog) findConflict(from int64, ents []Entry) int64 {
|
||||
}
|
||||
|
||||
func (l *raftLog) unstableEnts() []Entry {
|
||||
ents := l.entries(l.unstable)
|
||||
return l.entries(l.unstable)
|
||||
}
|
||||
|
||||
func (l *raftLog) resetUnstable() {
|
||||
l.unstable = l.lastIndex() + 1
|
||||
return ents
|
||||
}
|
||||
|
||||
// nextEnts returns all the available entries for execution.
|
||||
// all the returned entries will be marked as applied.
|
||||
func (l *raftLog) nextEnts() (ents []Entry) {
|
||||
if l.committed > l.applied {
|
||||
return l.slice(l.applied+1, l.committed+1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *raftLog) resetNextEnts() {
|
||||
if l.committed > l.applied {
|
||||
l.applied = l.committed
|
||||
}
|
||||
}
|
||||
|
||||
func (l *raftLog) lastIndex() int64 {
|
||||
@ -131,16 +148,6 @@ func (l *raftLog) maybeCommit(maxIndex, term int64) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// nextEnts returns all the available entries for execution.
|
||||
// all the returned entries will be marked as applied.
|
||||
func (l *raftLog) nextEnts() (ents []Entry) {
|
||||
if l.committed > l.applied {
|
||||
ents = l.slice(l.applied+1, l.committed+1)
|
||||
l.applied = l.committed
|
||||
}
|
||||
return ents
|
||||
}
|
||||
|
||||
// compact compacts all log entries until i.
|
||||
// It removes the log entries before i, exclusive.
|
||||
// i must be not smaller than the index of the first entry
|
||||
|
@ -134,6 +134,7 @@ func TestUnstableEnts(t *testing.T) {
|
||||
raftLog.ents = append(raftLog.ents, previousEnts...)
|
||||
raftLog.unstable = tt.unstable
|
||||
ents := raftLog.unstableEnts()
|
||||
raftLog.resetUnstable()
|
||||
if !reflect.DeepEqual(ents, tt.wents) {
|
||||
t.Errorf("#%d: unstableEnts = %+v, want %+v", i, ents, tt.wents)
|
||||
}
|
||||
|
@ -273,7 +273,9 @@ func (sm *stateMachine) maybeCommit() bool {
|
||||
|
||||
// nextEnts returns the appliable entries and updates the applied index
|
||||
func (sm *stateMachine) nextEnts() (ents []Entry) {
|
||||
return sm.raftLog.nextEnts()
|
||||
ents = sm.raftLog.nextEnts()
|
||||
sm.raftLog.resetNextEnts()
|
||||
return ents
|
||||
}
|
||||
|
||||
func (sm *stateMachine) reset(term int64) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user