示例#1
0
void MasterStateMachine :: BeforePropose(const int iGroupIdx, std::string & sValue)
{
    std::lock_guard<std::mutex> oLockGuard(m_oMutex);
    MasterOperator oMasterOper;
    bool bSucc = oMasterOper.ParseFromArray(sValue.data(), sValue.size());
    if (!bSucc)
    {
        return;
    }

    oMasterOper.set_lastversion(m_llMasterVersion);
    sValue.clear();
    bSucc = oMasterOper.SerializeToString(&sValue);
    assert(bSucc == true);
} 
示例#2
0
bool MasterStateMachine :: Execute(const int iGroupIdx, const uint64_t llInstanceID, 
        const std::string & sValue, SMCtx * poSMCtx)
{
    MasterOperator oMasterOper;
    bool bSucc = oMasterOper.ParseFromArray(sValue.data(), sValue.size());
    if (!bSucc)
    {
        PLG1Err("oMasterOper data wrong");
        //wrong oper data, just skip, so return true
        return true;
    }

    if (oMasterOper.operator_() == MasterOperatorType_Complete)
    {
        uint64_t * pAbsMasterTimeout = nullptr;
        if (poSMCtx != nullptr && poSMCtx->m_pCtx != nullptr)
        {
            pAbsMasterTimeout = (uint64_t *)poSMCtx->m_pCtx;
        }

        uint64_t llAbsMasterTimeout = pAbsMasterTimeout != nullptr ? *pAbsMasterTimeout : 0;

        PLG1Imp("absmaster timeout %lu", llAbsMasterTimeout);

        int ret = LearnMaster(llInstanceID, oMasterOper, llAbsMasterTimeout);
        if (ret != 0)
        {
            return false;
        }
    }
    else
    {
        PLG1Err("unknown op %u", oMasterOper.operator_());
        //wrong op, just skip, so return true;
        return true;
    }

    return true;
}