From fcce9ebafa10b3f9b6fb8a7b778fd29e7335e209 Mon Sep 17 00:00:00 2001 From: Minglei Jin Date: Fri, 19 Jul 2024 15:20:38 +0800 Subject: [PATCH] return wal fsync error code --- include/libs/wal/wal.h | 2 +- source/libs/sync/src/syncRaftLog.c | 6 +++++- source/libs/wal/src/walWrite.c | 9 +++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 9992e18584..b39cfcef92 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -164,7 +164,7 @@ void walClose(SWal *); // write interfaces // By assigning index by the caller, wal gurantees linearizability int32_t walAppendLog(SWal *, int64_t index, tmsg_t msgType, SWalSyncInfo syncMeta, const void *body, int32_t bodyLen); -void walFsync(SWal *, bool force); +int32_t walFsync(SWal *, bool force); // apis for lifecycle management int32_t walCommit(SWal *, int64_t ver); diff --git a/source/libs/sync/src/syncRaftLog.c b/source/libs/sync/src/syncRaftLog.c index 3ef59b3823..19c8837d83 100644 --- a/source/libs/sync/src/syncRaftLog.c +++ b/source/libs/sync/src/syncRaftLog.c @@ -227,7 +227,11 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr return -1; } - walFsync(pWal, forceSync); + code = walFsync(pWal, forceSync); + if (TSDB_CODE_SUCCESS != code) { + sNError(pData->pSyncNode, "wal fsync failed since %s", tstrerror(code)); + TAOS_RETURN(code); + } sNTrace(pData->pSyncNode, "write index:%" PRId64 ", type:%s, origin type:%s, elapsed:%" PRId64, pEntry->index, TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType), tsElapsed); diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 8a79f148bb..4a2beb1d45 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -732,9 +732,11 @@ _exit: return code; } -void walFsync(SWal *pWal, bool forceFsync) { +int32_t walFsync(SWal *pWal, bool forceFsync) { + int32_t code = 0; + if (pWal->cfg.level == TAOS_WAL_SKIP) { - return; + return code; } taosThreadMutexLock(&pWal->mutex); @@ -743,7 +745,10 @@ void walFsync(SWal *pWal, bool forceFsync) { if (taosFsyncFile(pWal->pLogFile) < 0) { wError("vgId:%d, file:%" PRId64 ".log, fsync failed since %s", pWal->cfg.vgId, walGetCurFileFirstVer(pWal), strerror(errno)); + code = TAOS_SYSTEM_ERROR(errno); } } taosThreadMutexUnlock(&pWal->mutex); + + return code; }