From a01f34fd83fcb7c8977a1af8dde91866df8dd0ef Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Sat, 26 Nov 2022 16:20:08 +0800 Subject: [PATCH] fix: clear sync log buffer in syncLogBufferDestroy --- source/libs/sync/src/syncPipeline.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/source/libs/sync/src/syncPipeline.c b/source/libs/sync/src/syncPipeline.c index 994d62ca73..bf8f830185 100644 --- a/source/libs/sync/src/syncPipeline.c +++ b/source/libs/sync/src/syncPipeline.c @@ -622,7 +622,7 @@ int32_t syncLogReplMgrRetryOnNeed(SSyncLogReplMgr* pMgr, SSyncNode* pNode) { _out: if (retried) { pMgr->retryBackoff = syncLogGetNextRetryBackoff(pMgr); - sInfo("vgId:%d, resend %d sync log entries. dest: %" PRIx64 ", indexes: %" PRId64 " ..., terms: ... %" PRId64 + sInfo("vgId:%d, resent %d sync log entries. dest: %" PRIx64 ", indexes: %" PRId64 " ..., terms: ... %" PRId64 ", retryWaitMs: %" PRId64 ", repl mgr: [%" PRId64 " %" PRId64 ", %" PRId64 ")", pNode->vgId, count, pDestId->addr, firstIndex, term, retryWaitMs, pMgr->startIndex, pMgr->matchIndex, pMgr->endIndex); @@ -919,10 +919,24 @@ _err: return NULL; } +void syncLogBufferClear(SSyncLogBuffer* pBuf) { + taosThreadMutexLock(&pBuf->mutex); + for (SyncIndex index = pBuf->startIndex; index < pBuf->endIndex; index++) { + SSyncRaftEntry* pEntry = pBuf->entries[(index + pBuf->size) % pBuf->size].pItem; + if (pEntry == NULL) continue; + syncEntryDestroy(pEntry); + pEntry = NULL; + memset(&pBuf->entries[(index + pBuf->size) % pBuf->size], 0, sizeof(pBuf->entries[0])); + } + pBuf->startIndex = pBuf->commitIndex = pBuf->matchIndex = pBuf->endIndex = 0; + taosThreadMutexUnlock(&pBuf->mutex); +} + void syncLogBufferDestroy(SSyncLogBuffer* pBuf) { if (pBuf == NULL) { return; } + syncLogBufferClear(pBuf); (void)taosThreadMutexDestroy(&pBuf->mutex); (void)taosMemoryFree(pBuf); return;