diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 170a57a7a9..80e0cbbf99 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -383,6 +383,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { snprintf(logBuf, sizeof(logBuf), "ignore, truncate error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); + syncEntryDestory(pLocalEntry); + syncEntryDestory(pAppendEntry); goto _IGNORE; } @@ -393,6 +395,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { snprintf(logBuf, sizeof(logBuf), "ignore, append error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); + syncEntryDestory(pLocalEntry); + syncEntryDestory(pAppendEntry); goto _IGNORE; } } @@ -408,6 +412,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, truncate error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); + syncEntryDestory(pLocalEntry); + syncEntryDestory(pAppendEntry); goto _IGNORE; } @@ -418,6 +424,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, append error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); + syncEntryDestory(pLocalEntry); + syncEntryDestory(pAppendEntry); goto _IGNORE; } @@ -427,33 +435,12 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) { snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64, appendIndex); syncLogRecvAppendEntries(ths, pMsg, logBuf); + syncEntryDestory(pLocalEntry); + syncEntryDestory(pAppendEntry); goto _IGNORE; } } -#if 0 - if (code != 0 && terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) { - code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); - ASSERT(code == 0); - - code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); - ASSERT(code == 0); - - } else { - ASSERT(code == 0); - - if (pLocalEntry->term == pAppendEntry->term) { - // do nothing - } else { - code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex); - ASSERT(code == 0); - - code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry); - ASSERT(code == 0); - } - } -#endif - // update match index pReply->matchIndex = pAppendEntry->index; diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index fd2a1b22b4..1f24c7c403 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -336,7 +336,10 @@ char* syncNodePeerState2Str(const SSyncNode* pSyncNode) { for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) { SPeerState* pState = syncNodeGetPeerState((SSyncNode*)pSyncNode, &(pSyncNode->replicasId[i])); - ASSERT(pState != NULL); + if (pState == NULL) { + sError("vgId:%d, replica maybe dropped", pSyncNode->vgId); + break; + } p = pStr + useLen; use = snprintf(p, leftLen, "%d:%" PRId64 " ,%" PRId64, i, pState->lastSendIndex, pState->lastSendTime); @@ -3495,6 +3498,7 @@ SPeerState* syncNodeGetPeerState(SSyncNode* ths, const SRaftId* pDestId) { bool syncNodeNeedSendAppendEntries(SSyncNode* ths, const SRaftId* pDestId, const SyncAppendEntries* pMsg) { SPeerState* pState = syncNodeGetPeerState(ths, pDestId); if (pState == NULL) { + sError("vgId:%d, replica maybe dropped", ths->vgId); return false; } diff --git a/source/libs/sync/src/syncReplication.c b/source/libs/sync/src/syncReplication.c index e040310e15..7296e30e02 100644 --- a/source/libs/sync/src/syncReplication.c +++ b/source/libs/sync/src/syncReplication.c @@ -163,7 +163,10 @@ int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftI syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg); SPeerState* pState = syncNodeGetPeerState(pSyncNode, destRaftId); - ASSERT(pState != NULL); + if (pState == NULL) { + sError("vgId:%d, replica maybe dropped", pSyncNode->vgId); + return 0; + } if (pMsg->dataLen > 0) { pState->lastSendIndex = pMsg->prevLogIndex + 1;