refactor: snapshotReSend
This commit is contained in:
parent
56253aedc9
commit
2e840969c8
|
@ -1253,10 +1253,11 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
||||||
bool syncNodeIsIndexInSnapshot(SSyncNode* pSyncNode, SyncIndex index) {
|
bool syncNodeIsIndexInSnapshot(SSyncNode* pSyncNode, SyncIndex index) {
|
||||||
SSnapshot snapshot;
|
SSnapshot snapshot;
|
||||||
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
||||||
bool b = index <= snapshot.lastApplyIndex;
|
bool b = (index <= snapshot.lastApplyIndex);
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get last index and term along with snapshot
|
||||||
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm) {
|
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm) {
|
||||||
SyncIndex logLastIndex = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore);
|
SyncIndex logLastIndex = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore);
|
||||||
SSnapshot snapshot;
|
SSnapshot snapshot;
|
||||||
|
@ -1266,13 +1267,17 @@ int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, Sy
|
||||||
if (logLastIndex > snapshotLastIndex) {
|
if (logLastIndex > snapshotLastIndex) {
|
||||||
*pLastIndex = logLastIndex;
|
*pLastIndex = logLastIndex;
|
||||||
*pLastTerm = pSyncNode->pLogStore->getLastTerm(pSyncNode->pLogStore);
|
*pLastTerm = pSyncNode->pLogStore->getLastTerm(pSyncNode->pLogStore);
|
||||||
} else {
|
} else if (logLastIndex == snapshotLastIndex) {
|
||||||
*pLastIndex = snapshotLastIndex;
|
*pLastIndex = snapshotLastIndex;
|
||||||
*pLastTerm = snapshot.lastApplyTerm;
|
*pLastTerm = snapshot.lastApplyTerm;
|
||||||
|
} else {
|
||||||
|
ASSERT(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get pre index and term of "index"
|
||||||
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm) {
|
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm) {
|
||||||
ASSERT(index >= SYNC_INDEX_BEGIN);
|
ASSERT(index >= SYNC_INDEX_BEGIN);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
@ -1282,6 +1287,7 @@ int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex
|
||||||
SSnapshot snapshot;
|
SSnapshot snapshot;
|
||||||
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
||||||
ASSERT(preIndex == snapshot.lastApplyIndex);
|
ASSERT(preIndex == snapshot.lastApplyIndex);
|
||||||
|
|
||||||
*pPreIndex = snapshot.lastApplyIndex;
|
*pPreIndex = snapshot.lastApplyIndex;
|
||||||
*pPreTerm = snapshot.lastApplyTerm;
|
*pPreTerm = snapshot.lastApplyTerm;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue