This commit is contained in:
xsren 2024-09-12 16:12:31 +08:00
parent 78e9bb95ac
commit 90d9784984
12 changed files with 59 additions and 34 deletions

View File

@ -129,6 +129,8 @@ extern int64_t tsRandErrDivisor;
extern int64_t tsRandErrScope; extern int64_t tsRandErrScope;
extern threadlocal bool tsEnableRandErr; extern threadlocal bool tsEnableRandErr;
#define TAOS_UNUSED(expr) (void)(expr)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -55,7 +55,7 @@ extern SDiskSpace tsLogSpace;
extern SDiskSpace tsTempSpace; extern SDiskSpace tsTempSpace;
int32_t osDefaultInit(); int32_t osDefaultInit();
void osUpdate(); int32_t osUpdate();
void osCleanup(); void osCleanup();
bool osLogSpaceAvailable(); bool osLogSpaceAvailable();

View File

@ -1871,7 +1871,6 @@ void s3EvictCache(const char *path, long object_size) {
taosDirName(dir_name); taosDirName(dir_name);
if (taosGetDiskSize((char *)dir_name, &disk_size) < 0) { if (taosGetDiskSize((char *)dir_name, &disk_size) < 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
vError("failed to get disk:%s size since %s", path, terrstr()); vError("failed to get disk:%s size since %s", path, terrstr());
return; return;
} }

View File

@ -89,9 +89,13 @@ static bool dmDataSpaceAvailable() {
} }
static int32_t dmCheckDiskSpace() { static int32_t dmCheckDiskSpace() {
osUpdate();
// availability // availability
int32_t code = 0; int32_t code = 0;
code = osUpdate();
if(code != 0) {
code = 0; // ignore the error, just log it
dError("failed to update os info since %s", tstrerror(code));
}
if (!dmDataSpaceAvailable()) { if (!dmDataSpaceAvailable()) {
code = TSDB_CODE_NO_DISKSPACE; code = TSDB_CODE_NO_DISKSPACE;
return code; return code;

View File

@ -159,7 +159,9 @@ int32_t dmRunDnode(SDnode *pDnode) {
} }
if (count == 10) { if (count == 10) {
osUpdate(); if(osUpdate() != 0) {
dError("failed to update os info");
}
count = 0; count = 0;
} else { } else {
count++; count++;

View File

@ -232,7 +232,7 @@ int metaDelJsonVarFromIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry, const SSche
} }
int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE); int32_t len = taosUcs4ToMbs((TdUcs4 *)pTagVal->pData, pTagVal->nData, val + VARSTR_HEADER_SIZE);
if (len < 0) { if (len < 0) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _exception); TAOS_CHECK_GOTO(len, NULL, _exception);
} }
memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE); memcpy(val, (uint16_t *)&len, VARSTR_HEADER_SIZE);
type = TSDB_DATA_TYPE_VARCHAR; type = TSDB_DATA_TYPE_VARCHAR;

View File

