add syncNodeIsIndexInSnapshot syncNodeGetLastIndexTerm syncNodeGetPreIndexTerm
This commit is contained in:
parent
79ae770a0b
commit
6be4119fe7
|
@ -220,7 +220,7 @@ void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId);
|
||||||
void syncNodeVoteForSelf(SSyncNode* pSyncNode);
|
void syncNodeVoteForSelf(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
// snapshot --------------
|
// snapshot --------------
|
||||||
bool syncNodeIsInSnapshot(SSyncNode* pSyncNode, SyncIndex index);
|
bool syncNodeIsIndexInSnapshot(SSyncNode* pSyncNode, SyncIndex index);
|
||||||
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm);
|
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm);
|
||||||
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm);
|
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm);
|
||||||
|
|
||||||
|
|
|
@ -1201,11 +1201,47 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// snapshot --------------
|
// snapshot --------------
|
||||||
bool syncNodeIsInSnapshot(SSyncNode* pSyncNode, SyncIndex index) { return true; }
|
bool syncNodeIsIndexInSnapshot(SSyncNode* pSyncNode, SyncIndex index) {
|
||||||
|
SSnapshot snapshot;
|
||||||
|
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
||||||
|
bool b = index <= snapshot.lastApplyIndex;
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm) { return 0; }
|
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm) {
|
||||||
|
SyncIndex logLastIndex = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore);
|
||||||
|
SSnapshot snapshot;
|
||||||
|
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
||||||
|
SyncIndex snapshotLastIndex = snapshot.lastApplyIndex;
|
||||||
|
|
||||||
|
if (logLastIndex > snapshotLastIndex) {
|
||||||
|
*pLastIndex = logLastIndex;
|
||||||
|
*pLastTerm = pSyncNode->pLogStore->getLastTerm(pSyncNode->pLogStore);
|
||||||
|
} else {
|
||||||
|
*pLastIndex = snapshotLastIndex;
|
||||||
|
*pLastTerm = snapshot.lastApplyTerm;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
|
SyncIndex preIndex = index - 1;
|
||||||
|
if (syncNodeIsIndexInSnapshot(pSyncNode, preIndex)) {
|
||||||
|
SSnapshot snapshot;
|
||||||
|
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
|
||||||
|
ASSERT(preIndex == snapshot.lastApplyIndex);
|
||||||
|
*pPreIndex = snapshot.lastApplyIndex;
|
||||||
|
*pPreTerm = snapshot.lastApplyTerm;
|
||||||
|
} else {
|
||||||
|
SSyncRaftEntry *pPreEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, preIndex);
|
||||||
|
ASSERT(pPreEntry != NULL);
|
||||||
|
*pPreIndex = pPreEntry->index;
|
||||||
|
*pPreTerm = pPreEntry->term;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue