void Learner :: OnSendLearnValue_Ack(const PaxosMsg & oPaxosMsg) { BP->GetLearnerBP()->OnSendLearnValue_Ack(); PLGHead("Msg.Ack.Instanceid %lu Msg.from_nodeid %lu", oPaxosMsg.instanceid(), oPaxosMsg.nodeid()); m_oLearnerSender.Ack(oPaxosMsg.instanceid(), oPaxosMsg.nodeid()); }
void Learner :: OnSendNowInstanceID(const PaxosMsg & oPaxosMsg) { BP->GetLearnerBP()->OnSendNowInstanceID(); PLGHead("START Msg.InstanceID %lu Now.InstanceID %lu Msg.from_nodeid %lu Msg.MaxInstanceID %lu systemvariables_size %zu mastervariables_size %zu", oPaxosMsg.instanceid(), GetInstanceID(), oPaxosMsg.nodeid(), oPaxosMsg.nowinstanceid(), oPaxosMsg.systemvariables().size(), oPaxosMsg.mastervariables().size()); SetSeenInstanceID(oPaxosMsg.nowinstanceid(), oPaxosMsg.nodeid()); bool bSystemVariablesChange = false; int ret = m_poConfig->GetSystemVSM()->UpdateByCheckpoint(oPaxosMsg.systemvariables(), bSystemVariablesChange); if (ret == 0 && bSystemVariablesChange) { PLGHead("SystemVariables changed!, all thing need to reflesh, so skip this msg"); return; } bool bMasterVariablesChange = false; if (m_poConfig->GetMasterSM() != nullptr) { ret = m_poConfig->GetMasterSM()->UpdateByCheckpoint(oPaxosMsg.mastervariables(), bMasterVariablesChange); if (ret == 0 && bMasterVariablesChange) { PLGHead("MasterVariables changed!"); } } if (oPaxosMsg.instanceid() != GetInstanceID()) { PLGErr("Lag msg, skip"); return; } if (oPaxosMsg.nowinstanceid() <= GetInstanceID()) { PLGErr("Lag msg, skip"); return; } if (oPaxosMsg.minchoseninstanceid() > GetInstanceID()) { BP->GetCheckpointBP()->NeedAskforCheckpoint(); PLGHead("my instanceid %lu small than other's minchoseninstanceid %lu, other nodeid %lu", GetInstanceID(), oPaxosMsg.minchoseninstanceid(), oPaxosMsg.nodeid()); AskforCheckpoint(oPaxosMsg.nodeid()); } else if (!m_bIsIMLearning) { ComfirmAskForLearn(oPaxosMsg.nodeid()); } }
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 :: OnComfirmAskForLearn(const PaxosMsg & oPaxosMsg) { BP->GetLearnerBP()->OnComfirmAskForLearn(); PLGHead("START Msg.InstanceID %lu Msg.from_nodeid %lu", oPaxosMsg.instanceid(), oPaxosMsg.nodeid()); if (!m_oLearnerSender.Comfirm(oPaxosMsg.instanceid(), oPaxosMsg.nodeid())) { BP->GetLearnerBP()->OnComfirmAskForLearnGetLockFail(); PLGErr("LearnerSender comfirm fail, maybe is lag msg"); return; } PLGImp("OK, success comfirm"); }
void Learner :: OnAskforLearn(const PaxosMsg & oPaxosMsg) { BP->GetLearnerBP()->OnAskforLearn(); PLGHead("START Msg.InstanceID %lu Now.InstanceID %lu Msg.from_nodeid %lu MinChosenInstanceID %lu", oPaxosMsg.instanceid(), GetInstanceID(), oPaxosMsg.nodeid(), m_poCheckpointMgr->GetMinChosenInstanceID()); SetSeenInstanceID(oPaxosMsg.instanceid(), oPaxosMsg.nodeid()); if (oPaxosMsg.proposalnodeid() == m_poConfig->GetMyNodeID()) { //Found a node follow me. PLImp("Found a node %lu follow me.", oPaxosMsg.nodeid()); m_poConfig->AddFollowerNode(oPaxosMsg.nodeid()); } if (oPaxosMsg.instanceid() >= GetInstanceID()) { return; } if (oPaxosMsg.instanceid() >= m_poCheckpointMgr->GetMinChosenInstanceID()) { if (!m_oLearnerSender.Prepare(oPaxosMsg.instanceid(), oPaxosMsg.nodeid())) { BP->GetLearnerBP()->OnAskforLearnGetLockFail(); PLGErr("LearnerSender working for others."); if (oPaxosMsg.instanceid() == (GetInstanceID() - 1)) { PLGImp("InstanceID only difference one, just send this value to other."); //send one value AcceptorStateData oState; int ret = m_oPaxosLog.ReadState(m_poConfig->GetMyGroupIdx(), oPaxosMsg.instanceid(), oState); if (ret == 0) { BallotNumber oBallot(oState.acceptedid(), oState.acceptednodeid()); SendLearnValue(oPaxosMsg.nodeid(), oPaxosMsg.instanceid(), oBallot, oState.acceptedvalue(), 0); } } return; } } SendNowInstanceID(oPaxosMsg.instanceid(), oPaxosMsg.nodeid()); }
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()); } }
void Learner :: AskforLearn() { BP->GetLearnerBP()->AskforLearn(); PLGHead("START"); PaxosMsg oPaxosMsg; oPaxosMsg.set_instanceid(GetInstanceID()); oPaxosMsg.set_nodeid(m_poConfig->GetMyNodeID()); oPaxosMsg.set_msgtype(MsgType_PaxosLearner_AskforLearn); if (m_poConfig->IsIMFollower()) { //this is not proposal nodeid, just use this val to bring followto nodeid info. oPaxosMsg.set_proposalnodeid(m_poConfig->GetFollowToNodeID()); } PLGHead("END InstanceID %lu MyNodeID %lu", oPaxosMsg.instanceid(), oPaxosMsg.nodeid()); BroadcastMessage(oPaxosMsg, BroadcastMessage_Type_RunSelf_None, Message_SendType_TCP); BroadcastMessageToTempNode(oPaxosMsg, Message_SendType_UDP); }