fix: fsync the current wal log and idx files at first to ensure validity of meta in walSaveMeta
This commit is contained in:
parent
7fb827debd
commit
b6c31ee67d
|
@ -134,6 +134,7 @@ SWal *walOpen(const char *path, SWalCfg *pCfg) {
|
|||
pWal->writeHead.head.protoVer = WAL_PROTO_VER;
|
||||
pWal->writeHead.magic = WAL_MAGIC;
|
||||
|
||||
// load meta
|
||||
(void)walLoadMeta(pWal);
|
||||
|
||||
if (walCheckAndRepairMeta(pWal) < 0) {
|
||||
|
@ -188,11 +189,11 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
|
|||
|
||||
void walClose(SWal *pWal) {
|
||||
taosThreadMutexLock(&pWal->mutex);
|
||||
(void)walSaveMeta(pWal);
|
||||
taosCloseFile(&pWal->pLogFile);
|
||||
pWal->pLogFile = NULL;
|
||||
taosCloseFile(&pWal->pIdxFile);
|
||||
pWal->pIdxFile = NULL;
|
||||
walSaveMeta(pWal);
|
||||
taosArrayDestroy(pWal->fileInfoSet);
|
||||
pWal->fileInfoSet = NULL;
|
||||
taosHashCleanup(pWal->pRefHash);
|
||||
|
|
|
@ -209,10 +209,12 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
|||
taosCloseFile(&pIdxFile);
|
||||
taosCloseFile(&pLogFile);
|
||||
|
||||
taosFsyncFile(pWal->pLogFile);
|
||||
taosFsyncFile(pWal->pIdxFile);
|
||||
|
||||
walSaveMeta(pWal);
|
||||
code = walSaveMeta(pWal);
|
||||
if (code < 0) {
|
||||
wError("vgId:%d, failed to save meta since %s", pWal->cfg.vgId, terrstr());
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// unlock
|
||||
taosThreadMutexUnlock(&pWal->mutex);
|
||||
|
@ -384,7 +386,11 @@ int32_t walRollImpl(SWal *pWal) {
|
|||
|
||||
pWal->lastRollSeq = walGetSeq();
|
||||
|
||||
walSaveMeta(pWal);
|
||||
code = walSaveMeta(pWal);
|
||||
if (code < 0) {
|
||||
wError("vgId:%d, failed to save meta since %s", pWal->cfg.vgId, terrstr());
|
||||
goto END;
|
||||
}
|
||||
|
||||
END:
|
||||
return code;
|
||||
|
|
Loading…
Reference in New Issue