Browse Source

Merge pull request #1314 from jonboulle/raft_tests

raft: remove unused compactThreshold
Jonathan Boulle 11 years ago
parent
commit
b7c42b0d76
2 changed files with 11 additions and 24 deletions
  1. 4 17
      raft/log.go
  2. 7 7
      raft/raft_test.go

+ 4 - 17
raft/log.go

@@ -6,10 +6,6 @@ import (
 	pb "github.com/coreos/etcd/raft/raftpb"
 	pb "github.com/coreos/etcd/raft/raftpb"
 )
 )
 
 
-const (
-	defaultCompactThreshold = 10000
-)
-
 type raftLog struct {
 type raftLog struct {
 	ents      []pb.Entry
 	ents      []pb.Entry
 	unstable  uint64
 	unstable  uint64
@@ -17,19 +13,14 @@ type raftLog struct {
 	applied   uint64
 	applied   uint64
 	offset    uint64
 	offset    uint64
 	snapshot  pb.Snapshot
 	snapshot  pb.Snapshot
-
-	// want a compact after the number of entries exceeds the threshold
-	// TODO(xiangli) size might be a better criteria
-	compactThreshold uint64
 }
 }
 
 
 func newLog() *raftLog {
 func newLog() *raftLog {
 	return &raftLog{
 	return &raftLog{
-		ents:             make([]pb.Entry, 1),
-		unstable:         0,
-		committed:        0,
-		applied:          0,
-		compactThreshold: defaultCompactThreshold,
+		ents:      make([]pb.Entry, 1),
+		unstable:  0,
+		committed: 0,
+		applied:   0,
 	}
 	}
 }
 }
 
 
@@ -178,10 +169,6 @@ func (l *raftLog) snap(d []byte, index, term uint64, nodes []uint64, removed []u
 	}
 	}
 }
 }
 
 
-func (l *raftLog) shouldCompact() bool {
-	return (l.applied - l.offset) > l.compactThreshold
-}
-
 func (l *raftLog) restore(s pb.Snapshot) {
 func (l *raftLog) restore(s pb.Snapshot) {
 	l.ents = []pb.Entry{{Term: s.Term}}
 	l.ents = []pb.Entry{{Term: s.Term}}
 	l.unstable = s.Index + 1
 	l.unstable = s.Index + 1

+ 7 - 7
raft/raft_test.go

@@ -896,8 +896,8 @@ func TestRecvMsgBeat(t *testing.T) {
 
 
 func TestRestore(t *testing.T) {
 func TestRestore(t *testing.T) {
 	s := pb.Snapshot{
 	s := pb.Snapshot{
-		Index:        defaultCompactThreshold + 1,
-		Term:         defaultCompactThreshold + 1,
+		Index:        11, // magic number
+		Term:         11, // magic number
 		Nodes:        []uint64{1, 2, 3},
 		Nodes:        []uint64{1, 2, 3},
 		RemovedNodes: []uint64{4, 5},
 		RemovedNodes: []uint64{4, 5},
 	}
 	}
@@ -934,8 +934,8 @@ func TestRestore(t *testing.T) {
 
 
 func TestProvideSnap(t *testing.T) {
 func TestProvideSnap(t *testing.T) {
 	s := pb.Snapshot{
 	s := pb.Snapshot{
-		Index: defaultCompactThreshold + 1,
-		Term:  defaultCompactThreshold + 1,
+		Index: 11, // magic number
+		Term:  11, // magic number
 		Nodes: []uint64{1, 2},
 		Nodes: []uint64{1, 2},
 	}
 	}
 	sm := newRaft(1, []uint64{1}, 10, 1)
 	sm := newRaft(1, []uint64{1}, 10, 1)
@@ -963,8 +963,8 @@ func TestProvideSnap(t *testing.T) {
 
 
 func TestRestoreFromSnapMsg(t *testing.T) {
 func TestRestoreFromSnapMsg(t *testing.T) {
 	s := pb.Snapshot{
 	s := pb.Snapshot{
-		Index: defaultCompactThreshold + 1,
-		Term:  defaultCompactThreshold + 1,
+		Index: 11, // magic number
+		Term:  11, // magic number
 		Nodes: []uint64{1, 2},
 		Nodes: []uint64{1, 2},
 	}
 	}
 	m := pb.Message{Type: pb.MsgSnap, From: 1, Term: 2, Snapshot: s}
 	m := pb.Message{Type: pb.MsgSnap, From: 1, Term: 2, Snapshot: s}
@@ -982,7 +982,7 @@ func TestSlowNodeRestore(t *testing.T) {
 	nt.send(pb.Message{From: 1, To: 1, Type: pb.MsgHup})
 	nt.send(pb.Message{From: 1, To: 1, Type: pb.MsgHup})
 
 
 	nt.isolate(3)
 	nt.isolate(3)
-	for j := 0; j < defaultCompactThreshold+1; j++ {
+	for j := 0; j <= 100; j++ {
 		nt.send(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{}}})
 		nt.send(pb.Message{From: 1, To: 1, Type: pb.MsgProp, Entries: []pb.Entry{{}}})
 	}
 	}
 	lead := nt.peers[1].(*raft)
 	lead := nt.peers[1].(*raft)