Move raft index to raft state
parent
17a9bb041b
commit
a9314d6bb7
|
@ -26,6 +26,7 @@ type raftState interface {
|
|||
addPeer(addr string) error
|
||||
invalidate() error
|
||||
close() error
|
||||
lastIndex() uint64
|
||||
}
|
||||
|
||||
// localRaft is a consensus strategy that uses a local raft implementation fo
|
||||
|
@ -125,6 +126,10 @@ func (r *localRaft) initialize() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *localRaft) lastIndex() uint64 {
|
||||
return r.store.raft.LastIndex()
|
||||
}
|
||||
|
||||
func (r *localRaft) sync(index uint64, timeout time.Duration) error {
|
||||
ticker := time.NewTicker(100 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
|
@ -283,6 +288,10 @@ func (r *remoteRaft) isLeader() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (r *remoteRaft) lastIndex() uint64 {
|
||||
return r.store.cachedData().Index
|
||||
}
|
||||
|
||||
func (r *remoteRaft) sync(index uint64, timeout time.Duration) error {
|
||||
//FIXME: jwilder: check index and timeout
|
||||
return r.store.invalidate()
|
||||
|
|
|
@ -539,7 +539,7 @@ func (s *Store) handleExecConn(conn net.Conn) {
|
|||
// Build response message.
|
||||
var resp internal.Response
|
||||
resp.OK = proto.Bool(err == nil)
|
||||
resp.Index = proto.Uint64(s.raft.LastIndex())
|
||||
resp.Index = proto.Uint64(s.raftState.lastIndex())
|
||||
if err != nil {
|
||||
resp.Error = proto.String(err.Error())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue