提交 6be4119f 编写于 作者: M Minghao Li

add syncNodeIsIndexInSnapshot syncNodeGetLastIndexTerm syncNodeGetPreIndexTerm

上级 79ae770a
......@@ -220,7 +220,7 @@ void syncNodeVoteForTerm(SSyncNode* pSyncNode, SyncTerm term, SRaftId* pRaftId);
void syncNodeVoteForSelf(SSyncNode* pSyncNode);
// snapshot --------------
bool syncNodeIsInSnapshot(SSyncNode* pSyncNode, SyncIndex index);
bool syncNodeIsIndexInSnapshot(SSyncNode* pSyncNode, SyncIndex index);
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm);
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm);
......
......@@ -1201,11 +1201,47 @@ void syncNodeVoteForSelf(SSyncNode* pSyncNode) {
}
// 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) {
SyncIndex logLastIndex = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore);
SSnapshot snapshot;
pSyncNode->pFsm->FpGetSnapshot(pSyncNode->pFsm, &snapshot);
SyncIndex snapshotLastIndex = snapshot.lastApplyIndex;
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm) { return 0; }
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) {
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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册