From a1cc2571ee871605989306712d19f968f2929758 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Fri, 24 Jun 2022 11:13:40 +0800 Subject: [PATCH] fix(wal): set first version to -1 if all log rollbacked --- source/libs/wal/src/walWrite.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 031289f93e..da7aa317d3 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -178,6 +178,10 @@ int32_t walRollback(SWal *pWal, int64_t ver) { } ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1; ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize = entry.offset; + if (((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer < ver - 1) { + ASSERT(((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->fileSize == 0); + ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->firstVer = -1; + } taosCloseFile(&pIdxTFile); taosCloseFile(&pLogTFile); @@ -395,8 +399,12 @@ int64_t walWriteWithSyncInfo(SWal *pWal, int64_t index, tmsg_t msgType, SSyncLog } // set status + if (pWal->vers.firstVer == -1) pWal->vers.firstVer = index; pWal->vers.lastVer = index; pWal->totSize += sizeof(SWalHead) + bodyLen; + if (walGetCurFileInfo(pWal)->firstVer == -1) { + walGetCurFileInfo(pWal)->firstVer = index; + } walGetCurFileInfo(pWal)->lastVer = index; walGetCurFileInfo(pWal)->fileSize += sizeof(SWalHead) + bodyLen; -- GitLab