enh: return error code

This commit is contained in:
kailixu 2024-07-22 16:33:42 +08:00
parent cdc85d9588
commit 280c5d4b3d
23 changed files with 138 additions and 36 deletions

View File

@ -113,6 +113,8 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) {
}
static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRaw *pRaw = sdbAllocRaw(SDB_ACCT, ACCT_VER_NUMBER, sizeof(SAcctObj) + ACCT_RESERVE_SIZE);
@ -153,6 +155,8 @@ _OVER:
}
static SSdbRow *mndAcctActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SAcctObj *pAcct = NULL;
SSdbRow *pRow = NULL;

View File

@ -114,6 +114,8 @@ void mndArbGroupInitFromVgObj(SVgObj *pVgObj, SArbGroup *outGroup) {
}
SSdbRaw *mndArbGroupActionEncode(SArbGroup *pGroup) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
int32_t size = sizeof(SArbGroup) + ARBGROUP_RESERVE_SIZE;
@ -152,6 +154,8 @@ _OVER:
}
SSdbRow *mndArbGroupActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SArbGroup *pGroup = NULL;

View File

@ -144,6 +144,8 @@ int64_t mndGetClusterUpTime(SMnode *pMnode) {
}
static SSdbRaw *mndClusterActionEncode(SClusterObj *pCluster) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRaw *pRaw = sdbAllocRaw(SDB_CLUSTER, CLUSTER_VER_NUMBE, sizeof(SClusterObj) + CLUSTER_RESERVE_SIZE);
@ -172,6 +174,8 @@ _OVER:
}
static SSdbRow *mndClusterActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SClusterObj *pCluster = NULL;
SSdbRow *pRow = NULL;

View File

@ -88,6 +88,8 @@ int32_t tDeserializeSCompactObj(void *buf, int32_t bufLen, SCompactObj *pObj) {
}
SSdbRaw *mndCompactActionEncode(SCompactObj *pCompact) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_SUCCESS;
void *buf = NULL;
@ -136,6 +138,8 @@ OVER:
}
SSdbRow *mndCompactActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
SSdbRow *pRow = NULL;
SCompactObj *pCompact = NULL;
void *buf = NULL;

View File

@ -144,6 +144,8 @@ int32_t tDeserializeSCompactDetailObj(void *buf, int32_t bufLen, SCompactDetailO
}
SSdbRaw *mndCompactDetailActionEncode(SCompactDetailObj *pCompact) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_SUCCESS;
void *buf = NULL;
@ -193,9 +195,11 @@ OVER:
}
SSdbRow *mndCompactDetailActionDecode(SSdbRaw *pRaw) {
SSdbRow *pRow = NULL;
SCompactDetailObj *pCompact = NULL;
void *buf = NULL;
int32_t code = 0;
int32_t lino = 0;
SSdbRow *pRow = NULL;
SCompactDetailObj *pCompact = NULL;
void *buf = NULL;
terrno = TSDB_CODE_SUCCESS;
int8_t sver = 0;

View File

@ -700,6 +700,8 @@ _over:
}
SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
void *buf = NULL;
@ -736,6 +738,8 @@ CM_ENCODE_OVER:
}
SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
SSdbRow *pRow = NULL;
SMqConsumerObj *pConsumer = NULL;
void *buf = NULL;

View File

@ -88,6 +88,8 @@ int32_t mndInitDb(SMnode *pMnode) {
void mndCleanupDb(SMnode *pMnode) {}
SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
int32_t size = sizeof(SDbObj) + pDb->cfg.numOfRetensions * sizeof(SRetention) + DB_RESERVE_SIZE;
@ -166,6 +168,8 @@ _OVER:
}
static SSdbRow *mndDbActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SDbObj *pDb = NULL;

View File

@ -184,6 +184,8 @@ _OVER:
}
static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRaw *pRaw = sdbAllocRaw(SDB_DNODE, TSDB_DNODE_VER_NUMBER, sizeof(SDnodeObj) + TSDB_DNODE_RESERVE_SIZE);
@ -215,6 +217,8 @@ _OVER:
}
static SSdbRow *mndDnodeActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SDnodeObj *pDnode = NULL;

View File

@ -61,6 +61,8 @@ int32_t mndInitFunc(SMnode *pMnode) {
void mndCleanupFunc(SMnode *pMnode) {}
static SSdbRaw *mndFuncActionEncode(SFuncObj *pFunc) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
int32_t size = pFunc->commentSize + pFunc->codeSize + sizeof(SFuncObj) + SDB_FUNC_RESERVE_SIZE;
@ -101,6 +103,8 @@ _OVER:
}
static SSdbRow *mndFuncActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SFuncObj *pFunc = NULL;

