From 78b4d1024934d7db380a0d26cf27936700f753dd Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Thu, 22 Sep 2022 00:36:04 +0800 Subject: [PATCH] optimize fix condition --- source/libs/wal/src/walMeta.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index a01869fbe0..c69046f707 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -257,6 +257,10 @@ int walCheckAndRepairIdx(SWal* pWal) { } taosFStatFile(pIdxFile, &fsize, NULL); + if (fsize == (pFileInfo->lastVer - pFileInfo->firstVer + 1) * sizeof(SWalIdxEntry)) { + taosCloseFile(&pIdxFile); + continue; + } int32_t left = fsize % sizeof(SWalIdxEntry); int64_t offset = taosLSeekFile(pIdxFile, -left, SEEK_END); @@ -267,7 +271,7 @@ int walCheckAndRepairIdx(SWal* pWal) { } offset -= sizeof(SWalIdxEntry); - SWalIdxEntry idxEntry = {0}; + SWalIdxEntry idxEntry = {.ver = pFileInfo->firstVer}; while (1) { if (offset < 0) { taosLSeekFile(pIdxFile, 0, SEEK_SET); @@ -306,7 +310,8 @@ int walCheckAndRepairIdx(SWal* pWal) { if (idxEntry.ver != ckHead.head.version) { // todo truncate this idx also taosCloseFile(&pLogFile); - wError("vgId:%d, invalid repair case", pWal->cfg.vgId); + wError("vgId:%d, invalid repair case, log seek to %ld to find ver %ld, actual ver %ld", pWal->cfg.vgId, + idxEntry.offset, idxEntry.ver, ckHead.head.version); return -1; } idxEntry.ver = ckHead.head.version + 1; -- GitLab