void Proposer :: Accept() { PLGHead("START ProposalID %lu ValueSize %zu ValueLen %zu", m_oProposerState.GetProposalID(), m_oProposerState.GetValue().size(), m_oProposerState.GetValue().size()); BP->GetProposerBP()->Accept(); m_oTimeStat.Point(); ExitPrepare(); m_bIsAccepting = true; PaxosMsg oPaxosMsg; oPaxosMsg.set_msgtype(MsgType_PaxosAccept); oPaxosMsg.set_instanceid(GetInstanceID()); oPaxosMsg.set_nodeid(m_poConfig->GetMyNodeID()); oPaxosMsg.set_proposalid(m_oProposerState.GetProposalID()); oPaxosMsg.set_value(m_oProposerState.GetValue()); oPaxosMsg.set_lastchecksum(GetLastChecksum()); m_oMsgCounter.StartNewRound(); AddAcceptTimer(); PLGHead("END"); BroadcastMessage(oPaxosMsg, BroadcastMessage_Type_RunSelf_Final); }
void Learner :: ProposerSendSuccess( const uint64_t llLearnInstanceID, const uint64_t llProposalID) { BP->GetLearnerBP()->ProposerSendSuccess(); PaxosMsg oPaxosMsg; oPaxosMsg.set_msgtype(MsgType_PaxosLearner_ProposerSendSuccess); oPaxosMsg.set_instanceid(llLearnInstanceID); oPaxosMsg.set_nodeid(m_poConfig->GetMyNodeID()); oPaxosMsg.set_proposalid(llProposalID); oPaxosMsg.set_lastchecksum(GetLastChecksum()); //run self first BroadcastMessage(oPaxosMsg, BroadcastMessage_Type_RunSelf_First); }
void Learner :: TransmitToFollower() { if (m_poConfig->GetMyFollowerCount() == 0) { return; } PaxosMsg oPaxosMsg; oPaxosMsg.set_msgtype(MsgType_PaxosLearner_SendLearnValue); oPaxosMsg.set_instanceid(GetInstanceID()); oPaxosMsg.set_nodeid(m_poConfig->GetMyNodeID()); oPaxosMsg.set_proposalnodeid(m_poAcceptor->GetAcceptorState()->GetAcceptedBallot().m_llNodeID); oPaxosMsg.set_proposalid(m_poAcceptor->GetAcceptorState()->GetAcceptedBallot().m_llProposalID); oPaxosMsg.set_value(m_poAcceptor->GetAcceptorState()->GetAcceptedValue()); oPaxosMsg.set_lastchecksum(GetLastChecksum()); BroadcastMessageToFollower(oPaxosMsg, Message_SendType_TCP); PLGHead("ok"); }
void Learner :: OnSendLearnValue(const PaxosMsg & oPaxosMsg) { BP->GetLearnerBP()->OnSendLearnValue(); PLGHead("START Msg.InstanceID %lu Now.InstanceID %lu Msg.ballot_proposalid %lu Msg.ballot_nodeid %lu Msg.ValueSize %zu", oPaxosMsg.instanceid(), GetInstanceID(), oPaxosMsg.proposalid(), oPaxosMsg.nodeid(), oPaxosMsg.value().size()); if (oPaxosMsg.instanceid() > GetInstanceID()) { PLGDebug("[Latest Msg] i can't learn"); return; } else if (oPaxosMsg.instanceid() < GetInstanceID()) { PLGDebug("[Lag Msg] no need to learn"); return; } //learn value BallotNumber oBallot(oPaxosMsg.proposalid(), oPaxosMsg.proposalnodeid()); int ret = m_oLearnerState.LearnValue(oPaxosMsg.instanceid(), oBallot, oPaxosMsg.value(), GetLastChecksum()); if (ret != 0) { PLGErr("LearnState.LearnValue fail, ret %d", ret); return; } PLGHead("END LearnValue OK, proposalid %lu proposalid_nodeid %lu valueLen %zu", oPaxosMsg.proposalid(), oPaxosMsg.nodeid(), oPaxosMsg.value().size()); if (oPaxosMsg.flag() == PaxosMsgFlagType_SendLearnValue_NeedAck) { //every time' when receive valid need ack learn value, reset noop timeout. Reset_AskforLearn_Noop(); SendLearnValue_Ack(oPaxosMsg.nodeid()); } }