From 7ce5fb11b09b51dfa1f1e8e93794e65344185f54 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Fri, 29 Jul 2022 21:05:56 +0800 Subject: [PATCH] refactor(sync): speed up sync point --- source/libs/sync/src/syncAppendEntriesReply.c | 5 +++++ source/libs/sync/src/syncMain.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/libs/sync/src/syncAppendEntriesReply.c b/source/libs/sync/src/syncAppendEntriesReply.c index 81d050e179..bfaa785d0f 100644 --- a/source/libs/sync/src/syncAppendEntriesReply.c +++ b/source/libs/sync/src/syncAppendEntriesReply.c @@ -213,6 +213,11 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie if (nextIndex > SYNC_INDEX_BEGIN) { --nextIndex; + // speed up + if (nextIndex > pMsg->matchIndex + 1) { + nextIndex = pMsg->matchIndex + 1; + } + bool needStartSnapshot = false; if (nextIndex >= SYNC_INDEX_BEGIN && !ths->pLogStore->syncLogExist(ths->pLogStore, nextIndex)) { needStartSnapshot = true; diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 2c64728998..52cbcd0059 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -2222,13 +2222,18 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { SyncIndex preIndex = index - 1; SSyncRaftEntry* pPreEntry = NULL; int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, preIndex, &pPreEntry); + + SSnapshot snapshot = {.data = NULL, + .lastApplyIndex = SYNC_INDEX_INVALID, + .lastApplyTerm = SYNC_TERM_INVALID, + .lastConfigIndex = SYNC_INDEX_INVALID}; + if (code == 0) { ASSERT(pPreEntry != NULL); preTerm = pPreEntry->term; taosMemoryFree(pPreEntry); return preTerm; } else { - SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0, .lastConfigIndex = -1}; if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) { pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot); if (snapshot.lastApplyIndex == preIndex) { @@ -2239,7 +2244,8 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) { do { char logBuf[128]; - snprintf(logBuf, sizeof(logBuf), "sync node get pre term error, index:%" PRId64, index); + snprintf(logBuf, sizeof(logBuf), "sync node get pre term error, index:%ld, snap-index:%ld, snap-term:%lu", index, + snapshot.lastApplyIndex, snapshot.lastApplyTerm); syncNodeErrorLog(pSyncNode, logBuf); } while (0); -- GitLab