Move raft index to raft state

pull/3372/head
Jason Wilder 2015-07-17 12:34:39 -06:00
parent 17a9bb041b
commit a9314d6bb7
2 changed files with 10 additions and 1 deletions

View File

@ -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()

View File

@ -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())
}