From 84a67e850e9ed2cfe9d1713191f40973210d0ef7 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Mon, 6 Jun 2022 17:23:59 +0800 Subject: [PATCH] fix(sync): sending snapshot --- include/libs/sync/sync.h | 1 + source/libs/sync/src/syncAppendEntries.c | 5 ++++- source/libs/sync/src/syncRaftLog.c | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 9a6d42e5bd..8f83e21ce4 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -91,6 +91,7 @@ typedef struct SSnapshot { void* data; SyncIndex lastApplyIndex; SyncTerm lastApplyTerm; + SyncIndex lastConfigIndex; } SSnapshot; typedef struct SSyncFSM { diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 0683e1d975..97600c3f15 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -438,9 +438,12 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries return true; } - SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); SyncIndex myLastIndex = syncNodeGetLastIndex(pSyncNode); + if (pMsg->prevLogIndex > myLastIndex) { + return false; + } + SyncTerm myPreLogTerm = syncNodeGetPreTerm(pSyncNode, pMsg->prevLogIndex + 1); if (pMsg->prevLogIndex <= myLastIndex && pMsg->prevLogTerm == myPreLogTerm) { return true; } diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index b021c3bf59..95f5926a6f 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -198,7 +198,7 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, } else { // index not in range - code = -2; + code = 0; } return code; -- GitLab