Fix crash at wal init write file.

This commit is contained in:
xiao-77 2024-12-04 09:30:58 +08:00
parent 79697c2a23
commit 1698fe0544
1 changed files with 13 additions and 1 deletions

View File

@ -706,8 +706,13 @@ _exit:
static int32_t walInitWriteFile(SWal *pWal) {
TdFilePtr pIdxTFile, pLogTFile;
int64_t fileFirstVer = -1;
int32_t code = 0;
SWalFileInfo *pRet = taosArrayGetLast(pWal->fileInfoSet);
int64_t fileFirstVer = pRet->firstVer;
if (pRet == NULL) {
fileFirstVer = pWal->vers.lastVer + 1;
}
fileFirstVer = pRet->firstVer;
char fnameStr[WAL_FILE_LEN];
walBuildIdxName(pWal, fileFirstVer, fnameStr);
@ -723,6 +728,13 @@ static int32_t walInitWriteFile(SWal *pWal) {
// switch file
pWal->pIdxFile = pIdxTFile;
pWal->pLogFile = pLogTFile;
if (taosArrayGetSize(pWal->fileInfoSet) == 0) {
code = walRollFileInfo(pWal);
if (code < 0) {
wError("vgId:%d, failed to roll file info while init write file since %s", pWal->cfg.vgId, terrstr());
TAOS_RETURN(code);
}
}
pWal->writeCur = taosArrayGetSize(pWal->fileInfoSet) - 1;
TAOS_RETURN(TSDB_CODE_SUCCESS);