From 4381c3620d424c92150cdb86bae2da4554994fa4 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 21 Jun 2022 19:00:24 +0800 Subject: [PATCH] refactor(sync): calculate index after append entry --- source/libs/sync/src/syncMain.c | 4 ++-- source/libs/sync/src/syncRaftLog.c | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 3a0e6edeee..da6d869611 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -2160,7 +2160,7 @@ static int32_t syncNodeEqNoop(SSyncNode* ths) { int32_t ret = 0; ASSERT(ths->state == TAOS_SYNC_STATE_LEADER); - SyncIndex index = ths->pLogStore->getLastIndex(ths->pLogStore) + 1; + SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore); SyncTerm term = ths->pRaftStore->currentTerm; SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId); ASSERT(pEntry != NULL); @@ -2188,7 +2188,7 @@ static int32_t syncNodeEqNoop(SSyncNode* ths) { static int32_t syncNodeAppendNoop(SSyncNode* ths) { int32_t ret = 0; - SyncIndex index = ths->pLogStore->getLastIndex(ths->pLogStore) + 1; + SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore); SyncTerm term = ths->pRaftStore->currentTerm; SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId); ASSERT(pEntry != NULL); diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index 9a4d47ee85..0f6e8a28d9 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -143,7 +143,10 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr SWal* pWal = pData->pWal; SyncIndex writeIndex = raftLogWriteIndex(pLogStore); - ASSERT(pEntry->index == writeIndex); + if (pEntry->index != writeIndex) { + sError("raftLogAppendEntry error, pEntry->index:%ld update to writeIndex:%ld", pEntry->index, writeIndex); + pEntry->index = writeIndex; + } int code = 0; SSyncLogMeta syncMeta; -- GitLab