Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raftlog 没有 compact, 测试 snapshot 没什么意义吧? #385

Open
lygn128 opened this issue Apr 2, 2022 · 0 comments
Open

raftlog 没有 compact, 测试 snapshot 没什么意义吧? #385

lygn128 opened this issue Apr 2, 2022 · 0 comments

Comments

@lygn128
Copy link

lygn128 commented Apr 2, 2022

func TestSlowNodeRestore2C(t *testing.T) {
nt := newNetwork(nil, nil, nil)
nt.send(pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgHup})

nt.isolate(3)
for j := 0; j <= 100; j++ {
	nt.send(pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgPropose, Entries: []*pb.Entry{{}}})
}
lead := nt.peers[1].(*Raft)
nextEnts(lead, nt.storage[1])
nt.storage[1].CreateSnapshot(lead.RaftLog.applied, &pb.ConfState{Nodes: nodes(lead)}, nil)
nt.storage[1].Compact(lead.RaftLog.applied)

nt.recover()

// send heartbeats so that the leader can learn everyone is active.
// node 3 will only be considered as active when node 1 receives a reply from it.
nt.send(pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgBeat})

// trigger a snapshot
nt.send(pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgPropose, Entries: []*pb.Entry{{}}})

follower := nt.peers[3].(*Raft)

// trigger a commit
nt.send(pb.Message{From: 1, To: 1, MsgType: pb.MessageType_MsgPropose, Entries: []*pb.Entry{{}}})
if follower.RaftLog.committed != lead.RaftLog.committed {
	t.Errorf("follower.committed = %d, want %d", follower.RaftLog.committed, lead.RaftLog.committed)
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant