dir : consensus/state.go
WAL set up (consensus 구동 전에 WAL을 set up)
if _, ok := cs.wal.(nilWAL); ok {
if err := cs.loadWalFile(); err != nil {
return err
}
}
set up timeout
if err := cs.timeoutTicker.Start(); err != nil {
return err
}
노드가 예상치 못하게 중지되었다면 vote 일부를 놓쳤을 수 있는데, 이는 consensus log를 reload해 확인한다.
if cs.doWALCatchup {
// ...
}
receiveRoutine을 생성
receiveRoutine은 채널을 통해 메시지를 받고 합의 과정을 진행시키는 함수를 호출함.
특정 step 수만큼만 실행되고 싶다면 인수로 그 숫자를 넣고, 노드가 꺼질 때까지 무제한적으로 실행하고 싶다면 0을 넣는다.
go cs.receiveRoutine(0)
첫 라운드를 schedule 한다.
// 여기서 timeout을 schedule하고
// 이 타임 아웃이 다 되면 다음 단계 (다음 step이든 round든..) 진행
cs.scheduleRound0(cs.GetRoundState())
return nil