/**************************************************************************** Function StartMaster Parameters ES_Event CurrentEvent Returns nothing Description Does any required initialization for this state machine ****************************************************************************/ void StartMaster ( ES_Event CurrentEvent ) { // local variable to get debugger to display the value of CurrentEvent volatile ES_Event LocalEvent = CurrentEvent; // there is only 1 state to the top level machine so no need for a state // variable. All we need to do is to let the Run function init the lower level // state machines // use LocalEvent to keep the compiler from complaining about unused var RunMaster(LocalEvent); return; }
int PNode :: Init(const Options & oOptions, NetWork *& poNetWork) { int ret = CheckOptions(oOptions); if (ret != 0) { PLErr("CheckOptions fail, ret %d", ret); return ret; } m_iMyNodeID = oOptions.oMyNode.GetNodeID(); //step1 init logstorage LogStorage * poLogStorage = nullptr; ret = InitLogStorage(oOptions, poLogStorage); if (ret != 0) { return ret; } //step2 init network ret = InitNetWork(oOptions, poNetWork); if (ret != 0) { return ret; } //step3 build masterlist for (int iGroupIdx = 0; iGroupIdx < oOptions.iGroupCount; iGroupIdx++) { MasterMgr * poMaster = new MasterMgr(this, iGroupIdx, poLogStorage, oOptions.pMasterChangeCallback); assert(poMaster != nullptr); m_vecMasterList.push_back(poMaster); ret = poMaster->Init(); if (ret != 0) { return ret; } } //step4 build grouplist for (int iGroupIdx = 0; iGroupIdx < oOptions.iGroupCount; iGroupIdx++) { Group * poGroup = new Group(poLogStorage, poNetWork, m_vecMasterList[iGroupIdx]->GetMasterSM(), iGroupIdx, oOptions); assert(poGroup != nullptr); m_vecGroupList.push_back(poGroup); } //step5 build batchpropose if (oOptions.bUseBatchPropose) { for (int iGroupIdx = 0; iGroupIdx < oOptions.iGroupCount; iGroupIdx++) { ProposeBatch * poProposeBatch = new ProposeBatch(iGroupIdx, this, &m_oNotifierPool); assert(poProposeBatch != nullptr); m_vecProposeBatch.push_back(poProposeBatch); } } //step6 init statemachine InitStateMachine(oOptions); //step7 parallel init group for (auto & poGroup : m_vecGroupList) { poGroup->StartInit(); } for (auto & poGroup : m_vecGroupList) { int initret = poGroup->GetInitRet(); if (initret != 0) { ret = initret; } } if (ret != 0) { return ret; } //last step. must init ok, then should start threads. //because that stop threads is slower, if init fail, we need much time to stop many threads. //so we put start threads in the last step. for (auto & poGroup : m_vecGroupList) { //start group's thread first. poGroup->Start(); } RunMaster(oOptions); RunProposeBatch(); PLHead("OK"); return 0; }