fix: set absent closeTs with mtime of log files during walCheckAndRepairMeta
This commit is contained in:
parent
ac0ac18cc1
commit
2a558323be
|
@ -295,6 +295,36 @@ void walAlignVersions(SWal* pWal) {
|
|||
wInfo("vgId:%d, reset commitVer to %" PRId64, pWal->cfg.vgId, pWal->vers.commitVer);
|
||||
}
|
||||
|
||||
int walRepairLogFileTs(SWal* pWal, bool* updateMeta) {
|
||||
int32_t sz = taosArrayGetSize(pWal->fileInfoSet);
|
||||
int32_t fileIdx = -1;
|
||||
int32_t lastCloseTs = 0;
|
||||
char fnameStr[WAL_FILE_LEN] = {0};
|
||||
|
||||
while (++fileIdx < sz - 1) {
|
||||
SWalFileInfo* pFileInfo = taosArrayGet(pWal->fileInfoSet, fileIdx);
|
||||
if (pFileInfo->closeTs != -1) {
|
||||
lastCloseTs = pFileInfo->closeTs;
|
||||
continue;
|
||||
}
|
||||
|
||||
walBuildLogName(pWal, pFileInfo->firstVer, fnameStr);
|
||||
int32_t mtime = 0;
|
||||
if (taosStatFile(fnameStr, NULL, &mtime) < 0) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
wError("vgId:%d, failed to stat file due to %s, file:%s", pWal->cfg.vgId, strerror(errno), fnameStr);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (updateMeta != NULL) *updateMeta = true;
|
||||
if (pFileInfo->createTs == -1) pFileInfo->createTs = lastCloseTs;
|
||||
pFileInfo->closeTs = mtime;
|
||||
lastCloseTs = pFileInfo->closeTs;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool walLogEntriesComplete(const SWal* pWal) {
|
||||
int32_t sz = taosArrayGetSize(pWal->fileInfoSet);
|
||||
bool complete = true;
|
||||
|
@ -460,6 +490,11 @@ int walCheckAndRepairMeta(SWal* pWal) {
|
|||
}
|
||||
(void)walAlignVersions(pWal);
|
||||
|
||||
// repair ts of files
|
||||
if (walRepairLogFileTs(pWal, &updateMeta) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// update meta file
|
||||
if (updateMeta) {
|
||||
(void)walSaveMeta(pWal);
|
||||
|
|
Loading…
Reference in New Issue