From aa5683cfd9fb9933924e3e0f0a6af0d8e9e2580f Mon Sep 17 00:00:00 2001 From: xsren <285808407@qq.com> Date: Tue, 10 Sep 2024 14:55:14 +0800 Subject: [PATCH] osfile --- source/client/src/clientMonitor.c | 4 +-- source/common/src/cos.c | 6 ++-- source/common/src/cos_cp.c | 4 +-- source/common/src/rsync.c | 4 +-- source/dnode/mgmt/mgmt_mnode/src/mmFile.c | 6 ++-- source/dnode/mgmt/mgmt_vnode/src/vmFile.c | 6 ++-- source/dnode/mgmt/node_util/src/dmEps.c | 10 +++--- source/dnode/mgmt/node_util/src/dmFile.c | 18 +++++----- source/dnode/mnode/sdb/src/sdbFile.c | 30 ++++++---------- source/dnode/vnode/src/tsdb/tsdbFS.c | 6 ++-- source/dnode/vnode/src/tsdb/tsdbFS2.c | 7 ++-- .../dnode/vnode/src/tsdb/tsdbReaderWriter.c | 8 ++--- source/dnode/vnode/src/vnd/vnodeCommit.c | 7 ++-- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 5 +-- source/libs/executor/src/groupcacheoperator.c | 10 +++--- source/libs/stream/src/streamBackendRocksdb.c | 4 +-- source/libs/sync/src/syncRaftCfg.c | 6 ++-- source/libs/sync/src/syncRaftStore.c | 8 ++--- source/libs/wal/src/walMeta.c | 20 +++++------ source/libs/wal/src/walRead.c | 6 ++-- source/libs/wal/src/walWrite.c | 12 +++---- source/os/src/osFile.c | 34 ++++++++++++------- source/os/src/osSocket.c | 2 +- source/util/src/tconfig.c | 7 +++- source/util/src/tlog.c | 5 ++- source/util/src/tpagedbuf.c | 5 ++- 26 files changed, 122 insertions(+), 118 deletions(-) diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 6a0a09f9bd..36dc474dd8 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -397,7 +397,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP } if (taosLSeekFile(pFile, 0, SEEK_END) < 0) { - tscError("failed to seek file:%p code: %d", pFile, errno); + tscError("failed to seek file:%p code: %d", pFile, terrno); return; } if (taosWriteFile(pFile, slowLogData->data, strlen(slowLogData->data) + 1) < 0) { @@ -409,7 +409,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP static char* readFile(TdFilePtr pFile, int64_t* offset, int64_t size) { tscDebug("[monitor] readFile slow begin pFile:%p, offset:%" PRId64 ", size:%" PRId64, pFile, *offset, size); if (taosLSeekFile(pFile, *offset, SEEK_SET) < 0) { - tscError("failed to seek file:%p code: %d", pFile, errno); + tscError("failed to seek file:%p code: %d", pFile, terrno); return NULL; } diff --git a/source/common/src/cos.c b/source/common/src/cos.c index 064e06eb43..1c06d9206e 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -132,7 +132,7 @@ int32_t s3CheckCfg() { } if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) { (void)fprintf(stderr, "failed to write test file: %s.\n", path); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); + TAOS_CHECK_GOTO(terrno, &lino, _next); } if (taosFsyncFile(fp) < 0) { (void)fprintf(stderr, "failed to fsync test file: %s.\n", path); @@ -872,7 +872,7 @@ upload: if (i > 0 && cp.parts[i - 1].completed) { if (taosLSeekFile(data->infileFD, cp.parts[i].offset, SEEK_SET) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } } @@ -1076,7 +1076,7 @@ static int32_t s3PutObjectFromFileOffsetByEp(const char *file, const char *objec } if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) { (void)taosCloseFile(&data.infileFD); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength = diff --git a/source/common/src/cos_cp.c b/source/common/src/cos_cp.c index 793433bba7..1caf6a7189 100644 --- a/source/common/src/cos_cp.c +++ b/source/common/src/cos_cp.c @@ -210,10 +210,10 @@ static int32_t cos_cp_save_json(cJSON const* json, SCheckpoint* checkpoint) { TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); } if (taosLSeekFile(fp, 0, SEEK_SET) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if (taosWriteFile(fp, data, strlen(data)) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if (taosFsyncFile(fp) < 0) { diff --git a/source/common/src/rsync.c b/source/common/src/rsync.c index b53c4e416e..525e1e0aea 100644 --- a/source/common/src/rsync.c +++ b/source/common/src/rsync.c @@ -90,10 +90,10 @@ static int32_t generateConfigFile(char* confDir) { #endif ); uDebug("[rsync] conf:%s", confContent); - if (taosWriteFile(pFile, confContent, strlen(confContent)) <= 0) { + if (taosWriteFile(pFile, confContent, strlen(confContent)) != TSDB_CODE_SUCCESS) { uError("[rsync] write conf file error," ERRNO_ERR_FORMAT, ERRNO_ERR_DATA); (void)taosCloseFile(&pFile); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; return code; } diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index d9f6920fcb..05a09b9a97 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -83,8 +83,8 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat mnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -203,7 +203,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } if (taosFsyncFile(pFile) < 0) { diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index d5b1e61aed..b7bf25c8d3 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -120,8 +120,8 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat mnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -240,7 +240,7 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) { int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } if (taosFsyncFile(pFile) < 0) { diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index 7c0272965a..685d70e1ae 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -209,8 +209,8 @@ int32_t dmReadEps(SDnodeData *pData) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat dnode file:%s since %s", file, terrstr()); goto _OVER; } @@ -336,7 +336,7 @@ int32_t dmWriteEps(SDnodeData *pData) { if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); int32_t len = strlen(buffer); - if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); + if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER); if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); (void)taosCloseFile(&pFile); @@ -612,8 +612,8 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat dnode file:%s since %s", file, terrstr()); goto _OVER; } diff --git a/source/dnode/mgmt/node_util/src/dmFile.c b/source/dnode/mgmt/node_util/src/dmFile.c index 3412d5ed3a..c524f4eacf 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -62,8 +62,8 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -154,7 +154,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) { int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } if (taosFsyncFile(pFile) < 0) { @@ -244,7 +244,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool } if (taosWriteFile(pFile, opts.result, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -282,7 +282,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC int32_t len = strlen(encryptCode); if (taosWriteFile(pFile, encryptCode, len) <= 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } if (taosFsyncFile(pFile) < 0) { @@ -320,8 +320,8 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) { goto _OVER; } - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { encryptError("failed to fstat dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -461,8 +461,8 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { dError("failed to fstat dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 813579ac26..e19f57ad46 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -168,26 +168,21 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) { } static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { - int32_t code = 0; int64_t sver = SDB_FILE_VER; if (taosWriteFile(pFile, &sver, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (taosWriteFile(pFile, &pSdb->applyIndex, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (taosWriteFile(pFile, &pSdb->applyTerm, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } if (taosWriteFile(pFile, &pSdb->applyConfig, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } for (int32_t i = 0; i < SDB_TABLE_SIZE; ++i) { @@ -196,8 +191,7 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { maxId = pSdb->maxId[i]; } if (taosWriteFile(pFile, &maxId, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } } @@ -207,15 +201,13 @@ static int32_t sdbWriteFileHead(SSdb *pSdb, TdFilePtr pFile) { ver = pSdb->tableVer[i]; } if (taosWriteFile(pFile, &ver, sizeof(int64_t)) != sizeof(int64_t)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } } char reserve[SDB_RESERVE_SIZE] = {0}; if (taosWriteFile(pFile, reserve, sizeof(reserve)) != sizeof(reserve)) { - code = TAOS_SYSTEM_ERROR(errno); - TAOS_RETURN(code); + return terrno; } return 0; @@ -440,7 +432,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { pRaw->status = pRow->status; if (taosWriteFile(pFile, pRaw, sizeof(SSdbRaw)) != sizeof(SSdbRaw)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -472,7 +464,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { } if (taosWriteFile(pFile, newData, newDataLen) != newDataLen) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -484,7 +476,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { int32_t cksum = taosCalcChecksum(0, (const uint8_t *)pRaw, sizeof(SSdbRaw) + pRaw->dataLen); if (taosWriteFile(pFile, &cksum, sizeof(int32_t)) != sizeof(int32_t)) { - code = TAOS_SYSTEM_ERROR(errno); + code = errno; taosHashCancelIterate(hash, ppRow); sdbFreeRaw(pRaw); break; @@ -784,7 +776,7 @@ int32_t sdbDoWrite(SSdb *pSdb, SSdbIter *pIter, void *pBuf, int32_t len) { int32_t code = 0; int32_t writelen = taosWriteFile(pIter->file, pBuf, len); if (writelen != len) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to write len:%d since %s, total:%" PRId64, len, tstrerror(code), pIter->total); TAOS_RETURN(code); } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index cde4d7ded8..3e2d8c026f 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -116,7 +116,7 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) { int64_t n = taosWriteFile(pFD, pData, size); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosFsyncFile(pFD) < 0) { @@ -296,8 +296,8 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) { } int64_t size; - if (taosFStatFile(pFD, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFD, &size, NULL); + if (code != 0) { (void)taosCloseFile(&pFD); TSDB_CHECK_CODE(code, lino, _exit); } diff --git a/source/dnode/vnode/src/tsdb/tsdbFS2.c b/source/dnode/vnode/src/tsdb/tsdbFS2.c index 843e700fd3..ea6f10b1bd 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -93,7 +93,7 @@ static int32_t save_json(const cJSON *json, const char *fname) { } if (taosWriteFile(fp, data, strlen(data)) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosFsyncFile(fp) < 0) { @@ -120,8 +120,9 @@ static int32_t load_json(const char *fname, cJSON **json) { } int64_t size; - if (taosFStatFile(fp, &size, NULL) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + code = taosFStatFile(fp, &size, NULL); + if (code != 0) { + TSDB_CHECK_CODE(code, lino, _exit); } data = taosMemoryMalloc(size + 1); diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index c34b29f97d..b0fbc19ec0 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -154,7 +154,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } (void)taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage); @@ -183,7 +183,7 @@ static int32_t tsdbWriteFilePage(STsdbFD *pFD, int32_t encryptAlgorithm, char *e n = taosWriteFile(pFD->pFD, pFD->pBuf, pFD->szPage); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (pFD->szFile < pFD->pgno) { @@ -220,7 +220,7 @@ static int32_t tsdbReadFilePage(STsdbFD *pFD, int64_t pgno, int32_t encryptAlgor // seek int64_t n = taosLSeekFile(pFD->pFD, offset, SEEK_SET); if (n < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } // read @@ -373,7 +373,7 @@ static int32_t tsdbReadFileBlock(STsdbFD *pFD, int64_t offset, int64_t size, boo // read last chunk int64_t ret = taosLSeekFile(pFD->pFD, chunksize * (chunkno - pFD->lcn) + cOffset, SEEK_SET); if (ret < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } ret = taosReadFile(pFD->pFD, buf + n, nRead); diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index c272e540ba..485499a28f 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -185,7 +185,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { } if (taosWriteFile(pFile, data, strlen(data)) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosFsyncFile(pFile) < 0) { @@ -236,9 +236,8 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) { TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); } - if (taosFStatFile(pFile, &size, NULL) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); - } + code = taosFStatFile(pFile, &size, NULL); + TSDB_CHECK_CODE(code, lino, _exit); pData = taosMemoryMalloc(size + 1); if (pData == NULL) { diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 7d8b5d4eda..e1ac42ca8c 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -272,9 +272,10 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) } int64_t size; - if (taosFStatFile(pFile, &size, NULL) < 0) { + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { (void)taosCloseFile(&pFile); - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code, lino, _exit); } *ppData = taosMemoryMalloc(sizeof(SSnapDataHdr) + size + 1); diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 576f3932b6..15350bdfef 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -315,16 +315,16 @@ static int32_t saveBlocksToDisk(SGroupCacheOperatorInfo* pGCache, SGcDownstreamC } int32_t ret = taosLSeekFile(pFd->fd, pHead->basic.offset, SEEK_SET); - if (ret == -1) { + if (ret < 0) { releaseFdToFileCtx(pFd); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _return; } ret = (int32_t)taosWriteFile(pFd->fd, pHead->pBuf, pHead->basic.bufSize); if (ret != pHead->basic.bufSize) { releaseFdToFileCtx(pFd); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _return; } @@ -548,8 +548,8 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa } int32_t ret = taosLSeekFile(pFileFd->fd, pBasic->offset, SEEK_SET); - if (ret == -1) { - code = TAOS_SYSTEM_ERROR(errno); + if (ret < 0) { + code = terrno; goto _return; } diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 4e14df9a40..993d9d91af 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -1669,7 +1669,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { } if (nBytes != taosWriteFile(pFile, buf, nBytes)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to write file to add extra info, file:%s, reason:%s", pDst, tstrerror(code)); goto _EXIT; } @@ -4970,7 +4970,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { nBytes = taosWriteFile(pFile, content, strlen(content)); if (nBytes != strlen(content)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("chkp failed to write meta file: %s,reason:%s", dstDir, tstrerror(code)); (void)taosCloseFile(&pFile); goto _ERROR; diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index ac3bba8c42..c7811ed093 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -156,7 +156,7 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) { int32_t len = strlen(buffer); if (taosWriteFile(pFile, buffer, len) <= 0) { - TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_EXIT(terrno); } if (taosFsyncFile(pFile) < 0) { @@ -265,8 +265,8 @@ int32_t syncReadCfgFile(SSyncNode *pNode) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { sError("vgId:%d, failed to fstat sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code)); goto _OVER; } diff --git a/source/libs/sync/src/syncRaftStore.c b/source/libs/sync/src/syncRaftStore.c index d6482ba2da..a4377858d8 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -58,10 +58,10 @@ int32_t raftStoreReadFile(SSyncNode *pNode) { } int64_t size = 0; - if (taosFStatFile(pFile, &size, NULL) < 0) { + code = taosFStatFile(pFile, &size, NULL); + if (code != 0) { sError("vgId:%d, failed to fstat raft store file:%s since %s", pNode->vgId, file, terrstr()); - - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + TAOS_CHECK_GOTO(code, &lino, _OVER); } pData = taosMemoryMalloc(size + 1); @@ -130,7 +130,7 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) { if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); int32_t len = strlen(buffer); - if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + if (taosWriteFile(pFile, buffer, len) <= 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 378e9d1903..3c144cae23 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -106,7 +106,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in int64_t ret = taosLSeekFile(pFile, offset, SEEK_SET); if (ret < 0) { wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno), offset); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (readSize != taosReadFile(pFile, buf, readSize)) { @@ -169,9 +169,9 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in } int64_t ret = taosLSeekFile(pFile, offset + readSize, SEEK_SET); if (ret < 0) { - wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(errno), + wError("vgId:%d, failed to lseek file due to %s. offset:%" PRId64 "", pWal->cfg.vgId, strerror(terrno), offset); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; break; } if (extraSize != taosReadFile(pFile, buf + readSize, extraSize)) { @@ -518,7 +518,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { static int32_t walReadLogHead(TdFilePtr pLogFile, int64_t offset, SWalCkHead* pCkHead) { if (taosLSeekFile(pLogFile, offset, SEEK_SET) < 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (taosReadFile(pLogFile, pCkHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) { @@ -578,14 +578,14 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { // determine the last valid entry end, i.e. offset while ((offset -= sizeof(SWalIdxEntry)) >= 0) { if (taosLSeekFile(pIdxFile, offset, SEEK_SET) < 0) { - wError("vgId:%d, failed to seek file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + wError("vgId:%d, failed to seek file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(terrno), offset, fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (taosReadFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) { - wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno), + wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(terrno), offset, fnameStr); TAOS_CHECK_GOTO(terrno, &lino, _err); @@ -628,7 +628,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { wError("vgId:%d, failed to seek file since %s. offset:%" PRId64 ", file:%s", pWal->cfg.vgId, terrstr(), offset, fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } int64_t count = 0; @@ -654,7 +654,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pIdxFile, &idxEntry, sizeof(SWalIdxEntry)) < 0) { wError("vgId:%d, failed to append file since %s. file:%s", pWal->cfg.vgId, terrstr(), fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } count++; } @@ -950,7 +950,7 @@ int32_t walSaveMeta(SWal* pWal) { if (pWal->cfg.level != TAOS_WAL_SKIP && len != taosWriteFile(pMetaFile, serialized, len)) { wError("vgId:%d, failed to write file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pMetaFile) < 0) { diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 6476cd39ac..73cf6d46ef 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -137,7 +137,7 @@ static int32_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int wError("vgId:%d, failed to seek idx file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pReader->pWal->cfg.vgId, ver, offset, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } SWalIdxEntry entry = {0}; if ((ret = taosReadFile(pIdxTFile, &entry, sizeof(SWalIdxEntry))) != sizeof(SWalIdxEntry)) { @@ -158,7 +158,7 @@ static int32_t walReadSeekFilePos(SWalReader *pReader, int64_t fileFirstVer, int wError("vgId:%d, failed to seek log file, index:%" PRId64 ", pos:%" PRId64 ", since %s", pReader->pWal->cfg.vgId, ver, entry.offset, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -303,7 +303,7 @@ int32_t walSkipFetchBody(SWalReader *pRead) { } int64_t code = taosLSeekFile(pRead->pLogFile, cryptedBodyLen, SEEK_CUR); if (code < 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } pRead->curVersion++; diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index a11831c437..43d5c07270 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -207,7 +207,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { if (code < 0) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // read idx file and get log file pos SWalIdxEntry entry; @@ -232,7 +232,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { // TODO TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // validate offset SWalCkHead head; @@ -536,13 +536,13 @@ static int32_t walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { pWal->stopDnode(); } - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // check alignment of idx entries int64_t endOffset = taosLSeekFile(pWal->pIdxFile, 0, SEEK_END); if (endOffset < 0) { - wFatal("vgId:%d, failed to seek end of WAL idxfile due to %s. ver:%" PRId64 "", pWal->cfg.vgId, strerror(errno), + wFatal("vgId:%d, failed to seek end of WAL idxfile due to %s. ver:%" PRId64 "", pWal->cfg.vgId, strerror(terrno), ver); taosMsleep(100); exit(EXIT_FAILURE); @@ -578,7 +578,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pWal->pLogFile, &pWal->writeHead, sizeof(SWalCkHead)) != sizeof(SWalCkHead)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); @@ -634,7 +634,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy } if (pWal->cfg.level != TAOS_WAL_SKIP && taosWriteFile(pWal->pLogFile, (char *)buf, cyptedBodyLen) != cyptedBodyLen) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), strerror(errno)); diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 3be2b1e351..042be9c71f 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -437,19 +437,22 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count) { if (pFile == NULL || pFile->hFile == NULL) { + terrno = TSDB_CODE_INVALID_PARA; return 0; } #if FILE_WITH_LOCK - taosThreadRwlockWrlock(&(pFile->rwlock)); + (void)taosThreadRwlockWrlock(&(pFile->rwlock)); #endif DWORD bytesWritten; if (!WriteFile(pFile->hFile, buf, count, &bytesWritten, NULL)) { + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); bytesWritten = -1; } #if FILE_WITH_LOCK - taosThreadRwlockUnlock(&(pFile->rwlock)); + (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif return bytesWritten; } @@ -490,6 +493,7 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { if (pFile == NULL || pFile->hFile == NULL) { + terrno = TSDB_CODE_INVALID_PARA; return -1; } #if FILE_WITH_LOCK @@ -499,11 +503,15 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { LARGE_INTEGER liOffset; liOffset.QuadPart = offset; if (!SetFilePointerEx(pFile->hFile, liOffset, NULL, whence)) { + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); return -1; } liOffset.QuadPart = 0; if (!SetFilePointerEx(pFile->hFile, liOffset, &liOffset, FILE_CURRENT)) { + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); return -1; } #if FILE_WITH_LOCK @@ -514,13 +522,16 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { if (pFile == NULL || pFile->hFile == NULL) { - return 0; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } if (size != NULL) { LARGE_INTEGER fileSize; if (!GetFileSizeEx(pFile->hFile, &fileSize)) { - return -1; // Error getting file size + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); + return terrno; // Error getting file size } *size = fileSize.QuadPart; } @@ -528,7 +539,9 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { if (mtime != NULL) { FILETIME creationTime, lastAccessTime, lastWriteTime; if (!GetFileTime(pFile->hFile, &creationTime, &lastAccessTime, &lastWriteTime)) { - return -1; // Error getting file time + errno = GetLastError(); + terrno = TAOS_SYSTEM_WINAPI_ERROR(errno); + return terrno; // Error getting file time } // Convert the FILETIME structure to a time_t value ULARGE_INTEGER ull; @@ -854,7 +867,7 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { if (pFile == NULL || pFile->fd < 0) { terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } #if FILE_WITH_LOCK (void)taosThreadRwlockRdlock(&(pFile->rwlock)); @@ -873,7 +886,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) { if (code) { terrno = code; - return terrno; + return -1; } return ret; @@ -890,16 +903,11 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { return terrno; } -#ifdef WINDOWS - struct __stat64 fileStat; - int32_t code = _fstat64(pFile->fd, &fileStat); -#else struct stat fileStat; int32_t code = fstat(pFile->fd, &fileStat); -#endif if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); - return code; + return terrno; } if (size != NULL) { diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 48ca36b5e5..4d650715f9 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -1178,7 +1178,7 @@ int32_t taosWinSocketInit() { WSADATA wsaData; wVersionRequested = MAKEWORD(1, 1); if (WSAStartup(wVersionRequested, &wsaData) != 0) { - atomic_store_8(&flag, 0) + atomic_store_8(&flag, 0); int errorCode = WSAGetLastError(); return terrno = TAOS_SYSTEM_WINSOCKET_ERROR(errorCode); } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index c6da1537f5..48fe271d33 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -1255,11 +1255,16 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); } size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END); + if(fileSize <= 0) { + (void)taosCloseFile(&pFile); + (void)printf("load json file error: %s\n", filepath); + TAOS_CHECK_EXIT(terrno); + } char *buf = taosMemoryMalloc(fileSize + 1); if (!buf) { (void)taosCloseFile(&pFile); (void)printf("load json file error: %s, failed to alloc memory\n", filepath); - TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY); + TAOS_RETURN(terrno); } buf[fileSize] = 0; diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 49e1d87d80..98e17c5db9 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -545,9 +545,9 @@ static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) { // only an estimate for number of lines int64_t filesize = 0; - if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) < 0) { + if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) != 0) { (void)printf("\nfailed to fstat log file:%s, reason:%s\n", name, strerror(errno)); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } tsLogObj.lines = (int32_t)(filesize / 60); @@ -1003,7 +1003,6 @@ _return: if (pFile) (void)taosCloseFile(&pFile); - terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "crash signal is %d", signum); #ifdef _TD_DARWIN_64 diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index de27cf4df9..265f06cbfd 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -136,13 +136,12 @@ static FORCE_INLINE size_t getAllocPageSize(int32_t pageSize) { return pageSize static int32_t doFlushBufPageImpl(SDiskbasedBuf* pBuf, int64_t offset, const char* pData, int32_t size) { int32_t ret = taosLSeekFile(pBuf->pFile, offset, SEEK_SET); if (ret == -1) { - terrno = TAOS_SYSTEM_ERROR(errno); + terrno = terrno; return terrno; } ret = (int32_t)taosWriteFile(pBuf->pFile, pData, size); if (ret != size) { - terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } @@ -249,7 +248,7 @@ static int32_t loadPageFromDisk(SDiskbasedBuf* pBuf, SPageInfo* pg) { int32_t ret = taosLSeekFile(pBuf->pFile, pg->offset, SEEK_SET); if (ret == -1) { - ret = TAOS_SYSTEM_ERROR(errno); + ret = terrno; return ret; }