コード例 #1
0
ファイル: learner.cpp プロジェクト: BLiYing/phxpaxos
int Learner :: SendLearnValue(
        const nodeid_t iSendNodeID,
        const uint64_t llLearnInstanceID,
        const BallotNumber & oLearnedBallot,
        const std::string & sLearnedValue,
        const uint32_t iChecksum,
        const bool bNeedAck)
{
    BP->GetLearnerBP()->SendLearnValue();

    PaxosMsg oPaxosMsg;
    
    oPaxosMsg.set_msgtype(MsgType_PaxosLearner_SendLearnValue);
    oPaxosMsg.set_instanceid(llLearnInstanceID);
    oPaxosMsg.set_nodeid(m_poConfig->GetMyNodeID());
    oPaxosMsg.set_proposalnodeid(oLearnedBallot.m_llNodeID);
    oPaxosMsg.set_proposalid(oLearnedBallot.m_llProposalID);
    oPaxosMsg.set_value(sLearnedValue);
    oPaxosMsg.set_lastchecksum(iChecksum);
    if (bNeedAck)
    {
        oPaxosMsg.set_flag(PaxosMsgFlagType_SendLearnValue_NeedAck);
    }

    return SendMessage(iSendNodeID, oPaxosMsg, Message_SendType_TCP);
}
コード例 #2
0
ファイル: proposer.cpp プロジェクト: chaozh/phxpaxos
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);
}
コード例 #3
0
ファイル: proposer.cpp プロジェクト: chaozh/phxpaxos
void Proposer :: Prepare(const bool bNeedNewBallot)
{
    PLGHead("START Now.InstanceID %lu MyNodeID %lu State.ProposalID %lu State.ValueLen %zu",
            GetInstanceID(), m_poConfig->GetMyNodeID(), m_oProposerState.GetProposalID(),
            m_oProposerState.GetValue().size());

    BP->GetProposerBP()->Prepare();
    m_oTimeStat.Point();
    
    ExitAccept();
    m_bIsPreparing = true;
    m_bCanSkipPrepare = false;
    m_bWasRejectBySomeone = false;

    m_oProposerState.ResetHighestOtherPreAcceptBallot();
    if (bNeedNewBallot)
    {
        m_oProposerState.NewPrepare();
    }

    PaxosMsg oPaxosMsg;
    oPaxosMsg.set_msgtype(MsgType_PaxosPrepare);
    oPaxosMsg.set_instanceid(GetInstanceID());
    oPaxosMsg.set_nodeid(m_poConfig->GetMyNodeID());
    oPaxosMsg.set_proposalid(m_oProposerState.GetProposalID());

    m_oMsgCounter.StartNewRound();

    AddPrepareTimer();

    PLGHead("END OK");

    BroadcastMessage(oPaxosMsg);
}
コード例 #4
0
ファイル: proposer_ut.cpp プロジェクト: BLiYing/phxpaxos
TEST(Proposer, OnAcceptReply_Reject)
{
    ProposerBuilder ob;

    MockProposerBP & oProposerBP = ob.oMockBreakpoint.m_oMockProposerBP;

    ob.poProposer->m_oProposerState.m_llProposalID = 100;
    ob.poProposer->m_bIsAccepting = true;
    ob.poProposer->m_oProposerState.m_sValue = "abc";
    PaxosMsg oPaxosMsg;
    oPaxosMsg.set_proposalid(100);

    //first call
    oPaxosMsg.set_rejectbypromiseid(101);
    oPaxosMsg.set_nodeid(2);
    ob.poProposer->OnAcceptReply(oPaxosMsg);

    EXPECT_TRUE(ob.poProposer->m_bWasRejectBySomeone == true);

    //second call
    oPaxosMsg.set_rejectbypromiseid(0);
    oPaxosMsg.set_nodeid(GetMyNode().GetNodeID());
    ob.poProposer->OnAcceptReply(oPaxosMsg);

    //third call
    oPaxosMsg.set_rejectbypromiseid(102);
    oPaxosMsg.set_nodeid(3);

    EXPECT_CALL(oProposerBP, AcceptNotPass()).Times(1);

    ob.poProposer->OnAcceptReply(oPaxosMsg);

    EXPECT_TRUE(ob.poProposer->m_bCanSkipPrepare == false);
    EXPECT_TRUE(ob.poProposer->m_oProposerState.m_sValue == "abc");
}
コード例 #5
0
ファイル: learner.cpp プロジェクト: BLiYing/phxpaxos
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);
}
コード例 #6
0
ファイル: proposer_ut.cpp プロジェクト: BLiYing/phxpaxos
TEST(Proposer, OnAcceptReply_Skip)
{
    ProposerBuilder ob;

    MockProposerBP & oProposerBP = ob.oMockBreakpoint.m_oMockProposerBP;

    ob.poProposer->m_oProposerState.m_llProposalID = 100;
    PaxosMsg oPaxosMsg;

    //first call
    EXPECT_CALL(oProposerBP, OnAcceptReplyButNotAccepting()).Times(1);
    ob.poProposer->m_bIsAccepting = false;
    ob.poProposer->OnAcceptReply(oPaxosMsg);

    //second call
    EXPECT_CALL(oProposerBP, OnAcceptReplyNotSameProposalIDMsg()).Times(1);
    oPaxosMsg.set_proposalid(102);
    ob.poProposer->m_bIsAccepting = true;
    ob.poProposer->OnAcceptReply(oPaxosMsg);
}
コード例 #7
0
ファイル: proposer_ut.cpp プロジェクト: BLiYing/phxpaxos
TEST(Proposer, OnPrepareReply_Pass)
{
    ProposerBuilder ob;

    MockProposerBP & oProposerBP = ob.oMockBreakpoint.m_oMockProposerBP;

    ob.poProposer->m_oProposerState.m_llProposalID = 100;
    ob.poProposer->m_bIsPreparing = true;
    ob.poProposer->m_oProposerState.m_sValue = "abc";
    PaxosMsg oPaxosMsg;
    oPaxosMsg.set_proposalid(100);

    //first call
    oPaxosMsg.set_preacceptid(95);
    oPaxosMsg.set_preacceptnodeid(GetMyNode().GetNodeID());
    oPaxosMsg.set_nodeid(GetMyNode().GetNodeID());
    oPaxosMsg.set_value("hello paxos");
    ob.poProposer->OnPrepareReply(oPaxosMsg);

    EXPECT_TRUE(ob.poProposer->m_oProposerState.m_sValue == "hello paxos");

    //second call
    oPaxosMsg.set_rejectbypromiseid(101);
    oPaxosMsg.set_nodeid(2);
    ob.poProposer->OnPrepareReply(oPaxosMsg);

    //third call
    oPaxosMsg.set_rejectbypromiseid(0);
    oPaxosMsg.set_preacceptid(98);
    oPaxosMsg.set_preacceptnodeid(3);
    oPaxosMsg.set_nodeid(3);
    oPaxosMsg.set_value("hello world");

    EXPECT_CALL(oProposerBP, PreparePass(_)).Times(1);

    ob.poProposer->OnPrepareReply(oPaxosMsg);

    EXPECT_TRUE(ob.poProposer->m_bCanSkipPrepare == true);
    EXPECT_TRUE(ob.poProposer->m_bIsAccepting == true);
    EXPECT_TRUE(ob.poProposer->m_oProposerState.m_sValue == "hello world");
}
コード例 #8
0
ファイル: learner.cpp プロジェクト: BLiYing/phxpaxos
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");
}