Page 194 - 《软件学报》2021年第6期
P. 194

1768                                     Journal of Software  软件学报 Vol.32, No.6,  June 2021

                          date6date,
                          value6chosen.value,
                          committed6chosen.committed]

             BecomeLeaderCandidate(i)==
               /\currentState[i]=Candidate
               /\\E P\in Quorums:
                 LET voteGranted=={m\in messages:/\m.mtype=RequestVoteResponse
                                            /\m.mdest=i
                                            /\m.msource\in P
                                            /\m.mterm=currentTerm[i]
                                            /\m.mvoteGranted=TRUE}
                   allLog==UNION {m.mlog:m\in voteGranted}
                   endLine==LET allPoint=={m.mend:m\in voteResponded}
                              IN e==CHOOSE e1\in allPoint:
                                            (\A e2\in allPoint:e1[1]\geq e2[1])
                   toRecover=={n\in 0..endLine:log[i][n].committed=FALSE}
                   toSync=={〈〈n,Merge({l[2]:l\in {t\in allLog:t[1]=n}},sync[i],currentTerm[i])〉〉
                          :n\in toRecover}
                 IN
                   /\\A p\in P:\E m\in voteGranted:m.msource=p
                   /\log′=[log EXCEPT ![i]=[n\in Index6IF n\in toRecover THEN
                                                   (CHOOSE e\in toSync:e[1]=n)[2]
                                                      ELSE log[i][n]]]
                   /\end′=[end EXCEPT ![i][sync[i]]=〈〈currentTerm[i],end〉〉]
               /\currentState′=[currentState EXCEPT ![i]=LeaderCandidate]
               /\syncTrack′=[syncTrack EXCEPT ![i]=[j\in Server6sync[i]]]
               /\UNCHANGED 〈〈messages,currentTerm,votedFor,sync,elections〉〉
             -------------------------------------------------------------------------------------------------------------------
             •   RequestSync(i):当 i 为主节点或主节点候选者时,对其他每个节点 p,i 向 p 发送任期为 syncTrack[i][p]的
                日志项.这些日志项可以乱序地发送和接受;
             •   HandleRequestSyncRequest(i):节点 i 收到同步请求 m.当 m.msync<sync[i]或 m.msync>sync[i]时,i 拒绝请
                求并回复 RequestSyncResponse 消息,将 sync[i]告知发送者.当 m.msync=sync[i]时,i 同意请求,回复确认,
                并根据 m.mend(可以接受的任期为 m.msync 的日志项的最大编号)和 m.mentries(任期为 m.msync 的日
                志项)修改 end[i]和 log[i].对日志的修改为:删除日志中所有编号大于 m.mend 的日志项,并将编号不超
                过 m.mend 的日志项替换为 m.mentries 中相应的项.
             -----------------------------------------------------------------------------
             RequestSync(i)==
               /\currentState[i]\in {LeaderCandidate,Leader}
               /\\E s\in 0..sync[i]:
                 LET start==Min({n\in Index:log[i][n].term=s})
                    end==Max({n\in Index:log[i][n].term=s})
   189   190   191   192   193   194   195   196   197   198   199