refactor(sync): optimize leader transfer
This commit is contained in:
parent
1167c86b34
commit
788a103132
|
@ -436,8 +436,15 @@ int32_t syncNodeLeaderTransfer(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER && pSyncNode->replicaNum > 1) {
|
||||||
SNodeInfo newLeader = (pSyncNode->peersNodeInfo)[0];
|
SNodeInfo newLeader = (pSyncNode->peersNodeInfo)[0];
|
||||||
|
if (pSyncNode->peersNum == 2) {
|
||||||
|
SyncIndex matchIndex0 = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId[0]));
|
||||||
|
SyncIndex matchIndex1 = syncIndexMgrGetIndex(pSyncNode->pMatchIndex, &(pSyncNode->peersId[1]));
|
||||||
|
if (matchIndex1 > matchIndex0) {
|
||||||
|
newLeader = (pSyncNode->peersNodeInfo)[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
ret = syncNodeLeaderTransferTo(pSyncNode, newLeader);
|
ret = syncNodeLeaderTransferTo(pSyncNode, newLeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue