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.head.protoVer = WAL_PROTO_VER;
|
||||||
pWal->writeHead.magic = WAL_MAGIC;
|
pWal->writeHead.magic = WAL_MAGIC;
|
||||||
|
|
||||||
|
// load meta
|
||||||
(void)walLoadMeta(pWal);
|
(void)walLoadMeta(pWal);
|
||||||
|
|
||||||
if (walCheckAndRepairMeta(pWal) < 0) {
|
if (walCheckAndRepairMeta(pWal) < 0) {
|
||||||
|
@ -188,11 +189,11 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) {
|
||||||
|
|
||||||
void walClose(SWal *pWal) {
|
void walClose(SWal *pWal) {
|
||||||
taosThreadMutexLock(&pWal->mutex);
|
taosThreadMutexLock(&pWal->mutex);
|
||||||
|
(void)walSaveMeta(pWal);
|
||||||
taosCloseFile(&pWal->pLogFile);
|
taosCloseFile(&pWal->pLogFile);
|
||||||
pWal->pLogFile = NULL;
|
pWal->pLogFile = NULL;
|
||||||
taosCloseFile(&pWal->pIdxFile);
|
taosCloseFile(&pWal->pIdxFile);
|
||||||
pWal->pIdxFile = NULL;
|
pWal->pIdxFile = NULL;
|
||||||
walSaveMeta(pWal);
|
|
||||||
taosArrayDestroy(pWal->fileInfoSet);
|
taosArrayDestroy(pWal->fileInfoSet);
|
||||||
pWal->fileInfoSet = NULL;
|
pWal->fileInfoSet = NULL;
|
||||||
taosHashCleanup(pWal->pRefHash);
|
taosHashCleanup(pWal->pRefHash);
|
||||||
|
|
|
@ -209,10 +209,12 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
|
||||||
taosCloseFile(&pIdxFile);
|
taosCloseFile(&pIdxFile);
|
||||||
taosCloseFile(&pLogFile);
|
taosCloseFile(&pLogFile);
|
||||||
|
|
||||||
taosFsyncFile(pWal->pLogFile);
|
code = walSaveMeta(pWal);
|
||||||
taosFsyncFile(pWal->pIdxFile);
|
if (code < 0) {
|
||||||
|
wError("vgId:%d, failed to save meta since %s", pWal->cfg.vgId, terrstr());
|
||||||
walSaveMeta(pWal);
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// unlock
|
// unlock
|
||||||
taosThreadMutexUnlock(&pWal->mutex);
|
taosThreadMutexUnlock(&pWal->mutex);
|
||||||
|
@ -384,7 +386,11 @@ int32_t walRollImpl(SWal *pWal) {
|
||||||
|
|
||||||
pWal->lastRollSeq = walGetSeq();
|
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:
|
END:
|
||||||
return code;
|
return code;
|
||||||
|
|
Loading…
Reference in New Issue