raft: remove unused compactThreshold

release-2.0
Jonathan Boulle 2014-10-16 15:32:57 -07:00
parent 7ef375efbd
commit fc42bdb904
2 changed files with 11 additions and 24 deletions

View File

@ -6,10 +6,6 @@ import (
pb "github.com/coreos/etcd/raft/raftpb"
)
const (
defaultCompactThreshold = 10000
)
type raftLog struct {
ents []pb.Entry
unstable uint64
@ -17,19 +13,14 @@ type raftLog struct {
applied uint64
offset uint64
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 {
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) {
l.ents = []pb.Entry{{Term: s.Term}}
l.unstable = s.Index + 1

View File

@ -896,8 +896,8 @@ func TestRecvMsgBeat(t *testing.T) {
func TestRestore(t *testing.T) {
s := pb.Snapshot{
Index: defaultCompactThreshold + 1,
Term: defaultCompactThreshold + 1,
Index: 11, // magic number
Term: 11, // magic number
Nodes: []uint64{1, 2, 3},
RemovedNodes: []uint64{4, 5},
}
@ -934,8 +934,8 @@ func TestRestore(t *testing.T) {
func TestProvideSnap(t *testing.T) {
s := pb.Snapshot{
Index: defaultCompactThreshold + 1,
Term: defaultCompactThreshold + 1,
Index: 11, // magic number
Term: 11, // magic number
Nodes: []uint64{1, 2},
}
sm := newRaft(1, []uint64{1}, 10, 1)
@ -963,8 +963,8 @@ func TestProvideSnap(t *testing.T) {
func TestRestoreFromSnapMsg(t *testing.T) {
s := pb.Snapshot{
Index: defaultCompactThreshold + 1,
Term: defaultCompactThreshold + 1,
Index: 11, // magic number
Term: 11, // magic number
Nodes: []uint64{1, 2},
}
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.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{{}}})
}
lead := nt.peers[1].(*raft)