@ -33,7 +33,7 @@ int32_t tfsNewDisk(int32_t level, int32_t id, int8_t disable, const char *path,
pDisk->id = id; pDisk->id = id;
pDisk->disable = disable; pDisk->disable = disable;
if (taosGetDiskSize(pDisk->path, &pDisk->size) < 0) { if (taosGetDiskSize(pDisk->path, &pDisk->size) < 0) {
code = TAOS_SYSTEM_ERROR(errno); // TODO: refactor this line code = terrno;
TAOS_CHECK_GOTO(code, &lino, _exit); TAOS_CHECK_GOTO(code, &lino, _exit);
} }
_exit: _exit:
@ -57,7 +57,7 @@ STfsDisk *tfsFreeDisk(STfsDisk *pDisk) {
int32_t tfsUpdateDiskSize(STfsDisk *pDisk) { int32_t tfsUpdateDiskSize(STfsDisk *pDisk) {
if (taosGetDiskSize(pDisk->path, &pDisk->size) < 0) { if (taosGetDiskSize(pDisk->path, &pDisk->size) < 0) {
int32_t code = TAOS_SYSTEM_ERROR(errno); // TODO: refactor this line int32_t code = terrno;
fError("failed to get disk:%s size, level:%d id:%d since %s", pDisk->path, pDisk->level, pDisk->id, fError("failed to get disk:%s size, level:%d id:%d since %s", pDisk->path, pDisk->level, pDisk->id,
tstrerror(code)); tstrerror(code));
TAOS_RETURN(code); TAOS_RETURN(code);

View File

@ -94,16 +94,18 @@ int32_t osDefaultInit() {
return code; return code;
} }
void osUpdate() { int32_t osUpdate() {
int code = 0;
if (tsLogDir[0] != 0) { if (tsLogDir[0] != 0) {
(void)taosGetDiskSize(tsLogDir, &tsLogSpace.size); code = taosGetDiskSize(tsLogDir, &tsLogSpace.size);
} }
if (tsDataDir[0] != 0) { if (tsDataDir[0] != 0) {
(void)taosGetDiskSize(tsDataDir, &tsDataSpace.size); code = taosGetDiskSize(tsDataDir, &tsDataSpace.size);
} }
if (tsTempDir[0] != 0) { if (tsTempDir[0] != 0) {
(void)taosGetDiskSize(tsTempDir, &tsTempSpace.size); code = taosGetDiskSize(tsTempDir, &tsTempSpace.size);
} }
return code;
} }
void osCleanup() {} void osCleanup() {}

View File

@ -174,9 +174,12 @@ int64_t taosCopyFile(const char *from, const char *to) {
} }
code = taosFsyncFile(pFileTo); code = taosFsyncFile(pFileTo);
if (code != 0) {
goto _err;
}
(void)taosCloseFile(&pFileFrom); TAOS_UNUSED(taosCloseFile(&pFileFrom));
(void)taosCloseFile(&pFileTo); TAOS_UNUSED(taosCloseFile(&pFileTo));
if (code != 0) { if (code != 0) {
terrno = code; terrno = code;
@ -187,10 +190,10 @@ int64_t taosCopyFile(const char *from, const char *to) {
_err: _err:
if (pFileFrom != NULL) (void)taosCloseFile(&pFileFrom); if (pFileFrom != NULL) TAOS_UNUSED(taosCloseFile(&pFileFrom));
if (pFileTo != NULL) (void)taosCloseFile(&pFileTo); if (pFileTo != NULL) TAOS_UNUSED(taosCloseFile(&pFileTo));
/* coverity[+retval] */ /* coverity[+retval] */
(void)taosRemoveFile(to); TAOS_UNUSED(taosRemoveFile(to));
terrno = code; terrno = code;
return -1; return -1;
@ -1120,8 +1123,8 @@ int32_t taosCloseFile(TdFilePtr *ppFile) {
(void)taosThreadRwlockWrlock(&((*ppFile)->rwlock)); (void)taosThreadRwlockWrlock(&((*ppFile)->rwlock));
#endif #endif
if ((*ppFile)->fp != NULL) { if ((*ppFile)->fp != NULL) {
(void)fflush((*ppFile)->fp); TAOS_UNUSED(fflush((*ppFile)->fp));
(void)fclose((*ppFile)->fp); TAOS_UNUSED(fclose((*ppFile)->fp));
(*ppFile)->fp = NULL; (*ppFile)->fp = NULL;
} }
#ifdef WINDOWS #ifdef WINDOWS
@ -1471,7 +1474,11 @@ int32_t taosCompressFile(char *srcFileName, char *destFileName) {
while (!feof(pSrcFile->fp)) { while (!feof(pSrcFile->fp)) {
len = (int32_t)fread(data, 1, compressSize, pSrcFile->fp); len = (int32_t)fread(data, 1, compressSize, pSrcFile->fp);
if (len > 0) { if (len > 0) {
(void)gzwrite(dstFp, data, len); if(gzwrite(dstFp, data, len) == 0) {
terrno = TAOS_SYSTEM_ERROR(errno);
ret = terrno;
goto cmp_end;
}
} }
} }
@ -1481,11 +1488,11 @@ cmp_end:
(void)close(fd); (void)close(fd);
} }
if (pSrcFile) { if (pSrcFile) {
(void)taosCloseFile(&pSrcFile); TAOS_UNUSED(taosCloseFile(&pSrcFile));
} }
if (dstFp) { if (dstFp) {
(void)gzclose(dstFp); TAOS_UNUSED(gzclose(dstFp));
} }
taosMemoryFree(data); taosMemoryFree(data);

View File

@ -94,6 +94,8 @@ int32_t taosStr2int64(const char *str, int64_t *val) {
int64_t ret = strtoll(str, &endptr, 10); int64_t ret = strtoll(str, &endptr, 10);
if (errno == ERANGE && (ret == LLONG_MAX || ret == LLONG_MIN)) { if (errno == ERANGE && (ret == LLONG_MAX || ret == LLONG_MIN)) {
return TAOS_SYSTEM_ERROR(errno); return TAOS_SYSTEM_ERROR(errno);
} else if (errno == EINVAL && ret == 0) {
return TSDB_CODE_INVALID_PARA;
} else { } else {
*val = ret; *val = ret;
return 0; return 0;
@ -106,7 +108,7 @@ int32_t taosStr2int16(const char *str, int16_t *val) {
if (code) { if (code) {
return code; return code;
} else if (tmp > INT16_MAX || tmp < INT16_MIN) { } else if (tmp > INT16_MAX || tmp < INT16_MIN) {
return TSDB_CODE_INVALID_PARA; return TAOS_SYSTEM_ERROR(ERANGE);
} else { } else {
*val = (int16_t)tmp; *val = (int16_t)tmp;
return 0; return 0;
@ -119,7 +121,7 @@ int32_t taosStr2int32(const char *str, int32_t *val) {
if (code) { if (code) {
return code; return code;
} else if (tmp > INT32_MAX || tmp < INT32_MIN) { } else if (tmp > INT32_MAX || tmp < INT32_MIN) {
return TSDB_CODE_INVALID_PARA; return TAOS_SYSTEM_ERROR(ERANGE);
} else { } else {
*val = (int32_t)tmp; *val = (int32_t)tmp;
return 0; return 0;
@ -132,7 +134,7 @@ int32_t taosStr2int8(const char *str, int8_t *val) {
if (code) { if (code) {
return code; return code;
} else if (tmp > INT8_MAX || tmp < INT8_MIN) { } else if (tmp > INT8_MAX || tmp < INT8_MIN) {
return TSDB_CODE_INVALID_PARA; return TAOS_SYSTEM_ERROR(ERANGE);
} else { } else {
*val = (int8_t)tmp; *val = (int8_t)tmp;
return 0; return 0;
@ -336,17 +338,20 @@ bool taosMbsToUcs4(const char *mbs, size_t mbsLength, TdUcs4 *ucs4, int32_t ucs4
#endif #endif
} }
// if success, return the number of bytes written to mbs ( >= 0)
// otherwise return error code ( < 0)
int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) { int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) {
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV #ifdef DISALLOW_NCHAR_WITHOUT_ICONV
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n");
return -1; terrno = TSDB_CODE_APP_ERROR;
return terrno;
#else #else
int32_t idx = -1; int32_t idx = -1;
int32_t code = 0; int32_t code = 0;
iconv_t conv = taosAcquireConv(&idx, C2M); iconv_t conv = taosAcquireConv(&idx, C2M);
if ((iconv_t)-1 == conv || (iconv_t)0 == conv) { if ((iconv_t)-1 == conv || (iconv_t)0 == conv) {
return false; return TSDB_CODE_APP_ERROR;
} }
size_t ucs4_input_len = ucs4_max_len; size_t ucs4_input_len = ucs4_max_len;
@ -364,10 +369,13 @@ int32_t taosUcs4ToMbs(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs) {
#endif #endif
} }
// if success, return the number of bytes written to mbs ( >= 0)
// otherwise return error code ( < 0)
int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv) { int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t conv) {
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV #ifdef DISALLOW_NCHAR_WITHOUT_ICONV
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n");
return -1; terrno = TSDB_CODE_APP_ERROR;
return terrno;
#else #else
size_t ucs4_input_len = ucs4_max_len; size_t ucs4_input_len = ucs4_max_len;
@ -384,7 +392,8 @@ int32_t taosUcs4ToMbsEx(TdUcs4 *ucs4, int32_t ucs4_max_len, char *mbs, iconv_t c
bool taosValidateEncodec(const char *encodec) { bool taosValidateEncodec(const char *encodec) {
#ifdef DISALLOW_NCHAR_WITHOUT_ICONV #ifdef DISALLOW_NCHAR_WITHOUT_ICONV
printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n"); printf("Nchar cannot be read and written without iconv, please install iconv library and recompile.\n");
return true; terrno = TSDB_CODE_APP_ERROR;
return false;
#else #else
iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC); iconv_t cd = iconv_open(encodec, DEFAULT_UNICODE_ENCODEC);
if (cd == (iconv_t)(-1)) { if (cd == (iconv_t)(-1)) {

View File

@ -779,15 +779,15 @@ int32_t taosGetDiskSize(char *dataDir, SDiskSize *diskSize) {
return 0; return 0;
} else { } else {
// printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); // printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
// terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_WINAPI_ERROR(GetLastError());
return -1; return terrno;
} }
#elif defined(_TD_DARWIN_64) #elif defined(_TD_DARWIN_64)
struct statvfs info; struct statvfs info;
if (statvfs(dataDir, &info)) { if (statvfs(dataDir, &info)) {
// printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); // printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno));
// terrno = TAOS_SYSTEM_ERROR(errno); terrno = TAOS_SYSTEM_ERROR(errno);
return -1; return terrno;
} else { } else {
diskSize->total = info.f_blocks * info.f_frsize; diskSize->total = info.f_blocks * info.f_frsize;
diskSize->avail = info.f_bavail * info.f_frsize; diskSize->avail = info.f_bavail * info.f_frsize;

View File

@ -215,7 +215,7 @@ int32_t taosInitSlowLog() {
int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) { int32_t taosInitLog(const char *logName, int32_t maxFiles, bool tsc) {
if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0; if (atomic_val_compare_exchange_8(&tsLogInited, 0, 1) != 0) return 0;
osUpdate(); TAOS_CHECK_RETURN(osUpdate());
TAOS_CHECK_RETURN(taosInitNormalLog(logName, maxFiles)); TAOS_CHECK_RETURN(taosInitNormalLog(logName, maxFiles));
if (tsc){ if (tsc){
@ -908,7 +908,7 @@ static void *taosAsyncOutputLog(void *param) {
updateCron++; updateCron++;
taosMsleep(writeInterval); taosMsleep(writeInterval);
if (count > 1000) { if (count > 1000) {
osUpdate(); TAOS_UNUSED(osUpdate());
count = 0; count = 0;
} }