Merge pull request #27752 from taosdata/fix/TD-31870/OSFileRetCode

osDir
This commit is contained in:
Pan Wei 2024-09-11 17:52:14 +08:00 committed by GitHub
commit 8b7b5b7c6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
43 changed files with 495 additions and 579 deletions

View File

@ -143,7 +143,7 @@ int32_t taosWriteMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t taosReadMsg(TdSocketPtr pSocket, void *ptr, int32_t nbytes);
int32_t taosNonblockwrite(TdSocketPtr pSocket, char *ptr, int32_t nbytes);
int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len);
void taosWinSocketInit();
int32_t taosWinSocketInit();
/*
* set timeout(ms)

View File

@ -35,6 +35,8 @@ extern STaosError errors[];
#define TAOS_DEF_ERROR_CODE(mod, code) ((int32_t)((0x80000000 | ((mod)<<16) | (code))))
#define TAOS_SYSTEM_ERROR(code) (0x80ff0000 | (code))
#define TAOS_SYSTEM_WINAPI_ERROR(code) (0x81ff0000 | (code))
#define TAOS_SYSTEM_WINSOCKET_ERROR(code) (0x82ff0000 | (code))
#define TAOS_SUCCEEDED(err) ((err) >= 0)
#define TAOS_FAILED(err) ((err) < 0)
@ -153,6 +155,7 @@ int32_t taosGetErrSize();
#define TSDB_CODE_MSG_PREPROCESSED TAOS_DEF_ERROR_CODE(0, 0x0136) // internal
#define TSDB_CODE_OUT_OF_BUFFER TAOS_DEF_ERROR_CODE(0, 0x0137)
#define TSDB_CODE_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x0138)
#define TSDB_CODE_SOCKET_ERROR TAOS_DEF_ERROR_CODE(0, 0x0139)
//client
#define TSDB_CODE_TSC_INVALID_OPERATION TAOS_DEF_ERROR_CODE(0, 0x0200)

View File

@ -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;
}
@ -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;
}
@ -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;
}
@ -821,9 +821,10 @@ int32_t monitorInit() {
return code;
}
if (taosMulModeMkDir(tmpSlowLogPath, 0777, true) != 0) {
code = taosMulModeMkDir(tmpSlowLogPath, 0777, true);
if (code != 0) {
tscError("failed to create dir:%s since %s", tmpSlowLogPath, terrstr());
return TAOS_GET_TERRNO(TSDB_CODE_OUT_OF_MEMORY);
return code;
}
if (tsem2_init(&monitorSem, 0, 0) != 0) {

View File

@ -128,15 +128,15 @@ 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);
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);
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _next);
TAOS_CHECK_GOTO(terrno, &lino, _next);
}
(void)taosCloseFile(&fp);
@ -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);
}
}
@ -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,18 +1065,18 @@ 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);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
}
data.totalContentLength = data.totalOriginalContentLength = data.contentLength = data.originalContentLength =
@ -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};
@ -1881,7 +1881,6 @@ void s3EvictCache(const char *path, long object_size) {
// 1, list data files' atime under dir(path)
tdbDirPtr pDir = taosOpenDir(dir_name);
if (pDir == NULL) {
terrno = TAOS_SYSTEM_ERROR(errno);
vError("failed to open %s since %s", dir_name, terrstr());
}
SArray *evict_files = taosArrayInit(16, sizeof(SEvictFile));

View File

@ -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;
@ -175,7 +175,7 @@ int32_t cos_cp_load(char const* filepath, SCheckpoint* checkpoint) {
int64_t n = taosReadFile(fd, cp_body, size);
if (n < 0) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _exit);
TAOS_CHECK_GOTO(terrno, &lino, _exit);
} else if (n != size) {
TAOS_CHECK_GOTO(TSDB_CODE_FILE_CORRUPTED, &lino, _exit);
}
@ -207,13 +207,13 @@ 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(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) {

View File

@ -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
@ -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;
}

View File

@ -71,20 +71,20 @@ 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;
}
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;
}
@ -96,7 +96,7 @@ int32_t mmReadFile(const char *path, SMnodeOpt *pOption) {
}
if (taosReadFile(pFile, pData, size) != size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
dError("failed to read mnode file:%s since %s", file, tstrerror(code));
goto _OVER;
}
@ -197,17 +197,17 @@ 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;
}
int32_t len = strlen(buffer);
if (taosWriteFile(pFile, buffer, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _OVER;
}
if (taosFsyncFile(pFile) < 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _OVER;
}
@ -215,10 +215,7 @@ int32_t mmWriteFile(const char *path, const SMnodeOpt *pOption) {
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
if (taosRenameFile(file, realfile) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
dInfo("succeed to write mnode file:%s, deloyed:%d", realfile, pOption->deploy);

View File

@ -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,14 +114,14 @@ 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;
}
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;
}
@ -133,7 +133,7 @@ int32_t vmGetVnodeListFromFile(SVnodeMgmt *pMgmt, SWrapperCfg **ppCfgs, int32_t
}
if (taosReadFile(pFile, pData, size) != size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
dError("failed to read vnode file:%s since %s", file, tstrerror(code));
goto _OVER;
}
@ -234,13 +234,13 @@ 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;
}
int32_t len = strlen(buffer);
if (taosWriteFile(pFile, buffer, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _OVER;
}
if (taosFsyncFile(pFile) < 0) {
@ -253,12 +253,8 @@ int32_t vmWriteVnodeListToFile(SVnodeMgmt *pMgmt) {
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
if (taosRenameFile(file, realfile) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = 0;
dInfo("succeed to write vnodes file:%s, vnodes:%d", realfile, numOfVnodes);
_OVER:

View File

@ -203,14 +203,14 @@ 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;
}
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;
}
@ -222,7 +222,7 @@ int32_t dmReadEps(SDnodeData *pData) {
}
if (taosReadFile(pFile, content, size) != size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
dError("failed to read dnode file:%s since %s", file, terrstr());
goto _OVER;
}
@ -333,16 +333,15 @@ 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(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
if (taosFsyncFile(pFile) < 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(terrno, NULL, _OVER);
(void)taosCloseFile(&pFile);
if (taosRenameFile(file, realfile) != 0) TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _OVER);
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = 0;
pData->updateTime = taosGetTimestampMs();
dInfo("succeed to write dnode file:%s, num:%d ver:%" PRId64, realfile, (int32_t)taosArrayGetSize(pData->dnodeEps),
pData->dnodeVer);
@ -599,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;
@ -607,14 +606,14 @@ 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;
}
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;
}
@ -626,7 +625,7 @@ static int32_t dmReadDnodePairs(SDnodeData *pData) {
}
if (taosReadFile(pFile, content, size) != size) {
terrno = TAOS_SYSTEM_ERROR(errno);
terrno = terrno;
dError("failed to read dnode file:%s since %s", file, terrstr());
goto _OVER;
}

View File

@ -56,14 +56,14 @@ 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;
}
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;
}
@ -75,7 +75,7 @@ int32_t dmReadFile(const char *path, const char *name, bool *pDeployed) {
}
if (taosReadFile(pFile, content, size) != size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
dError("failed to read file:%s since %s", file, tstrerror(code));
goto _OVER;
}
@ -148,17 +148,17 @@ 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;
}
int32_t len = strlen(buffer);
if (taosWriteFile(pFile, buffer, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _OVER;
}
if (taosFsyncFile(pFile) < 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _OVER;
}
@ -166,12 +166,8 @@ int32_t dmWriteFile(const char *path, const char *name, bool deployed) {
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
if (taosRenameFile(file, realfile) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
code = 0;
dInfo("succeed to write file:%s, deloyed:%d", realfile, deployed);
_OVER:
@ -192,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;
}
@ -203,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);
@ -243,12 +239,12 @@ 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;
}
if (taosWriteFile(pFile, opts.result, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _OVER;
}
@ -262,10 +258,7 @@ static int32_t dmWriteCheckCodeFile(char *file, char *realfile, char *key, bool
goto _OVER;
}
if (taosRenameFile(file, realfile) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
encryptDebug("succeed to write checkCode file:%s", realfile);
@ -283,17 +276,17 @@ 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;
}
int32_t len = strlen(encryptCode);
if (taosWriteFile(pFile, encryptCode, len) <= 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _OVER;
}
if (taosFsyncFile(pFile) < 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _OVER;
}
@ -302,10 +295,7 @@ static int32_t dmWriteEncryptCodeFile(char *file, char *realfile, char *encryptC
goto _OVER;
}
if (taosRenameFile(file, realfile) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _OVER;
}
TAOS_CHECK_GOTO(taosRenameFile(file, realfile), NULL, _OVER);
encryptDebug("succeed to write encryptCode file:%s", realfile);
@ -325,25 +315,25 @@ 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;
}
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;
}
content = taosMemoryMalloc(size);
if (content == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
code = terrno;
goto _OVER;
}
if (taosReadFile(pFile, content, size) != size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
encryptError("failed to read dnode file:%s since %s", file, tstrerror(code));
goto _OVER;
}
@ -465,14 +455,14 @@ 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;
}
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;
}
@ -484,7 +474,7 @@ static int32_t dmReadEncryptCodeFile(char *file, char **output) {
}
if (taosReadFile(pFile, content, size) != size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
dError("failed to read dnode file:%s since %s", file, tstrerror(code));
goto _OVER;
}

View File

@ -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;
}

View File

@ -86,8 +86,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
int64_t sver = 0;
int32_t ret = taosReadFile(pFile, &sver, sizeof(int64_t));
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
TAOS_RETURN(code);
return terrno;
}
if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED;
@ -100,8 +99,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
ret = taosReadFile(pFile, &pSdb->applyIndex, sizeof(int64_t));
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
TAOS_RETURN(code);
return terrno;
}
if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED;
@ -110,8 +108,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
ret = taosReadFile(pFile, &pSdb->applyTerm, sizeof(int64_t));
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
TAOS_RETURN(code);
return terrno;
}
if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED;
@ -120,8 +117,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
ret = taosReadFile(pFile, &pSdb->applyConfig, sizeof(int64_t));
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
TAOS_RETURN(code);
return terrno;
}
if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED;
@ -132,8 +128,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
int64_t maxId = 0;
ret = taosReadFile(pFile, &maxId, sizeof(int64_t));
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
TAOS_RETURN(code);
return terrno;
}
if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED;
@ -148,8 +143,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
int64_t ver = 0;
ret = taosReadFile(pFile, &ver, sizeof(int64_t));
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
TAOS_RETURN(code);
return terrno;
}
if (ret != sizeof(int64_t)) {
code = TSDB_CODE_FILE_CORRUPTED;
@ -163,8 +157,7 @@ static int32_t sdbReadFileHead(SSdb *pSdb, TdFilePtr pFile) {
char reserve[SDB_RESERVE_SIZE] = {0};
ret = taosReadFile(pFile, reserve, sizeof(reserve));
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
TAOS_RETURN(code);
return terrno;
}
if (ret != sizeof(reserve)) {
code = TSDB_CODE_FILE_CORRUPTED;
@ -175,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) {
@ -203,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;
}
}
@ -214,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;
@ -249,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;
}
@ -274,7 +259,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
if (ret == 0) break;
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
mError("failed to read sdb file:%s since %s", file, tstrerror(code));
goto _OVER;
}
@ -305,7 +290,7 @@ static int32_t sdbReadFileImp(SSdb *pSdb) {
ret = taosReadFile(pFile, pRaw->pData, readLen);
if (ret < 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
mError("failed to read sdb file:%s since %s, ret:%" PRId64 " readLen:%d", file, tstrerror(code), ret, readLen);
goto _OVER;
}
@ -401,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);
}
@ -447,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;
@ -479,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;
@ -491,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;
@ -523,7 +508,6 @@ static int32_t sdbWriteFileImp(SSdb *pSdb, int32_t skip_type) {
if (code == 0) {
code = taosRenameFile(tmpfile, curfile);
if (code != 0) {
code = TAOS_SYSTEM_ERROR(errno);
mError("failed to write sdb file:%s since %s", curfile, tstrerror(code));
}
}
@ -654,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);
@ -664,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);
@ -693,7 +677,7 @@ int32_t sdbDoRead(SSdb *pSdb, SSdbIter *pIter, void **ppBuf, int32_t *len) {
int32_t readlen = taosReadFile(pIter->file, pBuf, maxlen);
if (readlen < 0 || readlen > maxlen) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
mError("sdbiter:%p, failed to read snapshot since %s, total:%" PRId64, pIter, tstrerror(code), pIter->total);
*ppBuf = NULL;
*len = 0;
@ -724,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);
@ -758,8 +742,8 @@ int32_t sdbStopWrite(SSdb *pSdb, SSdbIter *pIter, bool isApply, int64_t index, i
char datafile[PATH_MAX] = {0};
snprintf(datafile, sizeof(datafile), "%s%ssdb.data", pSdb->currDir, TD_DIRSEP);
if (taosRenameFile(pIter->name, datafile) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = taosRenameFile(pIter->name, datafile);
if (code != 0) {
mError("sdbiter:%p, failed to rename file %s to %s since %s", pIter, pIter->name, datafile, tstrerror(code));
goto _OVER;
}
@ -792,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);
}

View File

@ -113,12 +113,12 @@ 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);
if (n < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
if (taosFsyncFile(pFD) < 0) {
@ -178,7 +178,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);
}
}
@ -192,7 +192,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)) {
@ -203,7 +203,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)) {
@ -218,7 +218,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)) {
@ -234,7 +234,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)) {
@ -293,13 +293,13 @@ 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);
}
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);
}
@ -312,7 +312,7 @@ static int32_t load_fs(const char *fname, STsdbFS *pFS) {
}
if (taosReadFile(pFD, pData, size) < 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
(void)taosCloseFile(&pFD);
TSDB_CHECK_CODE(code, lino, _exit);
}
@ -713,10 +713,7 @@ static int32_t tsdbFSCommit(STsdb *pTsdb) {
if (!taosCheckExistFile(current_t)) goto _exit;
// rename the file
if (taosRenameFile(current_t, current) < 0) {
code = TAOS_SYSTEM_ERROR(errno);
TSDB_CHECK_CODE(code, lino, _exit);
}
TSDB_CHECK_CODE(taosRenameFile(current_t, current), lino, _exit);
// Load the new FS
code = tsdbFSCreate(&fs);

View File

@ -84,15 +84,15 @@ 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) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
if (taosFsyncFile(fp) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
_exit:
@ -111,12 +111,13 @@ 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;
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);
@ -125,7 +126,7 @@ static int32_t load_json(const char *fname, cJSON **json) {
}
if (taosReadFile(fp, data, size) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(code), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
data[size] = '\0';
@ -304,10 +305,7 @@ static int32_t commit_edit(STFileSystem *fs) {
int32_t code;
int32_t lino;
if ((code = taosRenameFile(current_t, current))) {
code = TAOS_SYSTEM_ERROR(code);
TSDB_CHECK_CODE(code, lino, _exit);
}
TSDB_CHECK_CODE(taosRenameFile(current_t, current), lino, _exit);
code = apply_commit(fs);
TSDB_CHECK_CODE(code, lino, _exit);

View File

@ -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);
}
}
@ -157,7 +157,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);
}
code = taosCalcChecksumAppend(0, pFD->pBuf, pFD->szPage);
@ -187,7 +187,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) {
@ -224,13 +224,13 @@ 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
n = taosReadFile(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);
} else if (n < pFD->szPage) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}
@ -377,12 +377,12 @@ 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);
if (ret < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
} else if (ret < nRead) {
TSDB_CHECK_CODE(code = TSDB_CODE_FILE_CORRUPTED, lino, _exit);
}

View File

@ -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);
@ -430,7 +430,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);
@ -520,7 +520,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);
@ -528,12 +528,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:
@ -619,19 +619,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:

View File

@ -181,15 +181,15 @@ 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) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
if (taosFsyncFile(pFile) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
_exit:
@ -211,8 +211,9 @@ int vnodeCommitInfo(const char *dir) {
snprintf(fname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME);
snprintf(tfname, TSDB_FILENAME_LEN, "%s%s%s", dir, TD_DIRSEP, VND_INFO_FNAME_TMP);
if (taosRenameFile(tfname, fname) < 0) {
return terrno = TAOS_SYSTEM_ERROR(errno);
int32_t code = taosRenameFile(tfname, fname);
if (code < 0) {
return code;
}
vInfo("vnode info is committed, dir:%s", dir);
@ -232,12 +233,11 @@ 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);
}
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) {
@ -245,7 +245,7 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) {
}
if (taosReadFile(pFile, pData, size) < 0) {
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
pData[size] = '\0';

View File

@ -267,14 +267,15 @@ 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);
}
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);
@ -289,7 +290,7 @@ int32_t vnodeSnapRead(SVSnapReader *pReader, uint8_t **ppData, uint32_t *nData)
if (taosReadFile(pFile, ((SSnapDataHdr *)(*ppData))->data, size) < 0) {
taosMemoryFree(*ppData);
(void)taosCloseFile(&pFile);
TSDB_CHECK_CODE(code = TAOS_SYSTEM_ERROR(errno), lino, _exit);
TSDB_CHECK_CODE(code = terrno, lino, _exit);
}
(void)taosCloseFile(&pFile);

View File

@ -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);
@ -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;
}
@ -562,7 +562,7 @@ static int32_t readBlockFromDisk(SGroupCacheOperatorInfo* pGCache, SGroupCacheDa
ret = (int32_t)taosReadFile(pFileFd->fd, *ppBuf, pBasic->bufSize);
if (ret != pBasic->bufSize) {
taosMemoryFreeClear(*ppBuf);
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _return;
}

View File

@ -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);

View File

@ -1125,7 +1125,7 @@ static int32_t tfileGetFileList(const char* path, SArray** ppResult) {
TdDirPtr pDir = taosOpenDir(path);
if (NULL == pDir) {
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), NULL, _exception);
TAOS_CHECK_GOTO(terrno, NULL, _exception);
}
TdDirEntryPtr pDirEntry;
while ((pDirEntry = taosReadDir(pDir)) != NULL) {

View File

@ -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);

View File

@ -11384,7 +11384,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;
@ -11401,7 +11401,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);
@ -14080,7 +14080,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;
}
}

View File

@ -290,13 +290,13 @@ 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;
}
char buf[256] = {0};
if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) {
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;
}
@ -367,8 +367,8 @@ int32_t remoteChkp_validAndCvtMeta(char* path, SSChkpMetaOnS3* pMeta, int64_t ch
goto _EXIT;
}
if (taosRenameFile(src, dst) != 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = taosRenameFile(src, dst);
if (code != 0) {
goto _EXIT;
}
@ -507,7 +507,6 @@ int32_t rebuildFromRemoteChkp_s3(const char* key, char* chkpPath, int64_t chkpId
if (taosIsDir(defaultPath)) {
code = taosRenameFile(defaultPath, defaultTmp);
if (code != 0) {
code = TAOS_SYSTEM_ERROR(errno);
goto _EXIT;
} else {
rename = 1;
@ -598,7 +597,7 @@ int32_t backendFileCopyFilesImpl(const char* src, const char* dst) {
// copy file to dst
TdDirPtr pDir = taosOpenDir(src);
if (pDir == NULL) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
goto _ERROR;
}
@ -1427,7 +1426,7 @@ int32_t chkpPreBuildDir(char* path, int64_t chkpId, char** chkpDir, char** chkpI
code = taosMulModeMkDir(pChkpDir, 0755, true);
if (code != 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
stError("failed to prepare checkpoint dir, path:%s, reason:%s", path, tstrerror(code));
goto _EXIT;
}
@ -1603,12 +1602,12 @@ 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;
}
if (taosReadFile(pFile, buf, sizeof(buf)) <= 0) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
stError("failed to read file to load extra info, file:%s, reason:%s", pDst, tstrerror(code));
goto _EXIT;
}
@ -1656,7 +1655,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;
}
@ -1669,7 +1668,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;
}
@ -4665,7 +4664,7 @@ int32_t dbChkpGetDelta(SDbChkp* p, int64_t chkpId, SArray* list) {
TdDirPtr pDir = taosOpenDir(p->buf);
if (pDir == NULL) {
(void)taosThreadRwlockUnlock(&p->rwLock);
return TAOS_SYSTEM_ERROR(errno);
return terrno;
}
TdDirEntryPtr de = NULL;
@ -4973,7 +4972,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;
}
@ -4986,7 +4985,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;
}
@ -5003,7 +5002,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;

View File

@ -1244,7 +1244,7 @@ static int32_t uploadCheckpointToS3(const char* id, const char* path) {
TdDirPtr pDir = taosOpenDir(path);
if (pDir == NULL) {
return TAOS_SYSTEM_ERROR(errno);
return terrno;
}
TdDirEntryPtr de = NULL;

View File

@ -271,7 +271,7 @@ int32_t snapFileReadMeta(SBackendSnapFile2* pSnapFile) {
int32_t code = 0;
TdDirPtr pDir = taosOpenDir(pSnapFile->path);
if (NULL == pDir) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
stError("%s failed to open %s, reason:%s", STREAM_STATE_TRANSFER, pSnapFile->path, tstrerror(code));
return code;
}
@ -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;
@ -696,7 +696,7 @@ int32_t streamSnapWriteImpl(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t
if (strlen(pHdr->name) == strlen(pItem->name) && strcmp(pHdr->name, pItem->name) == 0) {
int64_t bytes = taosPWriteFile(pSnapFile->fd, pHdr->data, pHdr->size, pSnapFile->offset);
if (bytes != pHdr->size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
stError("%s failed to write snap, file name:%s, reason:%s", STREAM_STATE_TRANSFER, pHdr->name, tstrerror(code));
goto _err;
} else {
@ -735,7 +735,7 @@ int32_t streamSnapWriteImpl(SStreamSnapWriter* pWriter, uint8_t* pData, uint32_t
// open fd again, let's close fd during handle errors.
if (taosPWriteFile(pSnapFile->fd, pHdr->data, pHdr->size, pSnapFile->offset) != pHdr->size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
stError("%s failed to write snap, file name:%s, reason:%s", STREAM_STATE_TRANSFER, pHdr->name, tstrerror(code));
goto _err;
}

View File

@ -150,13 +150,13 @@ 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);
}
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) {
@ -164,9 +164,7 @@ int32_t syncWriteCfgFile(SSyncNode *pNode) {
}
(void)taosCloseFile(&pFile);
if (taosRenameFile(file, realfile) != 0) {
TAOS_CHECK_EXIT(TAOS_SYSTEM_ERROR(errno));
}
TAOS_CHECK_EXIT(taosRenameFile(file, realfile));
sInfo("vgId:%d, succeed to write sync cfg file:%s, len:%d, lastConfigIndex:%" PRId64 ", changeVersion:%d",
pNode->vgId, realfile, len, pNode->raftCfg.lastConfigIndex, pNode->raftCfg.cfg.changeVersion);
@ -261,14 +259,14 @@ 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;
}
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;
}
@ -280,7 +278,7 @@ int32_t syncReadCfgFile(SSyncNode *pNode) {
}
if (taosReadFile(pFile, pData, size) != size) {
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
sError("vgId:%d, failed to read sync cfg file:%s since %s", pNode->vgId, file, tstrerror(code));
goto _OVER;
}

View File

@ -54,14 +54,14 @@ 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;
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);
@ -72,7 +72,7 @@ int32_t raftStoreReadFile(SSyncNode *pNode) {
if (taosReadFile(pFile, pData, size) != size) {
sError("vgId:%d, failed to read 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);
}
pData[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(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);
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);

View File

@ -1136,7 +1136,7 @@ int tdbPagerRestoreJournals(SPager *pPager) {
tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName);
if (pDir == NULL) {
tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno));
return TAOS_SYSTEM_ERROR(errno);
return terrno;
}
SArray *pTxnList = taosArrayInit(16, sizeof(int64_t));
@ -1182,7 +1182,7 @@ int tdbPagerRollback(SPager *pPager) {
tdbDirPtr pDir = taosOpenDir(pPager->pEnv->dbName);
if (pDir == NULL) {
tdbError("failed to open %s since %s", pPager->pEnv->dbName, strerror(errno));
return terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
while ((pDirEntry = tdbReadDir(pDir)) != NULL) {

View File

@ -39,7 +39,9 @@ int tdbGnrtFileID(tdb_fd_t fd, uint8_t *fileid, bool unique) {
int64_t stDev = 0, stIno = 0;
int32_t code = taosDevInoFile(fd, &stDev, &stIno);
return code;
if (TSDB_CODE_SUCCESS != code) {
return code;
}
memset(fileid, 0, TDB_FILE_ID_LEN);

View File

@ -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
@ -106,13 +106,13 @@ 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)) {
wError("vgId:%d, failed to read file due to %s. readSize:%" PRId64 ", file:%s", pWal->cfg.vgId, strerror(errno),
readSize, fnameStr);
TAOS_CHECK_GOTO(TAOS_SYSTEM_ERROR(errno), &lino, _err);
TAOS_CHECK_GOTO(terrno, &lino, _err);
}
char* candidate = NULL;
@ -169,15 +169,15 @@ 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)) {
wError("vgId:%d, failed to read file due to %s. offset:%" PRId64 ", extraSize:%" PRId64 ", file:%s",
pWal->cfg.vgId, strerror(errno), offset + readSize, extraSize, fnameStr);
code = TAOS_SYSTEM_ERROR(errno);
code = terrno;
break;
}
}
@ -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,
@ -403,7 +403,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
regfree(&logRegPattern);
regfree(&idxRegPattern);
wError("vgId:%d, path:%s, failed to open since %s", pWal->cfg.vgId, pWal->path, strerror(errno));
TAOS_RETURN(TSDB_CODE_FAILED);
return terrno;
}
SArray* actualLog = taosArrayInit(8, sizeof(SWalFileInfo));
@ -422,7 +422,7 @@ int32_t walCheckAndRepairMeta(SWal* pWal) {
regfree(&idxRegPattern);
(void)taosCloseDir(&pDir);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
return terrno;
}
}
}
@ -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) {
@ -518,11 +518,11 @@ 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)) {
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
}
if (walValidHeadCksum(pCkHead) != 0) {
@ -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,30 +565,30 @@ 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
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(TAOS_SYSTEM_ERROR(errno), &lino, _err);
TAOS_CHECK_GOTO(terrno, &lino, _err);
}
if (idxEntry.ver > pFileInfo->lastVer) {
@ -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);
}
}
@ -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++;
}
@ -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;
@ -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) {
@ -1028,7 +1028,7 @@ int32_t walLoadMeta(SWal* pWal) {
(void)taosCloseFile(&pFile);
taosMemoryFree(buf);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
}
// load into fileInfoSet
code = walMetaDeserialize(pWal, buf);

View File

@ -137,14 +137,14 @@ 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)) {
if (ret < 0) {
wError("vgId:%d, failed to read idx file, since %s", pReader->pWal->cfg.vgId, terrstr());
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
} else {
wError("vgId:%d, read idx file incompletely, read bytes %" PRId64 ", bytes should be %ld",
pReader->pWal->cfg.vgId, ret, 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);
@ -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;
@ -270,7 +270,7 @@ int32_t walFetchHead(SWalReader *pRead, int64_t ver) {
continue;
} else {
if (contLen < 0) {
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
} else {
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
}
@ -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++;
@ -345,7 +345,7 @@ int32_t walFetchBody(SWalReader *pRead) {
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64 ", since %s, 0x%" PRIx64, vgId,
pReadHead->version, ver, tstrerror(terrno), id);
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
} else {
wError("vgId:%d, wal fetch body error:%" PRId64 ", read request index:%" PRId64
", since file corrupted, 0x%" PRIx64,
@ -426,7 +426,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
if (contLen < 0) {
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
} else {
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
}
@ -467,7 +467,7 @@ int32_t walReadVer(SWalReader *pReader, int64_t ver) {
TAOS_UNUSED(taosThreadMutexUnlock(&pReader->mutex));
if (contLen < 0) {
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
} else {
TAOS_RETURN(TSDB_CODE_WAL_FILE_CORRUPTED);
}

View File

@ -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,21 +200,21 @@ 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);
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;
if (taosReadFile(pIdxFile, &entry, sizeof(SWalIdxEntry)) != sizeof(SWalIdxEntry)) {
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
}
walBuildLogName(pWal, walGetCurFileFirstVer(pWal), fnameStr);
@ -225,14 +225,14 @@ 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) {
// TODO
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
}
// validate offset
SWalCkHead head;
@ -240,7 +240,7 @@ int32_t walRollback(SWal *pWal, int64_t ver) {
if (size != sizeof(SWalCkHead)) {
TAOS_UNUSED(taosThreadMutexUnlock(&pWal->mutex));
TAOS_RETURN(TAOS_SYSTEM_ERROR(errno));
TAOS_RETURN(terrno);
}
code = walValidHeadCksum(&head);
@ -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);
@ -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));
@ -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));

View File

@ -145,7 +145,10 @@ int32_t taosMulMkDir(const char *dirname) {
char *pos = temp;
int32_t code = 0;
#ifdef WINDOWS
taosRealPath(dirname, temp, sizeof(temp));
code = taosRealPath(dirname, temp, sizeof(temp));
if(code != 0) {
return code;
}
if (temp[1] == ':') pos += 3;
#else
(void)strcpy(temp, dirname);
@ -207,7 +210,10 @@ int32_t taosMulModeMkDir(const char *dirname, int mode, bool checkAccess) {
char *pos = temp;
int32_t code = 0;
#ifdef WINDOWS
taosRealPath(dirname, temp, sizeof(temp));
code = taosRealPath(dirname, temp, sizeof(temp));
if(code != 0) {
return code;
}
if (temp[1] == ':') pos += 3;
#else
(void)strcpy(temp, dirname);
@ -430,6 +436,9 @@ TdDirPtr taosOpenDir(const char *dirname) {
HANDLE hFind;
TdDirPtr pDir = taosMemoryMalloc(sizeof(TdDir));
if(pDir == NULL) {
return NULL;
}
strcpy(szFind, dirname);
strcat(szFind, "\\*.*"); //利用通配符找这个目录下的所以文件,包括目录
@ -437,6 +446,8 @@ TdDirPtr taosOpenDir(const char *dirname) {
pDir->hFind = FindFirstFile(szFind, &(pDir->dirEntry.findFileData));
if (INVALID_HANDLE_VALUE == pDir->hFind) {
taosMemoryFree(pDir);
DWORD errorCode = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(errorCode);
return NULL;
}
return pDir;
@ -444,6 +455,11 @@ TdDirPtr taosOpenDir(const char *dirname) {
DIR *pDir = opendir(dirname);
if (pDir == NULL) return NULL;
TdDirPtr dirPtr = (TdDirPtr)taosMemoryMalloc(sizeof(TdDir));
if (dirPtr == NULL) {
(void)closedir(pDir);
terrno = TAOS_SYSTEM_ERROR(errno);
return NULL;
}
dirPtr->dirEntryPtr = (TdDirEntryPtr) & (dirPtr->dirEntry1);
dirPtr->pDir = pDir;
return dirPtr;
@ -506,22 +522,30 @@ char *taosGetDirEntryName(TdDirEntryPtr pDirEntry) {
}
int32_t taosCloseDir(TdDirPtr *ppDir) {
int32_t code = 0;
if (ppDir == NULL || *ppDir == NULL) {
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
#ifdef WINDOWS
FindClose((*ppDir)->hFind);
if(!FindClose((*ppDir)->hFind)) {
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
return terrno;
}
taosMemoryFree(*ppDir);
*ppDir = NULL;
return 0;
#elif defined(DARWIN)
closedir((*ppDir)->pDir);
code = closedir((*ppDir)->pDir);
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);
return terrno;
}
taosMemoryFree(*ppDir);
*ppDir = NULL;
return 0;
#else
int32_t code = closedir((DIR *)*ppDir);
code = closedir((DIR *)*ppDir);
*ppDir = NULL;
if (-1 == code) {
terrno = TAOS_SYSTEM_ERROR(errno);

View File

@ -64,7 +64,10 @@ int32_t osDefaultInit() {
}
#ifdef WINDOWS
taosWinSocketInit();
code = taosWinSocketInit();
if (code != TSDB_CODE_SUCCESS) {
return code;
}
const char *tmpDir = getenv("tmp");
if (tmpDir == NULL) {

View File

@ -132,6 +132,7 @@ int64_t taosCopyFile(const char *from, const char *to) {
if (CopyFile(from, to, 0)) {
return 1;
} else {
terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
return -1;
}
#else
@ -231,8 +232,9 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
HANDLE transactionHandle = CreateTransaction(NULL, NULL, 0, 0, 0, INFINITE, NULL);
if (transactionHandle == INVALID_HANDLE_VALUE) {
printf("failed to rename file %s to %s, reason: CreateTransaction failed.\n", oldName, newName);
return -1;
DWORD error = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(error);
return terrno;
}
BOOL result = MoveFileTransacted(oldName, newName, NULL, NULL, MOVEFILE_REPLACE_EXISTING, transactionHandle);
@ -241,18 +243,18 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
finished = CommitTransaction(transactionHandle);
if (!finished) {
DWORD error = GetLastError();
printf("failed to rename file %s to %s, reason: CommitTransaction errcode %d.\n", oldName, newName, error);
terrno = TAOS_SYSTEM_WINAPI_ERROR(error);
}
} else {
RollbackTransaction(transactionHandle);
DWORD error = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(error);
finished = false;
printf("failed to rename file %s to %s, reason: MoveFileTransacted errcode %d.\n", oldName, newName, error);
}
CloseHandle(transactionHandle);
return finished ? 0 : -1;
return finished ? 0 : terrno;
#else
int32_t code = rename(oldName, newName);
if (-1 == code) {
@ -260,7 +262,7 @@ int32_t taosRenameFile(const char *oldName, const char *newName) {
return terrno;
}
return code;
return TSDB_CODE_SUCCESS;
#endif
}
@ -294,12 +296,14 @@ int32_t taosStatFile(const char *path, int64_t *size, int32_t *mtime, int32_t *a
int32_t taosDevInoFile(TdFilePtr pFile, int64_t *stDev, int64_t *stIno) {
#ifdef WINDOWS
if (pFile == NULL || pFile->hFile == NULL) {
return -1;
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
BY_HANDLE_FILE_INFORMATION bhfi;
if (GetFileInformationByHandle(pFile->hFile, &bhfi) == FALSE) {
printf("taosFStatFile get file info fail.");
return -1;
DWORD error = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(error);
return terrno;
}
if (stDev != NULL) {
@ -395,68 +399,75 @@ HANDLE taosOpenFileNotStream(const char *path, int32_t tdFileOptions) {
if (h != INVALID_HANDLE_VALUE && (tdFileOptions & TD_FILE_APPEND) && (tdFileOptions & TD_FILE_WRITE)) {
SetFilePointer(h, 0, NULL, FILE_END);
}
// if (h == INVALID_HANDLE_VALUE) {
// DWORD dwError = GetLastError();
// LPVOID lpMsgBuf;
// FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError,
// 0,
// (LPTSTR)&lpMsgBuf, 0, NULL);
// printf("CreateFile failed with error %d: %s", dwError, (char*)lpMsgBuf);
// LocalFree(lpMsgBuf);
// }
if (h == INVALID_HANDLE_VALUE) {
DWORD dwError = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(dwError);
// LPVOID lpMsgBuf;
// FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, dwError, 0, (LPTSTR)&lpMsgBuf, 0,
// NULL);
// printf("CreateFile failed with error %d: %s", dwError, (char *)lpMsgBuf);
// LocalFree(lpMsgBuf);
}
return h;
}
int64_t taosReadFile(TdFilePtr pFile, void *buf, int64_t count) {
#if FILE_WITH_LOCK
taosThreadRwlockRdlock(&(pFile->rwlock));
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
#endif
if (pFile->hFile == NULL) {
#if FILE_WITH_LOCK
taosThreadRwlockUnlock(&(pFile->rwlock));
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif
return -1;
terrno = TSDB_CODE_INVALID_PARA;
return terrno;
}
DWORD bytesRead;
if (!ReadFile(pFile->hFile, buf, count, &bytesRead, NULL)) {
DWORD errCode = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(errCode);
bytesRead = -1;
}
#if FILE_WITH_LOCK
taosThreadRwlockUnlock(&(pFile->rwlock));
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif
return bytesRead;
}
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;
}
int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t offset) {
if (pFile == NULL) {
terrno = TSDB_CODE_INVALID_PARA;
return 0;
}
#if FILE_WITH_LOCK
taosThreadRwlockWrlock(&(pFile->rwlock));
(void)taosThreadRwlockWrlock(&(pFile->rwlock));
#endif
if (pFile->hFile == NULL) {
#if FILE_WITH_LOCK
taosThreadRwlockUnlock(&(pFile->rwlock));
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif
return 0;
}
@ -470,48 +481,57 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t
BOOL result = WriteFile(pFile->hFile, buf, count, &ret, &ol);
if (!result) {
errno = GetLastError();
terrno = TAOS_SYSTEM_WINAPI_ERROR(errno);
ret = -1;
}
#if FILE_WITH_LOCK
taosThreadRwlockUnlock(&(pFile->rwlock));
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif
return ret;
}
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
taosThreadRwlockRdlock(&(pFile->rwlock));
(void)taosThreadRwlockRdlock(&(pFile->rwlock));
#endif
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
taosThreadRwlockUnlock(&(pFile->rwlock));
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif
return liOffset.QuadPart;
}
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;
}
@ -519,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;
@ -532,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;
@ -546,7 +569,7 @@ int32_t taosLockFile(TdFilePtr pFile) {
&overlapped // overlapped structure
);
if (!fSuccess) {
return GetLastError();
return TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
}
return 0;
}
@ -560,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;
@ -579,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;
@ -587,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;
@ -596,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)) {
@ -610,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;
}
@ -637,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;
}
@ -644,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_;
@ -661,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;
}
@ -669,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;
@ -718,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;
@ -741,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
@ -826,25 +861,11 @@ int64_t taosPWriteFile(TdFilePtr pFile, const void *buf, int64_t count, int64_t
}
#endif
#ifdef WINDOWS
DWORD ret = 0;
OVERLAPPED ol = {0};
ol.OffsetHigh = (uint32_t)((offset & 0xFFFFFFFF00000000LL) >> 0x20);
ol.Offset = (uint32_t)(offset & 0xFFFFFFFFLL);
HANDLE handle = (HANDLE)_get_osfhandle(pFile->fd);
SetLastError(0);
BOOL result = WriteFile(handle, buf, count, &ret, &ol);
if (!result) {
errno = GetLastError();
ret = -1;
}
#else
int64_t ret = pwrite(pFile->fd, buf, count, offset);
if (-1 == ret) {
code = TAOS_SYSTEM_ERROR(errno);
}
#endif
#if FILE_WITH_LOCK
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif
@ -859,7 +880,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));
@ -867,14 +888,10 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
int32_t code = 0;
#ifdef WINDOWS
int64_t ret = _lseeki64(pFile->fd, offset, whence);
#else
int64_t ret = lseek(pFile->fd, offset, whence);
if (-1 == ret) {
code = TAOS_SYSTEM_ERROR(errno);
}
#endif
#if FILE_WITH_LOCK
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
@ -882,7 +899,7 @@ int64_t taosLSeekFile(TdFilePtr pFile, int64_t offset, int32_t whence) {
if (code) {
terrno = code;
return terrno;
return -1;
}
return ret;
@ -899,16 +916,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) {
@ -927,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) {
@ -960,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) {
@ -987,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};
@ -1113,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;
@ -1129,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);
@ -1224,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;
@ -1252,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;
@ -1268,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;
@ -1279,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
@ -1292,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) {
@ -1305,7 +1210,7 @@ int64_t taosPReadFile(TdFilePtr pFile, void *buf, int64_t count, int64_t offset)
if (code) {
terrno = code;
return code;
return -1;
}
return ret;
@ -1334,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) {
@ -1398,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;
@ -1406,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;
@ -1432,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
@ -1442,10 +1360,6 @@ END:
(void)taosThreadRwlockUnlock(&(pFile->rwlock));
#endif
if (code) {
terrno = code;
}
return ret;
}
@ -1637,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

View File

@ -1170,19 +1170,23 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) {
return (int)fd;
}
void taosWinSocketInit() {
int32_t taosWinSocketInit() {
#ifdef WINDOWS
static char flag = 0;
if (flag == 0) {
static int8_t flag = 0;
if (atomic_val_compare_exchange_8(&flag, 0, 1) == 0) {
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(1, 1);
if (WSAStartup(wVersionRequested, &wsaData) == 0) {
flag = 1;
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
atomic_store_8(&flag, 0);
int errorCode = WSAGetLastError();
return terrno = TAOS_SYSTEM_WINSOCKET_ERROR(errorCode);
}
}
return 0;
#else
#endif
return 0;
}
uint64_t taosHton64(uint64_t val) {

View File

@ -300,7 +300,7 @@ int32_t taosGetEmail(char *email, int32_t maxLen) {
if (taosReadFile(pFile, (void *)email, maxLen) < 0) {
taosCloseFile(&pFile);
return -1;
return terrno;
}
taosCloseFile(&pFile);

View File

@ -1227,8 +1227,8 @@ static void checkRegexCache(void* param, void* tmrId) {
if(sRegexCache.exit) {
goto _exit;
}
bool ret = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
if (!ret) {
bool stopped = taosTmrReset(checkRegexCache, REGEX_CACHE_CLEAR_TIME * 1000, param, sRegexCache.regexCacheTmr, &tmrId);
if (stopped) {
uError("failed to reset regex cache timer");
goto _exit;
}

View File

@ -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,14 +1252,19 @@ 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) {
(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;

View File

@ -850,6 +850,7 @@ static void tsSortError(void) {
taosSort(errors, sizeof(errors) / sizeof(errors[0]), sizeof(errors[0]), taosCompareTaosError);
}
static char WinAPIErrDesc[256] = {0};
const char* tstrerror(int32_t err) {
(void)taosThreadOnce(&tsErrorInit, tsSortError);
@ -860,6 +861,15 @@ const char* tstrerror(int32_t err) {
// invalid code return Unknown error
return strerror(code);
}
#ifdef WINDOWS
if ((err & 0x01ff0000) == 0x01ff0000) {
snprintf(WinAPIErrDesc, 256, "windows api error, code: 0x%08x", err & 0x0000ffff);
return WinAPIErrDesc;
} else if ((err & 0x02ff0000) == 0x02ff0000) {
snprintf(WinAPIErrDesc, 256, "windows socket error, code: 0x%08x", err & 0x0000ffff);
return WinAPIErrDesc;
}
#endif
int32_t s = 0;
int32_t e = sizeof(errors) / sizeof(errors[0]);

View File

@ -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,15 +539,15 @@ 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);
// 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);
@ -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;
}
@ -1003,7 +1002,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
@ -1030,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;
}
@ -1049,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;
}

View File

@ -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;
@ -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,14 +248,14 @@ 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;
}
void* pPage = (void*)GET_PAYLOAD_DATA(pg);
ret = (int32_t)taosReadFile(pBuf->pFile, pPage, pg->length);
if (ret != pg->length) {
ret = TAOS_SYSTEM_ERROR(errno);
ret = terrno;
return ret;
}