@@ -2,8 +2,7 @@ package raft
// Join command interface
type JoinCommand interface {
- CommandName() string
- Apply(server Server) (interface{}, error)
+ Command
NodeName() string
}
// Leave command interface
type LeaveCommand interface {
@@ -74,11 +74,7 @@ func (l *Log) CommitIndex() uint64 {
func (l *Log) currentIndex() uint64 {
l.mutex.RLock()
defer l.mutex.RUnlock()
-
- if len(l.entries) == 0 {
- return l.startIndex
- }
- return l.entries[len(l.entries)-1].Index
+ return l.internalCurrentIndex()
// The current index in the log without locking
@@ -176,7 +176,7 @@ func NewServer(name string, path string, transporter Transporter, stateMachine S
return c.Apply(&context{
server: s,
currentTerm: s.currentTerm,
- currentIndex: s.log.currentIndex(),
+ currentIndex: s.log.internalCurrentIndex(),
commitIndex: s.log.commitIndex,
})
case deprecatedCommandApply: