diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 9a6d42e5bda5016fc416c115940d3c3012cca548..8f83e21ce4ee845c49084e86838a3a35c95d7592 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 0683e1d97576066dd69e28ee9adb324bb9cd9ad0..97600c3f15e4caf21c7b8356dd97d98e86effde4 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 b021c3bf590b6df8374bf47a8f1dc5f49f4eb255..95f5926a6f8ae2dd7945fa10a1744686e6c0059d 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;