View File

@ -207,6 +207,8 @@ void mndCleanupIdx(SMnode *pMnode) {
}
static SSdbRaw *mndIdxActionEncode(SIdxObj *pIdx) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
// int32_t size =
@ -244,6 +246,8 @@ _OVER:
}
static SSdbRow *mndIdxActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SIdxObj *pIdx = NULL;

View File

@ -127,6 +127,8 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) {
}
static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRaw *pRaw = sdbAllocRaw(SDB_MNODE, MNODE_VER_NUMBER, sizeof(SMnodeObj) + MNODE_RESERVE_SIZE);
@ -154,6 +156,8 @@ _OVER:
}
static SSdbRow *mndMnodeActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SMnodeObj *pObj = NULL;

View File

@ -75,6 +75,8 @@ void mndReleaseQnode(SMnode *pMnode, SQnodeObj *pObj) {
}
static SSdbRaw *mndQnodeActionEncode(SQnodeObj *pObj) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRaw *pRaw = sdbAllocRaw(SDB_QNODE, QNODE_VER_NUMBER, sizeof(SQnodeObj) + QNODE_RESERVE_SIZE);
@ -100,6 +102,8 @@ _OVER:
}
static SSdbRow *mndQnodeActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SQnodeObj *pObj = NULL;

View File

@ -112,6 +112,8 @@ int32_t mndInitSma(SMnode *pMnode) {
void mndCleanupSma(SMnode *pMnode) {}
static SSdbRaw *mndSmaActionEncode(SSmaObj *pSma) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
int32_t size =
@ -173,6 +175,8 @@ _OVER:
}
static SSdbRow *mndSmaActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SSmaObj *pSma = NULL;

View File

@ -79,6 +79,8 @@ void mndReleaseSnode(SMnode *pMnode, SSnodeObj *pObj) {
}
static SSdbRaw *mndSnodeActionEncode(SSnodeObj *pObj) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRaw *pRaw = sdbAllocRaw(SDB_SNODE, SNODE_VER_NUMBER, sizeof(SSnodeObj) + SNODE_RESERVE_SIZE);
@ -104,6 +106,8 @@ _OVER:
}
static SSdbRow *mndSnodeActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SSnodeObj *pObj = NULL;

View File

@ -115,6 +115,8 @@ int32_t mndInitStb(SMnode *pMnode) {
void mndCleanupStb(SMnode *pMnode) {}
SSdbRaw *mndStbActionEncode(SStbObj *pStb) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
int32_t size = sizeof(SStbObj) + (pStb->numOfColumns + pStb->numOfTags) * sizeof(SSchema) + pStb->commentLen +
@ -205,6 +207,8 @@ _OVER:
}
static SSdbRow *mndStbActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SStbObj *pStb = NULL;

View File

@ -160,6 +160,8 @@ void mndCleanupStream(SMnode *pMnode) {
}
SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;

View File

@ -177,6 +177,8 @@ STrans *doCreateTrans(SMnode *pMnode, SStreamObj *pStream, SRpcMsg *pReq, ETrnCo
}
SSdbRaw *mndStreamActionEncode(SStreamObj *pStream) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
void *buf = NULL;

View File

@ -1096,6 +1096,8 @@ end:
void mndCleanupSubscribe(SMnode *pMnode) {}
static SSdbRaw *mndSubActionEncode(SMqSubscribeObj *pSub) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
void *buf = NULL;
int32_t tlen = tEncodeSubscribeObj(NULL, pSub);
@ -1132,6 +1134,8 @@ SUB_ENCODE_OVER:
}
static SSdbRow *mndSubActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SMqSubscribeObj *pSub = NULL;

View File

@ -76,6 +76,8 @@ const char *mndTopicGetShowName(const char topic[TSDB_TOPIC_FNAME_LEN]) {
}
SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
void *swBuf = NULL;
@ -163,6 +165,8 @@ TOPIC_ENCODE_OVER:
}
SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SMqTopicObj *pTopic = NULL;

View File

