diff --git a/source/client/src/clientMonitor.c b/source/client/src/clientMonitor.c index 36dc474dd8..b890b61668 100644 --- a/source/client/src/clientMonitor.c +++ b/source/client/src/clientMonitor.c @@ -34,11 +34,11 @@ static void processFileInTheEnd(TdFilePtr pFile, char* path) { return; } if (taosFtruncateFile(pFile, 0) != 0) { - tscError("failed to truncate file:%s, errno:%d", path, errno); + tscError("failed to truncate file:%s, errno:%d", path, terrno); return; } if (taosUnLockFile(pFile) != 0) { - tscError("failed to unlock file:%s, errno:%d", path, errno); + tscError("failed to unlock file:%s, errno:%d", path, terrno); return; } if (taosCloseFile(&(pFile)) != 0) { @@ -367,7 +367,7 @@ static void monitorWriteSlowLog2File(MonitorSlowLogData* slowLogData, char* tmpP tscInfo("[monitor] create slow log file:%s", path); pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC); if (pFile == NULL) { - tscError("failed to open file:%s since %d", path, errno); + tscError("failed to open file:%s since %d", path, terrno); return; } @@ -549,7 +549,7 @@ static void monitorSendSlowLogAtRunning(int64_t clusterId) { int64_t size = getFileSize(pClient->path); if (size <= pClient->offset) { if (taosFtruncateFile(pClient->pFile, 0) < 0) { - tscError("failed to truncate file:%p code: %d", pClient->pFile, errno); + tscError("failed to truncate file:%p code: %d", pClient->pFile, terrno); } tscDebug("[monitor] monitorSendSlowLogAtRunning truncate file to 0 file:%p", pClient->pFile); pClient->offset = 0; @@ -606,7 +606,7 @@ static void monitorSendAllSlowLogAtQuit() { static void processFileRemoved(SlowLogClient* pClient) { if (taosUnLockFile(pClient->pFile) != 0) { - tscError("failed to unlock file:%s since %d", pClient->path, errno); + tscError("failed to unlock file:%s since %d", pClient->path, terrno); return; } (void)taosCloseFile(&(pClient->pFile)); @@ -614,7 +614,7 @@ static void processFileRemoved(SlowLogClient* pClient) { TdFilePtr pFile = taosOpenFile(pClient->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND | TD_FILE_READ | TD_FILE_TRUNC); if (pFile == NULL) { - tscError("failed to open file:%s since %d", pClient->path, errno); + tscError("failed to open file:%s since %d", pClient->path, terrno); } else { pClient->pFile = pFile; } diff --git a/source/common/src/cos.c b/source/common/src/cos.c index 1c06d9206e..d3b3f1f87d 100644 --- a/source/common/src/cos.c +++ b/source/common/src/cos.c @@ -128,7 +128,7 @@ int32_t s3CheckCfg() { if (!fp) { (void)fprintf(stderr, "failed to open test file: %s.\n", path); // uError("ERROR: %s Failed to open %s", __func__, path); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); + TAOS_CHECK_GOTO(terrno, &lino, _next); } if (taosWriteFile(fp, testdata, strlen(testdata)) < 0) { (void)fprintf(stderr, "failed to write test file: %s.\n", path); @@ -136,7 +136,7 @@ int32_t s3CheckCfg() { } if (taosFsyncFile(fp) < 0) { (void)fprintf(stderr, "failed to fsync test file: %s.\n", path); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next); + TAOS_CHECK_GOTO(terrno, &lino, _next); } (void)taosCloseFile(&fp); @@ -988,12 +988,12 @@ int32_t s3PutObjectFromFile2ByEp(const char *file, const char *object_name, int8 if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) { uError("ERROR: %s Failed to stat file %s: ", __func__, file); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) { uError("ERROR: %s Failed to open file %s: ", __func__, file); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength = @@ -1065,14 +1065,14 @@ static int32_t s3PutObjectFromFileOffsetByEp(const char *file, const char *objec if (taosStatFile(file, (int64_t *)&contentLength, &lmtime, NULL) < 0) { uError("ERROR: %s Failed to stat file %s: ", __func__, file); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } contentLength = size; if (!(data.infileFD = taosOpenFile(file, TD_FILE_READ))) { uError("ERROR: %s Failed to open file %s: ", __func__, file); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (taosLSeekFile(data.infileFD, offset, SEEK_SET) < 0) { (void)taosCloseFile(&data.infileFD); @@ -1412,8 +1412,8 @@ static int32_t s3GetObjectToFileByEp(const char *object_name, const char *fileNa TdFilePtr pFile = taosOpenFile(fileName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - uError("[s3] open file error, errno:%d, fileName:%s", TAOS_SYSTEM_ERROR(errno), fileName); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + uError("[s3] open file error, errno:%d, fileName:%s", terrno, fileName); + TAOS_RETURN(terrno); } TS3GetData cbd = {0}; diff --git a/source/common/src/cos_cp.c b/source/common/src/cos_cp.c index 1caf6a7189..ce5f666f21 100644 --- a/source/common/src/cos_cp.c +++ b/source/common/src/cos_cp.c @@ -10,7 +10,7 @@ int32_t cos_cp_open(char const* cp_path, SCheckpoint* checkpoint) { TdFilePtr fd = taosOpenFile(cp_path, TD_FILE_WRITE | TD_FILE_CREATE /* | TD_FILE_TRUNC*/ | TD_FILE_WRITE_THROUGH); if (!fd) { uError("%s Failed to open %s", __func__, cp_path); - TAOS_CHECK_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_RETURN(terrno); } checkpoint->thefile = fd; @@ -162,7 +162,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) { TdFilePtr fd = taosOpenFile(filepath, TD_FILE_READ); if (!fd) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } int64_t size = -1; @@ -207,7 +207,7 @@ static int32_t cos_cp_save_json(cJSON const* json, SCheckpoint* checkpoint) { TdFilePtr fp = checkpoint->thefile; if (taosFtruncateFile(fp, 0) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } if (taosLSeekFile(fp, 0, SEEK_SET) < 0) { TAOS_CHECK_GOTO(terrno, &lino, _exit); diff --git a/source/common/src/rsync.c b/source/common/src/rsync.c index 525e1e0aea..77787db3ce 100644 --- a/source/common/src/rsync.c +++ b/source/common/src/rsync.c @@ -58,7 +58,7 @@ static int32_t generateConfigFile(char* confDir) { TdFilePtr pFile = taosOpenFile(confDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { uError("[rsync] open conf file error, dir:%s," ERRNO_ERR_FORMAT, confDir, ERRNO_ERR_DATA); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } #ifdef WINDOWS diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c index 05a09b9a97..073ba293e2 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmFile.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmFile.c @@ -71,13 +71,13 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) { } if (taosStatFile(file, NULL, NULL, NULL) < 0) { - dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(TAOS_SYSTEM_ERROR(errno))); + dInfo("mnode file:%s not exist, reason:%s", file, tstrerror(terrno)); return 0; } pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open mnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -197,7 +197,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -207,7 +207,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) { goto _OVER; } if (taosFsyncFile(pFile) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c index b7bf25c8d3..2f93d51ea2 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmFile.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmFile.c @@ -106,7 +106,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t snprintf(file, sizeof(file), "%s%svnodes.json", pMgmt->path, TD_DIRSEP); if (taosStatFile(file, NULL, NULL, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dInfo("vnode file:%s not exist, reason:%s", file, tstrerror(code)); code = 0; return code; @@ -114,7 +114,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open vnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -234,7 +234,7 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) { pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } diff --git a/source/dnode/mgmt/node_util/src/dmEps.c b/source/dnode/mgmt/node_util/src/dmEps.c index 685d70e1ae..982c139c7b 100644 --- a/source/dnode/mgmt/node_util/src/dmEps.c +++ b/source/dnode/mgmt/node_util/src/dmEps.c @@ -203,7 +203,7 @@ int32_t dmReadEps(SDnodeData *pData) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open dnode file:%s since %s", file, terrstr()); goto _OVER; } @@ -333,11 +333,11 @@ int32_t dmWriteEps(SDnodeData *pData) { } pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); - if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER); + if (pFile == NULL) TAOS_CHECK_GOTO(terrno, NULL, _OVER); int32_t len = strlen(buffer); 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); + if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(terrno, NULL, _OVER); (void)taosCloseFile(&pFile); TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER); @@ -598,7 +598,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) { snprintf(file, sizeof(file), "%s%sdnode%sep.json", tsDataDir, TD_DIRSEP, TD_DIRSEP); if (taosStatFile(file, NULL, NULL, NULL) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dDebug("dnode file:%s not exist, reason:%s", file, tstrerror(code)); code = 0; goto _OVER; @@ -606,7 +606,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open 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 c524f4eacf..61a72f2aeb 100644 --- a/source/dnode/mgmt/node_util/src/dmFile.c +++ b/source/dnode/mgmt/node_util/src/dmFile.c @@ -56,7 +56,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -148,7 +148,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) { pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -158,7 +158,7 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) { goto _OVER; } if (taosFsyncFile(pFile) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -188,7 +188,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) { *pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_CLOEXEC); if (*pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open file:%s since %s", filepath, tstrerror(code)); return code; } @@ -199,7 +199,7 @@ int32_t dmCheckRunning(const char *dataDir, TdFilePtr *pFile) { ret = taosLockFile(*pFile); if (ret == 0) break; - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; taosMsleep(1000); retryTimes++; dError("failed to lock file:%s since %s, retryTimes:%d", filepath, tstrerror(code), retryTimes); @@ -239,7 +239,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -276,7 +276,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -286,7 +286,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC goto _OVER; } if (taosFsyncFile(pFile) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _OVER; } @@ -315,7 +315,7 @@ static int32_t dmCompareEncryptKey(char *file, char *key, bool toLogFile) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; encryptError("failed to open dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } @@ -455,7 +455,7 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; dError("failed to open dnode file:%s since %s", file, tstrerror(code)); goto _OVER; } diff --git a/source/dnode/mnode/impl/src/mndDump.c b/source/dnode/mnode/impl/src/mndDump.c index 04c9093c11..7613282ef8 100644 --- a/source/dnode/mnode/impl/src/mndDump.c +++ b/source/dnode/mnode/impl/src/mndDump.c @@ -616,7 +616,7 @@ void mndDumpSdb() { char file[] = "sdb.json"; TdFilePtr pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); + terrno = terrno; mError("failed to write %s since %s", file, terrstr()); return; } diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index e19f57ad46..fd4819dadd 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -234,7 +234,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) { TdFilePtr pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { taosMemoryFree(pRaw); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mInfo("read sdb file:%s finished since %s", file, tstrerror(code)); return 0; } @@ -386,7 +386,7 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) { TdFilePtr pFile = taosOpenFile(tmpfile, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to open sdb file:%s for write since %s", tmpfile, tstrerror(code)); TAOS_RETURN(code); } @@ -638,8 +638,8 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter int64_t commitTerm = pSdb->commitTerm; int64_t commitConfig = pSdb->commitConfig; if (taosCopyFile(datafile, pIter->name) < 0) { + code = terrno; (void)taosThreadMutexUnlock(&pSdb->filelock); - code = TAOS_SYSTEM_ERROR(errno); mError("failed to copy sdb file %s to %s since %s", datafile, pIter->name, tstrerror(code)); sdbCloseIter(pIter); TAOS_RETURN(code); @@ -648,7 +648,7 @@ int32_t sdbStartRead(SSdb *pSdb, SSdbIter **ppIter, int64_t *index, int64_t *ter pIter->file = taosOpenFile(pIter->name, TD_FILE_READ); if (pIter->file == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to open sdb file:%s since %s", pIter->name, tstrerror(code)); sdbCloseIter(pIter); TAOS_RETURN(code); @@ -708,7 +708,7 @@ int32_t sdbStartWrite(SSdb *pSdb, SSdbIter **ppIter) { pIter->file = taosOpenFile(pIter->name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pIter->file == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; mError("failed to open %s since %s", pIter->name, tstrerror(code)); sdbCloseIter(pIter); TAOS_RETURN(code); diff --git a/source/dnode/vnode/src/tsdb/tsdbFS.c b/source/dnode/vnode/src/tsdb/tsdbFS.c index 3e2d8c026f..ecf838b761 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS.c @@ -111,7 +111,7 @@ static int32_t tsdbSaveFSToFile(STsdbFS *pFS, const char *fname) { // save to file pFD = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFD == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } int64_t n = taosWriteFile(pFD, pData, size); @@ -176,7 +176,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { if (pTsdb->fs.pDelFile) { tsdbDelFileName(pTsdb, pTsdb->fs.pDelFile, fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } } @@ -190,7 +190,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { // head ========= tsdbHeadFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pHeadF, fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } // if (size != tsdbLogicToFileSize(pSet->pHeadF->size, pTsdb->pVnode->config.tsdbPageSize)) { @@ -201,7 +201,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { // data ========= tsdbDataFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pDataF, fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } // if (size < tsdbLogicToFileSize(pSet->pDataF->size, pTsdb->pVnode->config.tsdbPageSize)) { @@ -216,7 +216,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { // sma ============= tsdbSmaFileName(pTsdb, pSet->diskId, pSet->fid, pSet->pSmaF, fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } // if (size < tsdbLogicToFileSize(pSet->pSmaF->size, pTsdb->pVnode->config.tsdbPageSize)) { @@ -232,7 +232,7 @@ static int32_t tsdbScanAndTryFixFS(STsdb *pTsdb) { for (int32_t iStt = 0; iStt < pSet->nSttF; iStt++) { tsdbSttFileName(pTsdb, pSet->diskId, pSet->fid, pSet->aSttF[iStt], fname); if (taosStatFile(fname, &size, NULL, NULL)) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } // if (size != tsdbLogicToFileSize(pSet->aSttF[iStt]->size, pTsdb->pVnode->config.tsdbPageSize)) { @@ -291,7 +291,7 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) { // load binary TdFilePtr pFD = taosOpenFile(fname, TD_FILE_READ); if (pFD == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; 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 ea6f10b1bd..f7c50e4260 100644 --- a/source/dnode/vnode/src/tsdb/tsdbFS2.c +++ b/source/dnode/vnode/src/tsdb/tsdbFS2.c @@ -89,7 +89,7 @@ static int32_t save_json(const cJSON *json, const char *fname) { fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (fp == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosWriteFile(fp, data, strlen(data)) < 0) { @@ -97,7 +97,7 @@ static int32_t save_json(const cJSON *json, const char *fname) { } if (taosFsyncFile(fp) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } _exit: @@ -116,7 +116,7 @@ static int32_t load_json(const char *fname, cJSON **json) { TdFilePtr fp = taosOpenFile(fname, TD_FILE_READ); if (fp == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } int64_t size; diff --git a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c index b0fbc19ec0..c0a1e4b047 100644 --- a/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c +++ b/source/dnode/vnode/src/tsdb/tsdbReaderWriter.c @@ -46,14 +46,14 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) { pFD->pFD = taosOpenFile(lc_path, flag); if (pFD->pFD == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosStatFile(lc_path, &lc_size, NULL, NULL) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } } else { tsdbInfo("no file: %s", path); - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } pFD->s3File = 1; } @@ -73,7 +73,7 @@ static int32_t tsdbOpenFileImpl(STsdbFD *pFD) { // not check file size when reading data files. if (flag != TD_FILE_READ /* && !pFD->s3File*/) { if (!lc_size && taosStatFile(path, &pFD->szFile, NULL, NULL) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } } diff --git a/source/dnode/vnode/src/tsdb/tsdbRetention.c b/source/dnode/vnode/src/tsdb/tsdbRetention.c index 96b752104d..c80e7c651e 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRetention.c +++ b/source/dnode/vnode/src/tsdb/tsdbRetention.c @@ -48,7 +48,7 @@ static int32_t tsdbCopyFileWithLimitedSpeed(TdFilePtr from, TdFilePtr to, int64_ int64_t n; int64_t last = taosGetTimestampMs(); if ((n = taosFSendFile(to, from, &offset, TMIN(limit, remain))) < 0) { - TAOS_CHECK_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_RETURN(terrno); } remain -= n; @@ -76,14 +76,14 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi fdFrom = taosOpenFile(fname_from, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname_to, from->f->size); fdTo = taosOpenFile(fname_to, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (fdTo == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } SVnodeCfg *pCfg = &rtner->tsdb->pVnode->config; @@ -91,7 +91,7 @@ static int32_t tsdbDoCopyFileLC(SRTNer *rtner, const STFileObj *from, const STFi int64_t lc_size = tsdbLogicToFileSize(to->size, rtner->szPage) - chunksize * (to->lcn - 1); if (taosFSendFile(fdTo, fdFrom, 0, lc_size) < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } _exit: @@ -116,14 +116,14 @@ static int32_t tsdbDoCopyFile(SRTNer *rtner, const STFileObj *from, const STFile fdFrom = taosOpenFile(from->fname, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } tsdbInfo("vgId: %d, open tofile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, from->f->size); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (fdTo == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } TSDB_CHECK_CODE(code, lino, _exit); @@ -429,7 +429,7 @@ static int32_t tsdbCopyFileS3(SRTNer *rtner, const STFileObj *from, const STFile fdFrom = taosOpenFile(from->fname, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } char *object_name = taosDirEntryBaseName(fname); @@ -519,7 +519,7 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int fdFrom = taosOpenFile(fname, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } tsdbInfo("vgId:%d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, lc_size); @@ -527,12 +527,12 @@ static int32_t tsdbMigrateDataFileLCS3(SRTNer *rtner, const STFileObj *fobj, int snprintf(dot2 + 1, TSDB_FQDN_LEN - (dot2 + 1 - object_name), "%d.data", lcn); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (fdTo == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size); if (n < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } _exit: @@ -618,19 +618,19 @@ static int32_t tsdbMigrateDataFileS3(SRTNer *rtner, const STFileObj *fobj, int64 fdFrom = taosOpenFile(fobj->fname, TD_FILE_READ); if (fdFrom == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } tsdbInfo("vgId: %d, open lcfile: %s size: %" PRId64, TD_VID(rtner->tsdb->pVnode), fname, fobj->f->size); fdTo = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC); if (fdTo == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } int64_t n = taosFSendFile(fdTo, fdFrom, &lc_offset, lc_size); if (n < 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } _exit: diff --git a/source/dnode/vnode/src/vnd/vnodeCommit.c b/source/dnode/vnode/src/vnd/vnodeCommit.c index 485499a28f..53d590bfbd 100644 --- a/source/dnode/vnode/src/vnd/vnodeCommit.c +++ b/source/dnode/vnode/src/vnd/vnodeCommit.c @@ -181,7 +181,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { // save info to a vnode_tmp.json pFile = taosOpenFile(fname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } if (taosWriteFile(pFile, data, strlen(data)) < 0) { @@ -189,7 +189,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) { } if (taosFsyncFile(pFile) < 0) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } _exit: @@ -233,7 +233,7 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) { // read info pFile = taosOpenFile(fname, TD_FILE_READ); if (pFile == NULL) { - TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit); + TSDB_CHECK_CODE(code = terrno, lino, _exit); } code = taosFStatFile(pFile, &size, NULL); diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index e1ac42ca8c..edf6c5a814 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -267,7 +267,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData) TdFilePtr pFile = taosOpenFile(fName, TD_FILE_READ); if (NULL == pFile) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; TSDB_CHECK_CODE(code, lino, _exit); } diff --git a/source/libs/executor/src/groupcacheoperator.c b/source/libs/executor/src/groupcacheoperator.c index 15350bdfef..8dfc08f26e 100644 --- a/source/libs/executor/src/groupcacheoperator.c +++ b/source/libs/executor/src/groupcacheoperator.c @@ -204,7 +204,7 @@ static FORCE_INLINE int32_t initOpenCacheFile(SGroupCacheFileFd* pFileFd, char* TdFilePtr newFd = taosOpenFile(filename, TD_FILE_CREATE|TD_FILE_READ|TD_FILE_WRITE|TD_FILE_AUTO_DEL); //TdFilePtr newFd = taosOpenFile(filename, TD_FILE_CREATE|TD_FILE_READ|TD_FILE_WRITE); if (NULL == newFd) { - QRY_ERR_RET(TAOS_SYSTEM_ERROR(errno)); + QRY_ERR_RET(terrno); } pFileFd->fd = newFd; int32_t code = taosThreadMutexInit(&pFileFd->mutex, NULL); diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index b17af44260..6ae718c101 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -994,7 +994,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) { TdFilePtr file = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC); if (file == NULL) { - fnError("udfd write udf shared library: %s failed, error: %d %s", path, errno, strerror(errno)); + fnError("udfd write udf shared library: %s failed, error: %d %s", path, errno, strerror(terrno)); return TSDB_CODE_FILE_CORRUPTED; } int64_t count = taosWriteFile(file, pFuncInfo->pCode, pFuncInfo->codeSize); diff --git a/source/libs/parser/src/parInsertSql.c b/source/libs/parser/src/parInsertSql.c index 9412735ded..51ecc67ec9 100644 --- a/source/libs/parser/src/parInsertSql.c +++ b/source/libs/parser/src/parInsertSql.c @@ -2268,7 +2268,7 @@ static int32_t parseDataFromFile(SInsertParseContext* pCxt, SVnodeModifyOpStmt* } pStmt->fp = taosOpenFile(filePathStr, TD_FILE_READ | TD_FILE_STREAM); if (NULL == pStmt->fp) { - return TAOS_SYSTEM_ERROR(errno); + return terrno; } return parseDataFromFileImpl(pCxt, pStmt, rowsDataCxt); diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index 62943cb6d5..b084fd8c5d 100755 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -11374,7 +11374,7 @@ static int32_t translateDropView(STranslateContext* pCxt, SDropViewStmt* pStmt) static int32_t readFromFile(char* pName, int32_t* len, char** buf) { int64_t filesize = 0; if (taosStatFile(pName, &filesize, NULL, NULL) < 0) { - return TAOS_SYSTEM_ERROR(errno); + return terrno; } *len = filesize; @@ -11391,7 +11391,7 @@ static int32_t readFromFile(char* pName, int32_t* len, char** buf) { TdFilePtr tfile = taosOpenFile(pName, O_RDONLY | O_BINARY); if (NULL == tfile) { taosMemoryFreeClear(*buf); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } int64_t s = taosReadFile(tfile, *buf, *len); @@ -14070,7 +14070,7 @@ static int32_t prepareReadCsvFile(STranslateContext* pCxt, SCreateSubTableFromFi if (NULL == pModifyStmt->fp) { fp = taosOpenFile(pCreateStmt->filePath, TD_FILE_READ | TD_FILE_STREAM); if (NULL == fp) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _ERR; } } diff --git a/source/libs/stream/src/streamBackendRocksdb.c b/source/libs/stream/src/streamBackendRocksdb.c index 993d9d91af..a177db688d 100644 --- a/source/libs/stream/src/streamBackendRocksdb.c +++ b/source/libs/stream/src/streamBackendRocksdb.c @@ -290,7 +290,7 @@ int32_t remoteChkp_readMetaData(char* path, SSChkpMetaOnS3** pMeta) { pFile = taosOpenFile(path, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _EXIT; } @@ -357,7 +357,7 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch } if (taosStatFile(src, NULL, NULL, NULL) != 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; goto _EXIT; } @@ -1603,7 +1603,7 @@ int32_t chkpLoadExtraInfo(char* pChkpIdDir, int64_t* chkpId, int64_t* processId) // compatible with previous version *processId = -1; code = 0; - stWarn("failed to open file to load extra info, file:%s, reason:%s", pDst, tstrerror(TAOS_SYSTEM_ERROR(errno))); + stWarn("failed to open file to load extra info, file:%s, reason:%s", pDst, tstrerror(terrno)); goto _EXIT; } @@ -1656,7 +1656,7 @@ int32_t chkpAddExtraInfo(char* pChkpIdDir, int64_t chkpId, int64_t processId) { pFile = taosOpenFile(pDst, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to open file to add extra info, file:%s, reason:%s", pDst, tstrerror(code)); goto _EXIT; } @@ -4940,7 +4940,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { } if (taosCopyFile(srcBuf, dstBuf) < 0) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("failed to copy file from %s to %s, reason:%s", srcBuf, dstBuf, tstrerror(code)); goto _ERROR; } @@ -4953,7 +4953,7 @@ int32_t dbChkpDumpTo(SDbChkp* p, char* dname, SArray* list) { TdFilePtr pFile = taosOpenFile(dstDir, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("chkp failed to create meta file: %s, reason:%s", dstDir, tstrerror(code)); goto _ERROR; } diff --git a/source/libs/stream/src/streamSnapshot.c b/source/libs/stream/src/streamSnapshot.c index 2b69da6007..4e804f9ca7 100644 --- a/source/libs/stream/src/streamSnapshot.c +++ b/source/libs/stream/src/streamSnapshot.c @@ -556,9 +556,9 @@ _NEXT: uint8_t* buf = taosMemoryCalloc(1, sizeof(SStreamSnapBlockHdr) + kBlockSize); int64_t nread = taosPReadFile(pSnapFile->fd, buf + sizeof(SStreamSnapBlockHdr), kBlockSize, pSnapFile->offset); - if (nread == -1) { + if (nread < 0) { taosMemoryFree(buf); - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; stError("%s snap failed to read snap, file name:%s, type:%d,reason:%s", STREAM_STATE_TRANSFER, item->name, item->type, tstrerror(code)); return code; diff --git a/source/libs/sync/src/syncRaftCfg.c b/source/libs/sync/src/syncRaftCfg.c index c7811ed093..e8ed73b089 100644 --- a/source/libs/sync/src/syncRaftCfg.c +++ b/source/libs/sync/src/syncRaftCfg.c @@ -150,7 +150,7 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) { pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); if (pFile == NULL) { - code = terrno ? terrno : TAOS_SYSTEM_ERROR(errno); + code = terrno; TAOS_CHECK_EXIT(code); } @@ -259,7 +259,7 @@ int32_t syncReadCfgFile(SSyncNode *pNode) { pFile = taosOpenFile(file, TD_FILE_READ); if (pFile == NULL) { - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; sError("vgId:%d, failed to open 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 a4377858d8..3bb40286bc 100644 --- a/source/libs/sync/src/syncRaftStore.c +++ b/source/libs/sync/src/syncRaftStore.c @@ -54,7 +54,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) { if (pFile == NULL) { sError("vgId:%d, failed to open raft store file:%s since %s", pNode->vgId, file, terrstr()); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + TAOS_CHECK_GOTO(terrno, &lino, _OVER); } int64_t size = 0; @@ -127,15 +127,15 @@ int32_t raftStoreWriteFile(SSyncNode *pNode) { if (buffer == NULL) TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER); pFile = taosOpenFile(file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_WRITE_THROUGH); - if (pFile == NULL) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + if (pFile == NULL) TAOS_CHECK_GOTO(terrno, &lino, _OVER); int32_t len = strlen(buffer); 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); + if (taosFsyncFile(pFile) < 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); (void)taosCloseFile(&pFile); - if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _OVER); + if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(terrno, &lino, _OVER); code = 0; sInfo("vgId:%d, succeed to write raft store file:%s, term:%" PRId64, pNode->vgId, realfile, pStore->currentTerm); diff --git a/source/libs/wal/src/walMeta.c b/source/libs/wal/src/walMeta.c index 3c144cae23..5f1ae02166 100644 --- a/source/libs/wal/src/walMeta.c +++ b/source/libs/wal/src/walMeta.c @@ -63,7 +63,7 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in if (pFile == NULL) { wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); *lastVer = retVer; - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // ensure size as non-negative @@ -223,8 +223,8 @@ static FORCE_INLINE int32_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx, in lastEntryEndOffset, fileSize); if (taosFtruncateFile(pFile, lastEntryEndOffset) < 0) { - wError("failed to truncate file due to %s. file:%s", strerror(errno), fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + wError("failed to truncate file due to %s. file:%s", strerror(terrno), fnameStr); + TAOS_CHECK_GOTO(terrno, &lino, _err); } if (pWal->cfg.level != TAOS_WAL_SKIP && taosFsyncFile(pFile) < 0) { @@ -315,7 +315,7 @@ static int32_t walRepairLogFileTs(SWal* pWal, bool* updateMeta) { if (taosStatFile(fnameStr, NULL, &mtime, NULL) < 0) { wError("vgId:%d, failed to stat file due to %s, file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (updateMeta != NULL) *updateMeta = true; @@ -375,7 +375,7 @@ static int32_t walTrimIdxFile(SWal* pWal, int32_t fileIdx) { TdFilePtr pFile = taosOpenFile(fnameStr, TD_FILE_READ | TD_FILE_WRITE); if (pFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } wInfo("vgId:%d, trim idx file. file: %s, size: %" PRId64 ", offset: %" PRId64, pWal->cfg.vgId, fnameStr, fileSize, @@ -462,7 +462,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) { if (code < 0) { wError("failed to stat file since %s. file:%s", terrstr(), fnameStr); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (pFileInfo->lastVer >= pFileInfo->firstVer && fileSize == pFileInfo->fileSize) { @@ -545,7 +545,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { if (taosStatFile(fnameStr, &fileSize, NULL, NULL) < 0 && errno != ENOENT) { wError("vgId:%d, failed to stat file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } if (fileSize == (pFileInfo->lastVer - pFileInfo->firstVer + 1) * sizeof(SWalIdxEntry)) { @@ -565,14 +565,14 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { if (pIdxFile == NULL) { wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), fnameStr); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } pLogFile = taosOpenFile(fLogNameStr, TD_FILE_READ); if (pLogFile == NULL) { wError("vgId:%d, cannot open file %s, since %s", pWal->cfg.vgId, fLogNameStr, terrstr()); - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err); + TAOS_CHECK_GOTO(terrno, &lino, _err); } // determine the last valid entry end, i.e. offset @@ -619,7 +619,7 @@ static int32_t walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) { wError("vgId:%d, failed to ftruncate 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); } } @@ -941,7 +941,7 @@ int32_t walSaveMeta(SWal* pWal) { if (pMetaFile == NULL) { wError("vgId:%d, failed to open file due to %s. file:%s", pWal->cfg.vgId, strerror(errno), tmpFnameStr); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } char* serialized = NULL; diff --git a/source/libs/wal/src/walRead.c b/source/libs/wal/src/walRead.c index 73cf6d46ef..aed7db327f 100644 --- a/source/libs/wal/src/walRead.c +++ b/source/libs/wal/src/walRead.c @@ -175,7 +175,7 @@ static int32_t walReadChangeFile(SWalReader *pReader, int64_t fileFirstVer) { if (pLogFile == NULL) { wError("vgId:%d, cannot open file %s, since %s", pReader->pWal->cfg.vgId, fnameStr, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } pReader->pLogFile = pLogFile; @@ -185,7 +185,7 @@ static int32_t walReadChangeFile(SWalReader *pReader, int64_t fileFirstVer) { if (pIdxFile == NULL) { wError("vgId:%d, cannot open file %s, since %s", pReader->pWal->cfg.vgId, fnameStr, terrstr()); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } pReader->pIdxFile = pIdxFile; diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 43d5c07270..224a7dc711 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -53,7 +53,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { wError("vgId:%d, restore from snapshot, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); @@ -62,7 +62,7 @@ int32_t walRestoreFromSnapshot(SWal *pWal, int64_t ver) { wError("vgId:%d, cannot remove file %s since %s", pWal->cfg.vgId, fnameStr, terrstr()); TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } wInfo("vgId:%d, restore from snapshot, remove file %s", pWal->cfg.vgId, fnameStr); } @@ -111,20 +111,20 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { char fnameStr[WAL_FILE_LEN]; if (pWal->pLogFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } code = taosCloseFile(&pWal->pLogFile); if (code != 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } } if (pWal->pIdxFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } code = taosCloseFile(&pWal->pIdxFile); if (code != 0) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } } @@ -141,7 +141,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { if (pIdxTFile == NULL) { pWal->pIdxFile = NULL; - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } walBuildLogName(pWal, fileFirstVer, fnameStr); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); @@ -149,7 +149,7 @@ static int64_t walChangeWrite(SWal *pWal, int64_t ver) { TAOS_UNUSED(taosCloseFile(&pIdxTFile)); pWal->pLogFile = NULL; - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } pWal->pLogFile = pLogTFile; @@ -200,7 +200,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { if (pIdxFile == NULL) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } int64_t idxOff = walGetVerIdxOffset(pWal, ver); code = taosLSeekFile(pIdxFile, idxOff, SEEK_SET); @@ -225,7 +225,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) { // TODO TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } code = taosLSeekFile(pLogFile, entry.offset, SEEK_SET); if (code < 0) { @@ -260,13 +260,13 @@ int32_t walRollback(SWal *pWal, int64_t ver) { if (code < 0) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(code); } code = taosFtruncateFile(pIdxFile, idxOff); if (code < 0) { TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(code); } pWal->vers.lastVer = ver - 1; ((SWalFileInfo *)taosArrayGetLast(pWal->fileInfoSet))->lastVer = ver - 1; @@ -294,21 +294,21 @@ static int32_t walRollImpl(SWal *pWal) { if (pWal->pIdxFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pIdxFile)) != 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } code = taosCloseFile(&pWal->pIdxFile); if (code != 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } } if (pWal->pLogFile != NULL) { if (pWal->cfg.level != TAOS_WAL_SKIP && (code = taosFsyncFile(pWal->pLogFile)) != 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } code = taosCloseFile(&pWal->pLogFile); if (code != 0) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } } @@ -319,13 +319,13 @@ static int32_t walRollImpl(SWal *pWal) { walBuildIdxName(pWal, newFileFirstVer, fnameStr); pIdxFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxFile == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } walBuildLogName(pWal, newFileFirstVer, fnameStr); pLogFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); wDebug("vgId:%d, wal create new file for write:%s", pWal->cfg.vgId, fnameStr); if (pLogFile == NULL) { - TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit); + TAOS_CHECK_GOTO(terrno, &lino, _exit); } TAOS_CHECK_GOTO(walRollFileInfo(pWal), &lino, _exit); @@ -672,7 +672,6 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy _exit: // recover in a reverse order if (taosFtruncateFile(pWal->pLogFile, offset) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); wFatal("vgId:%d, failed to recover WAL logfile from write error since %s, offset:%" PRId64, pWal->cfg.vgId, terrstr(), offset); taosMsleep(100); @@ -681,7 +680,6 @@ _exit: int64_t idxOffset = (index - pFileInfo->firstVer) * sizeof(SWalIdxEntry); if (taosFtruncateFile(pWal->pIdxFile, idxOffset) < 0) { - terrno = TAOS_SYSTEM_ERROR(errno); wFatal("vgId:%d, failed to recover WAL idxfile from write error since %s, offset:%" PRId64, pWal->cfg.vgId, terrstr(), idxOffset); taosMsleep(100); @@ -700,12 +698,12 @@ static int32_t walInitWriteFile(SWal *pWal) { walBuildIdxName(pWal, fileFirstVer, fnameStr); pIdxTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pIdxTFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } walBuildLogName(pWal, fileFirstVer, fnameStr); pLogTFile = taosOpenFile(fnameStr, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pLogTFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } // switch file pWal->pIdxFile = pIdxTFile; @@ -755,7 +753,7 @@ int32_t 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); + code = terrno; } } TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex)); diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index 042be9c71f..a9cd099d54 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -554,7 +554,8 @@ int32_t taosFStatFile(TdFilePtr pFile, int64_t *size, int32_t *mtime) { int32_t taosLockFile(TdFilePtr pFile) { if (pFile == NULL || pFile->hFile == NULL) { - return -1; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } BOOL fSuccess = FALSE; @@ -568,7 +569,7 @@ int32_t taosLockFile(TdFilePtr pFile) { &overlapped // overlapped structure ); if (!fSuccess) { - return GetLastError(); + return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } return 0; } @@ -582,18 +583,20 @@ int32_t taosUnLockFile(TdFilePtr pFile) { fSuccess = UnlockFileEx(pFile->hFile, 0, ~0, ~0, &overlapped); if (!fSuccess) { - return GetLastError(); + return TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); } return 0; } int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { if (pFile == NULL) { - return 0; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } if (pFile->hFile == NULL) { printf("Ftruncate file error, hFile was null\n"); - return -1; + terrno = TSDB_CODE_INVALID_PARA; + return terrno; } LARGE_INTEGER li_0; @@ -601,7 +604,8 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { BOOL cur = SetFilePointerEx(pFile->hFile, li_0, NULL, FILE_CURRENT); if (!cur) { printf("SetFilePointerEx Error getting current position in file.\n"); - return -1; + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); + return terrno; } LARGE_INTEGER li_size; @@ -609,7 +613,6 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { BOOL cur2 = SetFilePointerEx(pFile->hFile, li_size, NULL, FILE_BEGIN); if (cur2 == 0) { int error = GetLastError(); - printf("SetFilePointerEx GetLastError is: %d\n", error); switch (error) { case ERROR_INVALID_HANDLE: errno = EBADF; @@ -618,7 +621,8 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { errno = EIO; break; } - return -1; + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; } if (!SetEndOfFile(pFile->hFile)) { @@ -632,23 +636,27 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { errno = EIO; break; } - return -1; + terrno = TAOS_SYSTEM_ERROR(errno); + return terrno; } return 0; } int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) { if (pFileOut == NULL || pFileIn == NULL) { - return 0; + terrno = TSDB_CODE_INVALID_PARA; + return -1; } if (pFileIn->hFile == NULL || pFileOut->hFile == NULL) { - return 0; + terrno = TSDB_CODE_INVALID_PARA; + return -1; } LARGE_INTEGER fileOffset; fileOffset.QuadPart = *offset; if (!SetFilePointerEx(pFileIn->hFile, fileOffset, &fileOffset, FILE_BEGIN)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } @@ -659,6 +667,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in DWORD bytesWritten; for (int64_t len = 0; len < (size - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { if (!ReadFile(pFileIn->hFile, buffer, _SEND_FILE_STEP_, &bytesRead, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return writeLen; } @@ -666,12 +675,14 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in return writeLen; } else if (bytesRead < _SEND_FILE_STEP_) { if (!WriteFile(pFileOut->hFile, buffer, bytesRead, &bytesWritten, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } else { return (int64_t)(writeLen + bytesRead); } } else { if (!WriteFile(pFileOut->hFile, buffer, _SEND_FILE_STEP_, &bytesWritten, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } else { writeLen += _SEND_FILE_STEP_; @@ -683,6 +694,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in if (remain > 0) { DWORD bytesRead; if (!ReadFile(pFileIn->hFile, buffer, (DWORD)remain, &bytesRead, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } @@ -691,6 +703,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in } else { DWORD bytesWritten; if (!WriteFile(pFileOut->hFile, buffer, bytesRead, &bytesWritten, NULL)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return -1; } else { writeLen += bytesWritten; @@ -740,7 +753,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } int64_t leftbytes = count; @@ -763,7 +776,7 @@ int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) { (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif terrno = code; - return terrno; + return -1; } } else if (readbytes == 0) { #if FILE_WITH_LOCK @@ -926,32 +939,12 @@ int32_t taosLockFile(TdFilePtr pFile) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } - -#ifdef WINDOWS - BOOL fSuccess = FALSE; - LARGE_INTEGER fileSize; - OVERLAPPED overlapped = {0}; - - HANDLE hFile = (HANDLE)_get_osfhandle(pFile->fd); - - fSuccess = LockFileEx(hFile, LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY, - 0, // reserved - ~0, // number of bytes to lock low - ~0, // number of bytes to lock high - &overlapped // overlapped structure - ); - if (!fSuccess) { - return GetLastError(); - } - return 0; -#else int32_t code = (int32_t)flock(pFile->fd, LOCK_EX | LOCK_NB); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - return code; -#endif + return 0; } int32_t taosUnLockFile(TdFilePtr pFile) { @@ -959,25 +952,12 @@ int32_t taosUnLockFile(TdFilePtr pFile) { terrno = TSDB_CODE_INVALID_PARA; return terrno; } - -#ifdef WINDOWS - BOOL fSuccess = FALSE; - OVERLAPPED overlapped = {0}; - HANDLE hFile = (HANDLE)_get_osfhandle(pFile->fd); - - fSuccess = UnlockFileEx(hFile, 0, ~0, ~0, &overlapped); - if (!fSuccess) { - return GetLastError(); - } - return 0; -#else int32_t code = (int32_t)flock(pFile->fd, LOCK_UN | LOCK_NB); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - return code; -#endif + return 0; } int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { @@ -986,104 +966,29 @@ int32_t taosFtruncateFile(TdFilePtr pFile, int64_t l_size) { return terrno; } -#ifdef WINDOWS - - HANDLE h = (HANDLE)_get_osfhandle(pFile->fd); - - LARGE_INTEGER li_0; - li_0.QuadPart = (int64_t)0; - BOOL cur = SetFilePointerEx(h, li_0, NULL, FILE_CURRENT); - if (!cur) { - printf("SetFilePointerEx Error getting current position in file.\n"); - return -1; - } - - LARGE_INTEGER li_size; - li_size.QuadPart = l_size; - BOOL cur2 = SetFilePointerEx(h, li_size, NULL, FILE_BEGIN); - if (cur2 == 0) { - int error = GetLastError(); - printf("SetFilePointerEx GetLastError is: %d\n", error); - switch (error) { - case ERROR_INVALID_HANDLE: - errno = EBADF; - break; - default: - errno = EIO; - break; - } - return -1; - } - - if (!SetEndOfFile(h)) { - int error = GetLastError(); - printf("SetEndOfFile GetLastError is:%d", error); - switch (error) { - case ERROR_INVALID_HANDLE: - errno = EBADF; - break; - default: - errno = EIO; - break; - } - return -1; - } - - return 0; -#else int32_t code = ftruncate(pFile->fd, l_size); if (-1 == code) { terrno = TAOS_SYSTEM_ERROR(errno); return terrno; } - return code; -#endif + return 0; } int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, int64_t size) { if (pFileOut == NULL || pFileIn == NULL) { terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } if (pFileIn->fd < 0 || pFileOut->fd < 0) { terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } -#ifdef WINDOWS - - _lseeki64(pFileIn->fd, *offset, 0); - int64_t writeLen = 0; - uint8_t buffer[_SEND_FILE_STEP_] = {0}; - - for (int64_t len = 0; len < (size - _SEND_FILE_STEP_); len += _SEND_FILE_STEP_) { - size_t rlen = _read(pFileIn->fd, (void *)buffer, _SEND_FILE_STEP_); - if (rlen <= 0) { - return writeLen; - } else if (rlen < _SEND_FILE_STEP_) { - write(pFileOut->fd, (void *)buffer, (uint32_t)rlen); - return (int64_t)(writeLen + rlen); - } else { - write(pFileOut->fd, (void *)buffer, _SEND_FILE_STEP_); - writeLen += _SEND_FILE_STEP_; - } +#ifdef _TD_DARWIN_64 + if(lseek(pFileIn->fd, (int32_t)(*offset), 0) < 0) { + terrno = TAOS_SYSTEM_ERROR(errno); + return -1; } - - int64_t remain = size - writeLen; - if (remain > 0) { - size_t rlen = _read(pFileIn->fd, (void *)buffer, (size_t)remain); - if (rlen <= 0) { - return writeLen; - } else { - write(pFileOut->fd, (void *)buffer, (uint32_t)remain); - writeLen += remain; - } - } - return writeLen; - -#elif defined(_TD_DARWIN_64) - - lseek(pFileIn->fd, (int32_t)(*offset), 0); int64_t writeLen = 0; uint8_t buffer[_SEND_FILE_STEP_] = {0}; @@ -1112,7 +1017,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in } return writeLen; -#else +#else // for linux int64_t leftbytes = size; int64_t sentbytes; @@ -1128,7 +1033,7 @@ int64_t taosFSendFile(TdFilePtr pFileOut, TdFilePtr pFileIn, int64_t *offset, in continue; } else { terrno = TAOS_SYSTEM_ERROR(errno); - return terrno; + return -1; } } else if (sentbytes == 0) { return (int64_t)(size - leftbytes); @@ -1223,6 +1128,7 @@ int32_t taosCloseFile(TdFilePtr *ppFile) { if ((*ppFile)->hFile != NULL) { // FlushFileBuffers((*ppFile)->hFile); if (!CloseHandle((*ppFile)->hFile)) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); code = -1; } (*ppFile)->hFile = NULL; @@ -1251,7 +1157,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) STUB_RAND_IO_ERR(terrno) if (pFile == NULL) { terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } int32_t code = 0; @@ -1267,7 +1173,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) #endif terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } DWORD ret = 0; @@ -1278,7 +1184,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) SetLastError(0); BOOL result = ReadFile(pFile->hFile, buf, count, &ret, &ol); if (!result && GetLastError() != ERROR_HANDLE_EOF) { - errno = GetLastError(); + code = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); ret = -1; } #else @@ -1291,7 +1197,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif terrno = TSDB_CODE_INVALID_PARA; - return terrno; + return -1; } int64_t ret = pread(pFile->fd, buf, count, offset); if (-1 == ret) { @@ -1304,10 +1210,10 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset) if (code) { terrno = code; - return code; + return -1; } - return ret; + return 0; } int32_t taosFsyncFile(TdFilePtr pFile) { @@ -1333,7 +1239,12 @@ int32_t taosFsyncFile(TdFilePtr pFile) { if (pFile->tdFileOptions & TD_FILE_WRITE_THROUGH) { return 0; } - return !FlushFileBuffers(pFile->hFile); + bool ret = FlushFileBuffers(pFile->hFile); + if (!ret) { + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); + return terrno; + } + return 0; } #else if (pFile->fd >= 0) { @@ -1397,7 +1308,9 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { #ifdef WINDOWS size_t bufferSize = 512; *ptrBuf = taosMemoryMalloc(bufferSize); - if (*ptrBuf == NULL) goto END; + if (*ptrBuf == NULL) { + goto END; + } size_t bytesRead = 0; size_t totalBytesRead = 0; @@ -1405,8 +1318,14 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { while (1) { char *result = fgets(*ptrBuf + totalBytesRead, bufferSize - totalBytesRead, pFile->fp); if (result == NULL) { - taosMemoryFreeClear(*ptrBuf); - goto END; + if (feof(pFile->fp)) { + break; + } else { + ret = -1; + terrno = TAOS_SYSTEM_ERROR(ferror(pFile->fp)); + taosMemoryFreeClear(*ptrBuf); + goto END; + } } bytesRead = strlen(*ptrBuf + totalBytesRead); totalBytesRead += bytesRead; @@ -1431,7 +1350,7 @@ int64_t taosGetLineFile(TdFilePtr pFile, char **__restrict ptrBuf) { size_t len = 0; ret = getline(ptrBuf, &len, pFile->fp); if (-1 == ret) { - code = TAOS_SYSTEM_ERROR(errno); + terrno = TAOS_SYSTEM_ERROR(errno); } #endif @@ -1441,10 +1360,6 @@ END: (void)taosThreadRwlockUnlock(&(pFile->rwlock)); #endif - if (code) { - terrno = code; - } - return ret; } @@ -1636,8 +1551,7 @@ int taosSetAutoDelFile(char *path) { if (succ) { return 0; } else { - DWORD error = GetLastError(); - terrno = TAOS_SYSTEM_ERROR(error); + terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError()); return terrno; } #else diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 48fe271d33..bcbf09abdc 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -136,7 +136,7 @@ static int32_t cfgCheckAndSetConf(SConfigItem *pItem, const char *conf) { static int32_t cfgCheckAndSetDir(SConfigItem *pItem, const char *inputDir) { char fullDir[PATH_MAX] = {0}; if (taosExpandDir(inputDir, fullDir, PATH_MAX) != 0) { - int32_t code = TAOS_SYSTEM_ERROR(errno); + int32_t code = terrno; uError("failed to expand dir:%s since %s", inputDir, tstrerror(code)); TAOS_RETURN(code); } @@ -1009,7 +1009,7 @@ int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *envFile) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { - TAOS_RETURN(TAOS_SYSTEM_ERROR(errno)); + TAOS_RETURN(terrno); } while (!taosEOFFile(pFile)) { @@ -1066,7 +1066,7 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ | TD_FILE_STREAM); if (pFile == NULL) { // success when the file does not exist - code = TAOS_SYSTEM_ERROR(errno); + code = terrno; if (errno == ENOENT) { uInfo("failed to load from cfg file %s since %s, use default parameters", filepath, tstrerror(code)); TAOS_RETURN(TSDB_CODE_SUCCESS); @@ -1252,7 +1252,7 @@ int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { TdFilePtr pFile = taosOpenFile(filepath, TD_FILE_READ); if (pFile == NULL) { - TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno)); + TAOS_CHECK_EXIT(terrno); } size_t fileSize = taosLSeekFile(pFile, 0, SEEK_END); if(fileSize <= 0) { diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index 98e17c5db9..bde3d48a6d 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -207,7 +207,7 @@ int32_t taosInitSlowLog() { tsLogObj.slowHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (tsLogObj.slowHandle->pFile == NULL) { (void)printf("\nfailed to open slow log file:%s, reason:%s\n", name, strerror(errno)); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } return 0; @@ -539,7 +539,7 @@ static int32_t taosInitNormalLog(const char *logName, int32_t maxFileNum) { tsLogObj.logHandle->pFile = taosOpenFile(name, TD_FILE_CREATE | TD_FILE_WRITE); if (tsLogObj.logHandle->pFile == NULL) { (void)printf("\nfailed to open log file:%s, reason:%s\n", name, strerror(errno)); - return TAOS_SYSTEM_ERROR(errno); + return terrno; } (void)taosLockLogFile(tsLogObj.logHandle->pFile); @@ -973,7 +973,6 @@ void taosLogCrashInfo(char *nodeType, char *pMsg, int64_t msgLen, int signum, vo pFile = taosOpenFile(filepath, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND); if (pFile == NULL) { - terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr()); goto _return; } @@ -1029,11 +1028,10 @@ void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr if (NULL == *pFd) { int64_t filesize = 0; if (taosStatFile(filepath, &filesize, NULL, NULL) < 0) { - if (ENOENT == errno) { + if (TAOS_SYSTEM_ERROR(ENOENT) == terrno) { return; } - terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "failed to stat file:%s since %s", filepath, terrstr()); return; } @@ -1048,7 +1046,6 @@ void taosReadCrashInfo(char *filepath, char **pMsg, int64_t *pMsgLen, TdFilePtr return; } - terrno = TAOS_SYSTEM_ERROR(errno); taosPrintLog(flags, level, dflag, "failed to open file:%s since %s", filepath, terrstr()); return; } diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 265f06cbfd..534da9cd77 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -64,7 +64,7 @@ static int32_t createDiskFile(SDiskbasedBuf* pBuf) { pBuf->pFile = taosOpenFile(pBuf->path, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_READ | TD_FILE_TRUNC | TD_FILE_AUTO_DEL); if (pBuf->pFile == NULL) { - return TAOS_SYSTEM_ERROR(errno); + return terrno; } return TSDB_CODE_SUCCESS;