enh: refactor return code

This commit is contained in:
Hongze Cheng 2024-07-25 15:01:14 +08:00
parent d27227c235
commit a246e697b6
3 changed files with 48 additions and 40 deletions

View File

@ -19,6 +19,7 @@
#include "tconfig.h"
#include "tglobal.h"
#include "tjson.h"
#include "tutil.h"
#define LOG_MAX_LINE_SIZE (10024)
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 3)
@ -146,7 +147,7 @@ static int32_t taosStartLog() {
TdThreadAttr threadAttr;
taosThreadAttrInit(&threadAttr);
if (taosThreadCreate(&(tsLogObj.logHandle->asyncThread), &threadAttr, taosAsyncOutputLog, tsLogObj.logHandle) != 0) {
return -1;
return terrno;
}
taosThreadAttrDestroy(&threadAttr);
return 0;
@ -176,13 +177,13 @@ int32_t taosInitSlowLog() {
}
tsLogObj.slowHandle = taosLogBuffNew(LOG_SLOW_BUF_SIZE);
if (tsLogObj.slowHandle == NULL) return -1;
if (tsLogObj.slowHandle == NULL) return terrno;
taosUmaskFile(0);
tsLogObj.slowHandle->pFile = taosOpenFile(fullName, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_APPEND);
if (tsLogObj.slowHandle->pFile == NULL) {
printf("\nfailed to open slow log file:%s, reason:%s\n", fullName, strerror(errno));
return -1;
return TAOS_SYSTEM_ERROR(errno);
}
return 0;
@ -209,11 +210,11 @@ int32_t taosInitLog(const char *logName, int32_t maxFiles) {
taosUpdateDaylight();
tsLogObj.logHandle = taosLogBuffNew(LOG_DEFAULT_BUF_SIZE);
if (tsLogObj.logHandle == NULL) return -1;
if (taosOpenLogFile(fullName, maxFiles) < 0) return -1;
if (tsLogObj.logHandle == NULL) return terrno;
TAOS_CHECK_RETURN(taosOpenLogFile(fullName, maxFiles));
if (taosInitSlowLog() < 0) return -1;
if (taosStartLog() < 0) return -1;
TAOS_CHECK_RETURN(taosInitSlowLog());
TAOS_CHECK_RETURN(taosStartLog());
return 0;
}
@ -484,7 +485,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) {
if (tsLogObj.logHandle->pFile == NULL) {
printf("\nfailed to open log file:%s, reason:%s\n", fileName, strerror(errno));
return -1;
return TAOS_SYSTEM_ERROR(errno);
}
taosLockLogFile(tsLogObj.logHandle->pFile);
@ -492,7 +493,7 @@ static int32_t taosOpenLogFile(char *fn, int32_t maxFileNum) {
int64_t filesize = 0;
if (taosFStatFile(tsLogObj.logHandle->pFile, &filesize, NULL) < 0) {
printf("\nfailed to fstat log file:%s, reason:%s\n", fileName, strerror(errno));
return -1;
return TAOS_SYSTEM_ERROR(errno);
}
tsLogObj.lines = (int32_t)(filesize / 60);

View File

@ -516,7 +516,7 @@ static int32_t taosTmrModuleInit(void) {
tmrCtrls = taosMemoryMalloc(sizeof(tmr_ctrl_t) * tsMaxTmrCtrl);
if (tmrCtrls == NULL) {
tmrError("failed to allocate memory for timer controllers.");
return -1;
return terrno;
}
memset(&timerMap, 0, sizeof(timerMap));
@ -535,14 +535,14 @@ static int32_t taosTmrModuleInit(void) {
time_wheel_t* wheel = wheels + i;
if (taosThreadMutexInit(&wheel->mutex, NULL) != 0) {
tmrError("failed to create the mutex for wheel, reason:%s", strerror(errno));
return -1;
return terrno;
}
wheel->nextScanAt = now + wheel->resolution;
wheel->index = 0;
wheel->slots = (tmr_obj_t**)taosMemoryCalloc(wheel->size, sizeof(tmr_obj_t*));
if (wheel->slots == NULL) {
tmrError("failed to allocate wheel slots");
return -1;
return terrno;
}
timerMap.size += wheel->size;
}
@ -551,7 +551,7 @@ static int32_t taosTmrModuleInit(void) {
timerMap.slots = (timer_list_t*)taosMemoryCalloc(timerMap.size, sizeof(timer_list_t));
if (timerMap.slots == NULL) {
tmrError("failed to allocate hash map");
return -1;
return terrno;
}
tmrQhandle = taosInitScheduler(10000, taosTmrThreads, "tmr", NULL);

View File

@ -107,6 +107,9 @@ char **strsplit(char *z, const char *delim, int32_t *num) {
int32_t size = 4;
char **split = taosMemoryMalloc(POINTER_BYTES * size);
if (split == NULL) {
return NULL;
}
for (char *p = strsep(&z, delim); p != NULL; p = strsep(&z, delim)) {
size_t len = strlen(p);
@ -118,6 +121,9 @@ char **strsplit(char *z, const char *delim, int32_t *num) {
if ((*num) >= size) {
size = (size << 1);
split = taosMemoryRealloc(split, POINTER_BYTES * size);
if (split == NULL) {
return NULL;
}
ASSERTS(NULL != split, "realloc memory failed. size=%d", (int32_t)POINTER_BYTES * size);
}
}
@ -314,6 +320,9 @@ char *strbetween(char *string, char *begin, char *end) {
int32_t size = (int32_t)(_end - _begin);
if (_end != NULL && size > 0) {
result = (char *)taosMemoryCalloc(1, size);
if (result) {
return NULL;
}
memcpy(result, _begin + strlen(begin), size - +strlen(begin));
}
}
@ -503,13 +512,11 @@ int32_t parseCfgReal(const char* str, double* out) {
errno = 0;
val = taosStr2Double(str, &endPtr);
if (str == endPtr || errno == ERANGE || isnan(val)) {
terrno = TSDB_CODE_INVALID_CFG_VALUE;
return -1;
return terrno = TSDB_CODE_INVALID_CFG_VALUE;
}
while (isspace((unsigned char)*endPtr)) endPtr++;
if (*endPtr != '\0') {
terrno = TSDB_CODE_INVALID_CFG_VALUE;
return -1;
return terrno = TSDB_CODE_INVALID_CFG_VALUE;
}
*out = val;
return TSDB_CODE_SUCCESS;