@ -105,6 +105,8 @@ static int32_t mndTransGetActionsSize(SArray *pArray) {
}
static int32_t mndTransEncodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionsNum) {
int32_t code = 0;
int32_t lino = 0;
int32_t dataPos = *offset;
int8_t unused = 0;
int32_t ret = -1;
@ -142,6 +144,8 @@ _OVER:
}
SSdbRaw *mndTransEncode(STrans *pTrans) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_INVALID_MSG;
int8_t sver = taosArrayGetSize(pTrans->prepareActions) ? TRANS_VER2_NUMBER : TRANS_VER1_NUMBER;
@ -225,6 +229,8 @@ _OVER:
}
static int32_t mndTransDecodeAction(SSdbRaw *pRaw, int32_t *offset, SArray *pActions, int32_t actionNum) {
int32_t code = 0;
int32_t lino = 0;
STransAction action = {0};
int32_t dataPos = *offset;
int8_t unused = 0;
@ -279,7 +285,8 @@ _OVER:
SSdbRow *mndTransDecode(SSdbRaw *pRaw) {
terrno = TSDB_CODE_INVALID_MSG;
int32_t code = 0;
int32_t lino = 0;
SSdbRow *pRow = NULL;
STrans *pTrans = NULL;
char *pData = NULL;

View File

@ -784,11 +784,11 @@ static int32_t createIpWhiteList(void *buf, int32_t len, SIpWhiteList **ppList)
SDecoder decoder = {0};
tDecoderInit(&decoder, buf, len);
TAOS_CHECK_GOTO(tStartDecode(&decoder), &lino, _OVER), &lino, _OVER);
TAOS_CHECK_GOTO(tDecodeI32(&decoder, &num), &lino, _OVER), &lino, _OVER);
TAOS_CHECK_GOTO(tStartDecode(&decoder), &lino, _OVER);
TAOS_CHECK_GOTO(tDecodeI32(&decoder, &num), &lino, _OVER);
p = taosMemoryCalloc(1, sizeof(SIpWhiteList) + num * sizeof(SIpV4Range));
if(p == NULL) {
if (p == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
}
TAOS_CHECK_GOTO(tDerializeIpWhileList(buf, len, p), &lino, _OVER);
@ -796,7 +796,12 @@ static int32_t createIpWhiteList(void *buf, int32_t len, SIpWhiteList **ppList)
_OVER:
tEndDecode(&decoder);
tDecoderClear(&decoder);
return p;
if (code != 0) {
taosMemoryFreeClear(p);
mError("failed to create ip white list at line %d since %s", lino, tstrerror(code));
}
*ppList = p;
TAOS_RETURN(code);
}
static int32_t createDefaultIpWhiteList(SIpWhiteList **ppWhiteList) {
@ -876,7 +881,8 @@ static int32_t mndCreateDefaultUsers(SMnode *pMnode) {
}
SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
int32_t code = TSDB_CODE_OUT_OF_MEMORY;
int32_t code = 0;
int32_t lino = 0;
int32_t ipWhiteReserve =
pUser->pIpWhiteList ? (sizeof(SIpV4Range) * pUser->pIpWhiteList->num + sizeof(SIpWhiteList) + 4) : 16;
@ -989,7 +995,7 @@ SSdbRaw *mndUserActionEncode(SUserObj *pUser) {
SSdbRaw *pRaw = sdbAllocRaw(SDB_USER, USER_VER_NUMBER, size);
if (pRaw == NULL) {
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, NULL, _OVER);
TAOS_CHECK_GOTO(TSDB_CODE_OUT_OF_MEMORY, &lino, _OVER);
}
int32_t dataPos = 0;
@ -1744,21 +1750,30 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
if(pUniqueTab == NULL){
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
int32_t dummpy = 0;
int32_t dummpy = 0;
for (int i = 0; i < pCreate->numIpRanges; i++) {
SIpV4Range range = {.ip = pCreate->pIpRanges[i].ip, .mask = pCreate->pIpRanges[i].mask};
if(code = taosHashPut(pUniqueTab, &range, sizeof(range), &dummpy, sizeof(dummpy));
if ((code = taosHashPut(pUniqueTab, &range, sizeof(range), &dummpy, sizeof(dummpy))) != 0) {
taosHashCleanup(pUniqueTab);
TAOS_RETURN(code);
}
}
if ((code = taosHashPut(pUniqueTab, &defaultIpRange, sizeof(defaultIpRange), &dummpy, sizeof(dummpy))) != 0) {
taosHashCleanup(pUniqueTab);
TAOS_RETURN(code);
}
taosHashPut(pUniqueTab, &defaultIpRange, sizeof(defaultIpRange), &dummpy, sizeof(dummpy));
if (taosHashGetSize(pUniqueTab) > MND_MAX_USE_HOST) {
terrno = TSDB_CODE_MND_TOO_MANY_USER_HOST;
taosHashCleanup(pUniqueTab);
return terrno;
TAOS_RETURN(TSDB_CODE_MND_TOO_MANY_USER_HOST);
}
int32_t numOfRanges = taosHashGetSize(pUniqueTab);
SIpWhiteList *p = taosMemoryCalloc(1, sizeof(SIpWhiteList) + numOfRanges * sizeof(SIpV4Range));
if (p == NULL) {
taosHashCleanup(pUniqueTab);
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
void *pIter = taosHashIterate(pUniqueTab, NULL);
int32_t i = 0;
while (pIter) {
@ -1781,9 +1796,8 @@ static int32_t mndCreateUser(SMnode *pMnode, char *acct, SCreateUserReq *pCreate
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "create-user");
if (pTrans == NULL) {
mError("user:%s, failed to create since %s", pCreate->user, terrstr());
taosMemoryFree(userObj.pIpWhiteList);
return -1;
TAOS_RETURN(TSDB_CODE_OUT_OF_MEMORY);
}
mInfo("trans:%d, used to create user:%s", pTrans->id, pCreate->user);

View File

@ -89,6 +89,8 @@ int32_t mndInitVgroup(SMnode *pMnode) {
void mndCleanupVgroup(SMnode *pMnode) {}
SSdbRaw *mndVgroupActionEncode(SVgObj *pVgroup) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRaw *pRaw = sdbAllocRaw(SDB_VGROUP, VGROUP_VER_NUMBER, sizeof(SVgObj) + VGROUP_RESERVE_SIZE);
@ -127,6 +129,8 @@ _OVER:
}
SSdbRow *mndVgroupActionDecode(SSdbRaw *pRaw) {
int32_t code = 0;
int32_t lino = 0;
terrno = TSDB_CODE_OUT_OF_MEMORY;
SSdbRow *pRow = NULL;
SVgObj *pVgroup = NULL;

View File

@ -39,18 +39,20 @@ extern "C" {
#define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \
{ \
if (func(pRaw, dataPos, val) != 0) { \
if ((code = func(pRaw, dataPos, val)) != 0) { \
lino = __LINE__; \
goto pos; \
} \
dataPos += sizeof(type); \
}
#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \
{ \
if (sdbGetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
goto pos; \
} \
dataPos += valLen; \
#define SDB_GET_BINARY(pRaw, dataPos, val, valLen, pos) \
{ \
if ((code = sdbGetRawBinary(pRaw, dataPos, val, valLen)) != 0) { \
lino = __LINE__; \
goto pos; \
} \
dataPos += valLen; \
}
#define SDB_GET_INT64(pData, dataPos, val, pos) SDB_GET_VAL(pData, dataPos, val, pos, sdbGetRawInt64, int64_t)
@ -67,7 +69,8 @@ extern "C" {
#define SDB_SET_VAL(pRaw, dataPos, val, pos, func, type) \
{ \
if (func(pRaw, dataPos, val) != 0) { \
if ((code = func(pRaw, dataPos, val)) != 0) { \
lino = __LINE__; \
goto pos; \
} \
dataPos += sizeof(type); \
@ -79,12 +82,13 @@ extern "C" {
#define SDB_SET_INT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt8, int8_t)
#define SDB_SET_UINT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawUInt8, uint8_t)
#define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \
{ \
if (sdbSetRawBinary(pRaw, dataPos, val, valLen) != 0) { \
goto pos; \
} \
dataPos += valLen; \
#define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \
{ \
if ((code = sdbSetRawBinary(pRaw, dataPos, val, valLen)) != 0) { \
lino = __LINE__; \
goto pos; \
} \
dataPos += valLen; \
}
#define SDB_SET_RESERVE(pRaw, dataPos, valLen, pos) \
@ -93,11 +97,12 @@ extern "C" {
SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \
}
#define SDB_SET_DATALEN(pRaw, dataLen, pos) \
{ \
if (sdbSetRawDataLen(pRaw, dataLen) != 0) { \
goto pos; \
} \
#define SDB_SET_DATALEN(pRaw, dataLen, pos) \
{ \
if ((code = sdbSetRawDataLen(pRaw, dataLen)) != 0) { \
lino = __LINE__; \
goto pos; \
} \
}
typedef struct SMnode SMnode;