Browse Source

raft: index{} -> progress{}

Blake Mizerany 11 years ago
parent
commit
3c483e19d7
2 changed files with 14 additions and 14 deletions
  1. 10 10
      raft2/raft.go
  2. 4 4
      raft2/raft_test.go

+ 10 - 10
raft2/raft.go

@@ -84,22 +84,22 @@ func (m Message) String() string {
 		m.Type, m.From, m.To, m.Term, m.LogTerm, m.Index, m.Commit, len(m.Entries))
 		m.Type, m.From, m.To, m.Term, m.LogTerm, m.Index, m.Commit, len(m.Entries))
 }
 }
 
 
-type index struct {
+type progress struct {
 	match, next int64
 	match, next int64
 }
 }
 
 
-func (in *index) update(n int64) {
+func (in *progress) update(n int64) {
 	in.match = n
 	in.match = n
 	in.next = n + 1
 	in.next = n + 1
 }
 }
 
 
-func (in *index) decr() {
+func (in *progress) decr() {
 	if in.next--; in.next < 1 {
 	if in.next--; in.next < 1 {
 		in.next = 1
 		in.next = 1
 	}
 	}
 }
 }
 
 
-func (in *index) String() string {
+func (in *progress) String() string {
 	return fmt.Sprintf("n=%d m=%d", in.next, in.match)
 	return fmt.Sprintf("n=%d m=%d", in.next, in.match)
 }
 }
 
 
@@ -132,7 +132,7 @@ type raft struct {
 	// the log
 	// the log
 	raftLog *raftLog
 	raftLog *raftLog
 
 
-	ins map[int64]*index
+	ins map[int64]*progress
 
 
 	state stateType
 	state stateType
 
 
@@ -156,9 +156,9 @@ func newStateMachine(id int64, peers []int64) *raft {
 	if id == none {
 	if id == none {
 		panic("cannot use none id")
 		panic("cannot use none id")
 	}
 	}
-	sm := &raft{id: id, lead: none, raftLog: newLog(), ins: make(map[int64]*index)}
+	sm := &raft{id: id, lead: none, raftLog: newLog(), ins: make(map[int64]*progress)}
 	for _, p := range peers {
 	for _, p := range peers {
-		sm.ins[p] = &index{}
+		sm.ins[p] = &progress{}
 	}
 	}
 	sm.reset(0)
 	sm.reset(0)
 	return sm
 	return sm
@@ -279,7 +279,7 @@ func (sm *raft) reset(term int64) {
 	sm.setVote(none)
 	sm.setVote(none)
 	sm.votes = make(map[int64]bool)
 	sm.votes = make(map[int64]bool)
 	for i := range sm.ins {
 	for i := range sm.ins {
-		sm.ins[i] = &index{next: sm.raftLog.lastIndex() + 1}
+		sm.ins[i] = &progress{next: sm.raftLog.lastIndex() + 1}
 		if i == sm.id {
 		if i == sm.id {
 			sm.ins[i].match = sm.raftLog.lastIndex()
 			sm.ins[i].match = sm.raftLog.lastIndex()
 		}
 		}
@@ -500,7 +500,7 @@ func (sm *raft) restore(s Snapshot) bool {
 
 
 	sm.raftLog.restore(s)
 	sm.raftLog.restore(s)
 	sm.LastIndex = sm.raftLog.lastIndex()
 	sm.LastIndex = sm.raftLog.lastIndex()
-	sm.ins = make(map[int64]*index)
+	sm.ins = make(map[int64]*progress)
 	for _, n := range s.Nodes {
 	for _, n := range s.Nodes {
 		if n == sm.id {
 		if n == sm.id {
 			sm.addIns(n, sm.raftLog.lastIndex(), sm.raftLog.lastIndex()+1)
 			sm.addIns(n, sm.raftLog.lastIndex(), sm.raftLog.lastIndex()+1)
@@ -541,7 +541,7 @@ func (sm *raft) setVote(vote int64) {
 }
 }
 
 
 func (sm *raft) addIns(id, match, next int64) {
 func (sm *raft) addIns(id, match, next int64) {
-	sm.ins[id] = &index{next: next, match: match}
+	sm.ins[id] = &progress{next: next, match: match}
 	sm.saveState()
 	sm.saveState()
 }
 }
 
 

+ 4 - 4
raft2/raft_test.go

@@ -437,9 +437,9 @@ func TestCommit(t *testing.T) {
 	}
 	}
 
 
 	for i, tt := range tests {
 	for i, tt := range tests {
-		ins := make(map[int64]*index)
+		ins := make(map[int64]*progress)
 		for j := 0; j < len(tt.matches); j++ {
 		for j := 0; j < len(tt.matches); j++ {
-			ins[int64(j)] = &index{tt.matches[j], tt.matches[j] + 1}
+			ins[int64(j)] = &progress{tt.matches[j], tt.matches[j] + 1}
 		}
 		}
 		sm := &raft{raftLog: &raftLog{ents: tt.logs}, ins: ins, State: State{Term: tt.smTerm}}
 		sm := &raft{raftLog: &raftLog{ents: tt.logs}, ins: ins, State: State{Term: tt.smTerm}}
 		sm.maybeCommit()
 		sm.maybeCommit()
@@ -936,9 +936,9 @@ func newNetwork(peers ...Interface) *network {
 			npeers[nid] = sm
 			npeers[nid] = sm
 		case *raft:
 		case *raft:
 			v.id = nid
 			v.id = nid
-			v.ins = make(map[int64]*index)
+			v.ins = make(map[int64]*progress)
 			for i := 0; i < size; i++ {
 			for i := 0; i < size; i++ {
-				v.ins[int64(i)] = &index{}
+				v.ins[int64(i)] = &progress{}
 			}
 			}
 			v.reset(0)
 			v.reset(0)
 			npeers[nid] = v
 			npeers[nid] = v