fix: become leader if replica num is 1
This commit is contained in:
parent
a609f0efb5
commit
f76261dcb5
|
@ -603,22 +603,27 @@ static int32_t mndCheckMnodeState(SRpcMsg *pMsg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (mndAcquireRpc(pMsg->info.node) == 0) return 0;
|
if (mndAcquireRpc(pMsg->info.node) == 0) return 0;
|
||||||
|
|
||||||
|
SMnode *pMnode = pMsg->info.node;
|
||||||
|
const char *role = syncGetMyRoleStr(pMnode->syncMgmt.sync);
|
||||||
|
bool restored = syncIsRestoreFinish(pMnode->syncMgmt.sync);
|
||||||
if (pMsg->msgType == TDMT_MND_MQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER ||
|
if (pMsg->msgType == TDMT_MND_MQ_TIMER || pMsg->msgType == TDMT_MND_TELEM_TIMER ||
|
||||||
pMsg->msgType == TDMT_MND_TRANS_TIMER || pMsg->msgType == TDMT_MND_TTL_TIMER ||
|
pMsg->msgType == TDMT_MND_TRANS_TIMER || pMsg->msgType == TDMT_MND_TTL_TIMER ||
|
||||||
pMsg->msgType == TDMT_MND_UPTIME_TIMER) {
|
pMsg->msgType == TDMT_MND_UPTIME_TIMER) {
|
||||||
|
mTrace("timer not process since mnode restored:%d stopped:%d, sync restored:%d role:%s ", pMnode->restored,
|
||||||
|
pMnode->stopped, restored, role);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
SEpSet epSet = {0};
|
SEpSet epSet = {0};
|
||||||
SMnode *pMnode = pMsg->info.node;
|
|
||||||
mndGetMnodeEpSet(pMnode, &epSet);
|
mndGetMnodeEpSet(pMnode, &epSet);
|
||||||
|
|
||||||
const STraceId *trace = &pMsg->info.traceId;
|
|
||||||
mDebug(
|
mDebug(
|
||||||
"msg:%p, failed to check mnode state since %s, mnode restored:%d stopped:%d, sync restored:%d role:%s type:%s "
|
"msg:%p, type:%s failed to process since %s, mnode restored:%d stopped:%d, sync restored:%d "
|
||||||
"numOfEps:%d inUse:%d",
|
"role:%s, redirect numOfEps:%d inUse:%d",
|
||||||
pMsg, terrstr(), pMnode->restored, pMnode->stopped, syncIsRestoreFinish(pMnode->syncMgmt.sync),
|
pMsg, TMSG_INFO(pMsg->msgType), terrstr(), pMnode->restored, pMnode->stopped, restored, role, epSet.numOfEps,
|
||||||
syncGetMyRoleStr(pMnode->syncMgmt.sync), TMSG_INFO(pMsg->msgType), epSet.numOfEps, epSet.inUse);
|
epSet.inUse);
|
||||||
|
|
||||||
if (epSet.numOfEps > 0) {
|
if (epSet.numOfEps > 0) {
|
||||||
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
for (int32_t i = 0; i < epSet.numOfEps; ++i) {
|
||||||
|
|
|
@ -747,7 +747,13 @@ static void mndReloadSyncConfig(SMnode *pMnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cfg.myIndex == -1) {
|
if (cfg.myIndex == -1) {
|
||||||
|
#if 1
|
||||||
mInfo("vgId:1, mnode sync not reconfig since selfIndex is -1");
|
mInfo("vgId:1, mnode sync not reconfig since selfIndex is -1");
|
||||||
|
#else
|
||||||
|
// cannot reconfig because the leader may fail to elect after reboot
|
||||||
|
mInfo("vgId:1, mnode sync not reconfig since selfIndex is -1, do sync stop oper");
|
||||||
|
syncStop(pMnode->syncMgmt.sync);
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,19 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pSyncNode->replicaNum == 1) {
|
||||||
|
// only myself, to leader
|
||||||
|
voteGrantedUpdate(pSyncNode->pVotesGranted, pSyncNode);
|
||||||
|
votesRespondUpdate(pSyncNode->pVotesRespond, pSyncNode);
|
||||||
|
|
||||||
|
pSyncNode->quorum = syncUtilQuorum(pSyncNode->pRaftCfg->cfg.replicaNum);
|
||||||
|
|
||||||
|
syncNodeCandidate2Leader(pSyncNode);
|
||||||
|
pSyncNode->pVotesGranted->toLeader = true;
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
switch (pSyncNode->pRaftCfg->snapshotStrategy) {
|
switch (pSyncNode->pRaftCfg->snapshotStrategy) {
|
||||||
case SYNC_STRATEGY_NO_SNAPSHOT:
|
case SYNC_STRATEGY_NO_SNAPSHOT:
|
||||||
ret = syncNodeRequestVotePeers(pSyncNode);
|
ret = syncNodeRequestVotePeers(pSyncNode);
|
||||||
|
|
|
@ -2282,7 +2282,7 @@ void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr) {
|
||||||
|
|
||||||
void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
|
void syncNodeCandidate2Leader(SSyncNode* pSyncNode) {
|
||||||
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
|
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
|
||||||
ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted));
|
//ASSERT(voteGrantedMajority(pSyncNode->pVotesGranted));
|
||||||
syncNodeBecomeLeader(pSyncNode, "candidate to leader");
|
syncNodeBecomeLeader(pSyncNode, "candidate to leader");
|
||||||
|
|
||||||
syncNodeLog2("==state change syncNodeCandidate2Leader==", pSyncNode);
|
syncNodeLog2("==state change syncNodeCandidate2Leader==", pSyncNode);
|
||||||
|
|
Loading…
Reference in New Issue