提交 44a893a1 编写于 作者: M Minghao Li

fix(sync): snapshot maybe change when sending

上级 a56f149a
...@@ -165,29 +165,33 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries ...@@ -165,29 +165,33 @@ int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntries
// has snapshot // has snapshot
if (syncNodeHasSnapshot(ths)) { if (syncNodeHasSnapshot(ths)) {
SSnapshot snapshot; // get sender
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot); SSyncSnapshotSender* pSender = NULL;
if (nextIndex <= snapshot.lastApplyIndex) { for (int i = 0; i < ths->replicaNum; ++i) {
// ASSERT(nextIndex == snapshot.lastApplyIndex); if (syncUtilSameId(&(pMsg->srcId), &((ths->replicasId)[i]))) {
pSender = (ths->senders)[i];
}
}
ASSERT(pSender != NULL);
nextIndex = snapshot.lastApplyIndex + 1; // calculate sentryIndex
sInfo("reset new nextIndex %ld, snapshot.lastApplyIndex:%ld", nextIndex, snapshot.lastApplyIndex); SyncIndex sentryIndex;
if (pSender->start) {
sentryIndex = pSender->snapshot.lastApplyIndex;
} else {
// start send snapshot // start send snapshot
// get sender
SSyncSnapshotSender* pSender = NULL;
for (int i = 0; i < ths->replicaNum; ++i) {
if (syncUtilSameId(&(pMsg->srcId), &((ths->replicasId)[i]))) {
pSender = (ths->senders)[i];
}
}
ASSERT(pSender != NULL);
if (!(pSender->term == ths->pRaftStore->currentTerm && pSender->finish == true)) { if (!(pSender->term == ths->pRaftStore->currentTerm && pSender->finish == true)) {
snapshotSenderStart(pSender); snapshotSenderStart(pSender);
} else { } else {
sInfo("snapshot send finish, send_term:%lu, current_term:%lu", pSender->term, ths->pRaftStore->currentTerm); sInfo("snapshot send finish, send_term:%lu, current_term:%lu", pSender->term, ths->pRaftStore->currentTerm);
} }
sentryIndex = pSender->snapshot.lastApplyIndex;
}
// update nextIndex to sentryIndex + 1
if (nextIndex <= sentryIndex) {
nextIndex = sentryIndex + 1;
} }
} }
......
...@@ -1693,6 +1693,7 @@ const char* syncStr(ESyncState state) { ...@@ -1693,6 +1693,7 @@ const char* syncStr(ESyncState state) {
int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag) { int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag) {
int32_t code = 0; int32_t code = 0;
sInfo("sync commit from %ld to %ld, flag:0x%lX", beginIndex, endIndex, flag);
// maybe execute by leader, skip snapshot // maybe execute by leader, skip snapshot
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0}; SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册