void Proposer :: OnPrepareReply(const PaxosMsg & oPaxosMsg) { PLGHead("START Msg.ProposalID %lu State.ProposalID %lu Msg.from_nodeid %lu RejectByPromiseID %lu", oPaxosMsg.proposalid(), m_oProposerState.GetProposalID(), oPaxosMsg.nodeid(), oPaxosMsg.rejectbypromiseid()); BP->GetProposerBP()->OnPrepareReply(); if (!m_bIsPreparing) { BP->GetProposerBP()->OnPrepareReplyButNotPreparing(); //PLGErr("Not preparing, skip this msg"); return; } if (oPaxosMsg.proposalid() != m_oProposerState.GetProposalID()) { BP->GetProposerBP()->OnPrepareReplyNotSameProposalIDMsg(); //PLGErr("ProposalID not same, skip this msg"); return; } m_oMsgCounter.AddReceive(oPaxosMsg.nodeid()); if (oPaxosMsg.rejectbypromiseid() == 0) { BallotNumber oBallot(oPaxosMsg.preacceptid(), oPaxosMsg.preacceptnodeid()); PLGDebug("[Promise] PreAcceptedID %lu PreAcceptedNodeID %lu ValueSize %zu", oPaxosMsg.preacceptid(), oPaxosMsg.preacceptnodeid(), oPaxosMsg.value().size()); m_oMsgCounter.AddPromiseOrAccept(oPaxosMsg.nodeid()); m_oProposerState.AddPreAcceptValue(oBallot, oPaxosMsg.value()); } else { PLGDebug("[Reject] RejectByPromiseID %lu", oPaxosMsg.rejectbypromiseid()); m_oMsgCounter.AddReject(oPaxosMsg.nodeid()); m_bWasRejectBySomeone = true; m_oProposerState.SetOtherProposalID(oPaxosMsg.rejectbypromiseid()); } if (m_oMsgCounter.IsPassedOnThisRound()) { int iUseTimeMs = m_oTimeStat.Point(); BP->GetProposerBP()->PreparePass(iUseTimeMs); PLGImp("[Pass] start accept, usetime %dms", iUseTimeMs); m_bCanSkipPrepare = true; Accept(); } else if (m_oMsgCounter.IsRejectedOnThisRound() || m_oMsgCounter.IsAllReceiveOnThisRound()) { BP->GetProposerBP()->PrepareNotPass(); PLGImp("[Not Pass] wait 30ms and restart prepare"); AddPrepareTimer(OtherUtils::FastRand() % 30 + 10); } PLGHead("END"); }
void Proposer :: OnAcceptReply(const PaxosMsg & oPaxosMsg) { PLGHead("START Msg.ProposalID %lu State.ProposalID %lu Msg.from_nodeid %lu RejectByPromiseID %lu", oPaxosMsg.proposalid(), m_oProposerState.GetProposalID(), oPaxosMsg.nodeid(), oPaxosMsg.rejectbypromiseid()); BP->GetProposerBP()->OnAcceptReply(); if (!m_bIsAccepting) { //PLGErr("Not proposing, skip this msg"); BP->GetProposerBP()->OnAcceptReplyButNotAccepting(); return; } if (oPaxosMsg.proposalid() != m_oProposerState.GetProposalID()) { //PLGErr("ProposalID not same, skip this msg"); BP->GetProposerBP()->OnAcceptReplyNotSameProposalIDMsg(); return; } m_oMsgCounter.AddReceive(oPaxosMsg.nodeid()); if (oPaxosMsg.rejectbypromiseid() == 0) { PLGDebug("[Accept]"); m_oMsgCounter.AddPromiseOrAccept(oPaxosMsg.nodeid()); } else { PLGDebug("[Reject]"); m_oMsgCounter.AddReject(oPaxosMsg.nodeid()); m_bWasRejectBySomeone = true; m_oProposerState.SetOtherProposalID(oPaxosMsg.rejectbypromiseid()); } if (m_oMsgCounter.IsPassedOnThisRound()) { int iUseTimeMs = m_oTimeStat.Point(); BP->GetProposerBP()->AcceptPass(iUseTimeMs); PLGImp("[Pass] Start send learn, usetime %dms", iUseTimeMs); ExitAccept(); m_poLearner->ProposerSendSuccess(GetInstanceID(), m_oProposerState.GetProposalID()); } else if (m_oMsgCounter.IsRejectedOnThisRound() || m_oMsgCounter.IsAllReceiveOnThisRound()) { BP->GetProposerBP()->AcceptNotPass(); PLGImp("[Not pass] wait 30ms and Restart prepare"); AddAcceptTimer(OtherUtils::FastRand() % 30 + 10); } PLGHead("END"); }
void Learner :: OnProposerSendSuccess(const PaxosMsg & oPaxosMsg) { BP->GetLearnerBP()->OnProposerSendSuccess(); PLGHead("START Msg.InstanceID %lu Now.InstanceID %lu Msg.ProposalID %lu State.AcceptedID %lu " "State.AcceptedNodeID %lu, Msg.from_nodeid %lu", oPaxosMsg.instanceid(), GetInstanceID(), oPaxosMsg.proposalid(), m_poAcceptor->GetAcceptorState()->GetAcceptedBallot().m_llProposalID, m_poAcceptor->GetAcceptorState()->GetAcceptedBallot().m_llNodeID, oPaxosMsg.nodeid()); if (oPaxosMsg.instanceid() != GetInstanceID()) { //Instance id not same, that means not in the same instance, ignord. PLGDebug("InstanceID not same, skip msg"); return; } if (m_poAcceptor->GetAcceptorState()->GetAcceptedBallot().isnull()) { //Not accept any yet. BP->GetLearnerBP()->OnProposerSendSuccessNotAcceptYet(); PLGDebug("I haven't accpeted any proposal"); return; } BallotNumber oBallot(oPaxosMsg.proposalid(), oPaxosMsg.nodeid()); if (m_poAcceptor->GetAcceptorState()->GetAcceptedBallot() != oBallot) { //Proposalid not same, this accept value maybe not chosen value. PLGDebug("ProposalBallot not same to AcceptedBallot"); BP->GetLearnerBP()->OnProposerSendSuccessBallotNotSame(); return; } //learn value. m_oLearnerState.LearnValueWithoutWrite( oPaxosMsg.instanceid(), m_poAcceptor->GetAcceptorState()->GetAcceptedValue(), m_poAcceptor->GetAcceptorState()->GetChecksum()); BP->GetLearnerBP()->OnProposerSendSuccessSuccessLearn(); PLGHead("END Learn value OK, value %zu", m_poAcceptor->GetAcceptorState()->GetAcceptedValue().size()); TransmitToFollower(); }
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()); } }