enh: refactor return code

This commit is contained in:
kailixu 2024-07-23 18:05:56 +08:00
parent 0a8be1fd3d
commit aaf01291cf
6 changed files with 274 additions and 248 deletions

View File

@ -65,6 +65,16 @@ void *taosMemoryMallocAlign(uint32_t alignment, int64_t size);
} \ } \
} while (0) } while (0)
#define TAOS_MEMORY_REALLOC(ptr, len) \
do { \
void *tmp = taosMemoryRealloc(ptr, (len)); \
if (tmp) { \
(ptr) = tmp; \
} else { \
taosMemoryFreeClear(ptr); \
} \
} while (0)
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -157,18 +157,18 @@ static FORCE_INLINE int32_t taosGetTbHashVal(const char *tbname, int32_t tblen,
return (terrno = (code)); \ return (terrno = (code)); \
} while (0) } while (0)
#define TAOS_CHECK_RETURN(CMD) \ #define TAOS_CHECK_RETURN(CMD) \
do { \ do { \
int32_t code = (CMD); \ int32_t code = (CMD); \
if (code != TSDB_CODE_SUCCESS) { \ if (code < TSDB_CODE_SUCCESS) { \
TAOS_RETURN(code); \ TAOS_RETURN(code); \
} \ } \
} while (0) } while (0)
#define TAOS_CHECK_GOTO(CMD, LINO, LABEL) \ #define TAOS_CHECK_GOTO(CMD, LINO, LABEL) \
do { \ do { \
code = (CMD); \ code = (CMD); \
if (code != TSDB_CODE_SUCCESS) { \ if (code < TSDB_CODE_SUCCESS) { \
if (LINO) { \ if (LINO) { \
*((int32_t *)(LINO)) = __LINE__; \ *((int32_t *)(LINO)) = __LINE__; \
} \ } \

View File

@ -535,7 +535,7 @@ int32_t tdSTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow **ppRow, int8_t r
_exit: _exit:
taosMemoryFreeClear(varBuf); taosMemoryFreeClear(varBuf);
if (code != 0) { if (code < 0) {
if (isAlloc) { if (isAlloc) {
taosMemoryFreeClear(*ppRow); taosMemoryFreeClear(*ppRow);
} }

View File

@ -182,7 +182,7 @@ int32_t dmInitVars(SDnode *pDnode) {
code = 0; code = 0;
strncpy(tsEncryptKey, tsAuthCode, 16); strncpy(tsEncryptKey, tsAuthCode, 16);
if(code != 0) { if (code != 0) {
if(code == -1){ if(code == -1){
terrno = TSDB_CODE_DNODE_NO_ENCRYPT_KEY; terrno = TSDB_CODE_DNODE_NO_ENCRYPT_KEY;
dError("machine code changed, can't get crypt key"); dError("machine code changed, can't get crypt key");

View File

@ -735,8 +735,9 @@ static int32_t mndSetCreateDbUndoActions(SMnode *pMnode, STrans *pTrans, SDbObj
} }
static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, SUserObj *pUser) { static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate, SUserObj *pUser) {
int32_t code = -1; int32_t code = 0;
SDbObj dbObj = {0}; SUserObj newUserObj = {0};
SDbObj dbObj = {0};
memcpy(dbObj.name, pCreate->db, TSDB_DB_FNAME_LEN); memcpy(dbObj.name, pCreate->db, TSDB_DB_FNAME_LEN);
memcpy(dbObj.acct, pUser->acct, TSDB_USER_LEN); memcpy(dbObj.acct, pUser->acct, TSDB_USER_LEN);
dbObj.createdTime = taosGetTimestampMs(); dbObj.createdTime = taosGetTimestampMs();
@ -816,7 +817,7 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
} }
// add database privileges for user // add database privileges for user
SUserObj newUserObj = {0}, *pNewUserDuped = NULL; SUserObj *pNewUserDuped = NULL;
if (!pUser->superUser) { if (!pUser->superUser) {
TAOS_CHECK_GOTO(mndUserDupObj(pUser, &newUserObj), NULL, _OVER); TAOS_CHECK_GOTO(mndUserDupObj(pUser, &newUserObj), NULL, _OVER);
taosHashPut(newUserObj.readDbs, dbObj.name, strlen(dbObj.name) + 1, dbObj.name, TSDB_FILENAME_LEN); taosHashPut(newUserObj.readDbs, dbObj.name, strlen(dbObj.name) + 1, dbObj.name, TSDB_FILENAME_LEN);
@ -845,8 +846,6 @@ static int32_t mndCreateDb(SMnode *pMnode, SRpcMsg *pReq, SCreateDbReq *pCreate,
TAOS_CHECK_GOTO(mndSetCreateDbUndoActions(pMnode, pTrans, &dbObj, pVgroups), NULL, _OVER); TAOS_CHECK_GOTO(mndSetCreateDbUndoActions(pMnode, pTrans, &dbObj, pVgroups), NULL, _OVER);
TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER); TAOS_CHECK_GOTO(mndTransPrepare(pMnode, pTrans), NULL, _OVER);
code = 0;
_OVER: _OVER:
taosMemoryFree(pVgroups); taosMemoryFree(pVgroups);
mndUserFreeObj(&newUserObj); mndUserFreeObj(&newUserObj);

File diff suppressed because it is too large Load Diff