Merge pull request #27126 from taosdata/fix/TD-31353

fix return error
This commit is contained in:
Hongze Cheng 2024-08-13 10:14:09 +08:00 committed by GitHub
commit 2ab16fd72a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 60 additions and 44 deletions

View File

@ -1222,7 +1222,7 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
SMetaFltParam *param = arg; SMetaFltParam *param = arg;
SMetaEntry oStbEntry = {0}; SMetaEntry oStbEntry = {0};
int32_t ret = -1; int32_t code = 0;
char *buf = NULL; char *buf = NULL;
void *pData = NULL; void *pData = NULL;
int nData = 0; int nData = 0;
@ -1244,34 +1244,34 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
metaRLock(pMeta); metaRLock(pMeta);
if (tdbTbGet(pMeta->pUidIdx, &param->suid, sizeof(tb_uid_t), &pData, &nData) != 0) { TAOS_CHECK_GOTO(tdbTbGet(pMeta->pUidIdx, &param->suid, sizeof(tb_uid_t), &pData, &nData), NULL, END);
goto END;
}
tbDbKey.uid = param->suid; tbDbKey.uid = param->suid;
tbDbKey.version = ((SUidIdxVal *)pData)[0].version; tbDbKey.version = ((SUidIdxVal *)pData)[0].version;
(void)tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData);
TAOS_CHECK_GOTO(tdbTbGet(pMeta->pTbDb, &tbDbKey, sizeof(tbDbKey), &pData, &nData), NULL, END);
tDecoderInit(&dc, pData, nData); tDecoderInit(&dc, pData, nData);
ret = metaDecodeEntry(&dc, &oStbEntry);
TAOS_CHECK_GOTO(metaDecodeEntry(&dc, &oStbEntry), NULL, END);
if (oStbEntry.stbEntry.schemaTag.pSchema == NULL || oStbEntry.stbEntry.schemaTag.pSchema == NULL) { if (oStbEntry.stbEntry.schemaTag.pSchema == NULL || oStbEntry.stbEntry.schemaTag.pSchema == NULL) {
ret = -1; TAOS_CHECK_GOTO(TSDB_CODE_INVALID_PARA, NULL, END);
goto END;
} }
ret = -1;
code = TSDB_CODE_INVALID_PARA;
for (int i = 0; i < oStbEntry.stbEntry.schemaTag.nCols; i++) { for (int i = 0; i < oStbEntry.stbEntry.schemaTag.nCols; i++) {
SSchema *schema = oStbEntry.stbEntry.schemaTag.pSchema + i; SSchema *schema = oStbEntry.stbEntry.schemaTag.pSchema + i;
if (schema->colId == param->cid && param->type == schema->type && (IS_IDX_ON(schema))) { if (schema->colId == param->cid && param->type == schema->type && (IS_IDX_ON(schema))) {
ret = 0; code = 0;
} else {
TAOS_CHECK_GOTO(code, NULL, END);
} }
} }
if (ret != 0) {
goto END;
}
ret = tdbTbcOpen(pMeta->pTagIdx, &pCursor->pCur, NULL); code = tdbTbcOpen(pMeta->pTagIdx, &pCursor->pCur, NULL);
if (ret != 0) { if (code != 0) {
goto END; TAOS_CHECK_GOTO(terrno, NULL, END);
} }
int32_t maxSize = 0; int32_t maxSize = 0;
@ -1280,7 +1280,6 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
if (param->val == NULL) { if (param->val == NULL) {
metaError("vgId:%d, failed to filter NULL data", TD_VID(pMeta->pVnode)); metaError("vgId:%d, failed to filter NULL data", TD_VID(pMeta->pVnode));
ret = -1;
goto END; goto END;
} else { } else {
if (IS_VAR_DATA_TYPE(param->type)) { if (IS_VAR_DATA_TYPE(param->type)) {
@ -1290,9 +1289,12 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
if (param->type == TSDB_DATA_TYPE_NCHAR) { if (param->type == TSDB_DATA_TYPE_NCHAR) {
maxSize = 4 * nTagData + 1; maxSize = 4 * nTagData + 1;
buf = taosMemoryCalloc(1, maxSize); buf = taosMemoryCalloc(1, maxSize);
if (buf == NULL) {
TAOS_CHECK_GOTO(terrno, NULL, END);
}
if (false == taosMbsToUcs4(tagData, nTagData, (TdUcs4 *)buf, maxSize, &maxSize)) { if (false == taosMbsToUcs4(tagData, nTagData, (TdUcs4 *)buf, maxSize, &maxSize)) {
ret = -1; TAOS_CHECK_GOTO(terrno, NULL, END);
goto END;
} }
tagData = buf; tagData = buf;
@ -1303,18 +1305,12 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
nTagData = tDataTypes[param->type].bytes; nTagData = tDataTypes[param->type].bytes;
} }
} }
ret = metaCreateTagIdxKey(pCursor->suid, pCursor->cid, tagData, nTagData, pCursor->type,
param->reverse ? INT64_MAX : INT64_MIN, &pKey, &nKey);
if (ret != 0) { TAOS_CHECK_GOTO(metaCreateTagIdxKey(pCursor->suid, pCursor->cid, tagData, nTagData, pCursor->type,
goto END; param->reverse ? INT64_MAX : INT64_MIN, &pKey, &nKey), NULL, END);
}
int cmp = 0; int cmp = 0;
ret = tdbTbcMoveTo(pCursor->pCur, pKey, nKey, &cmp); TAOS_CHECK_GOTO(tdbTbcMoveTo(pCursor->pCur, pKey, nKey, &cmp), 0, END);
if (ret != 0) {
goto END;
}
int count = 0; int count = 0;
int32_t valid = 0; int32_t valid = 0;
@ -1331,7 +1327,7 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal); valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal);
if (valid < 0) { if (valid < 0) {
break; code = valid;
} }
if (count > TRY_ERROR_LIMIT) { if (count > TRY_ERROR_LIMIT) {
break; break;
@ -1347,6 +1343,7 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
count++; count++;
valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur); valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur);
if (valid < 0) { if (valid < 0) {
code = valid;
break; break;
} else { } else {
continue; continue;
@ -1363,8 +1360,7 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
tuid = *(tb_uid_t *)(p->data + tDataTypes[pCursor->type].bytes); tuid = *(tb_uid_t *)(p->data + tDataTypes[pCursor->type].bytes);
} }
if (taosArrayPush(pUids, &tuid) == NULL) { if (taosArrayPush(pUids, &tuid) == NULL) {
ret = terrno; TAOS_CHECK_GOTO(terrno, NULL, END);
break;
} }
found = true; found = true;
} else { } else {
@ -1375,6 +1371,7 @@ int32_t metaFilterTableIds(void *pVnode, SMetaFltParam *arg, SArray *pUids) {
} }
valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur); valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur);
if (valid < 0) { if (valid < 0) {
code = valid;
break; break;
} }
} while (1); } while (1);
@ -1391,7 +1388,7 @@ END:
taosMemoryFree(pCursor); taosMemoryFree(pCursor);
return ret; return code;
} }
static int32_t metaGetTableTagByUid(SMeta *pMeta, int64_t suid, int64_t uid, void **tag, int32_t *len, bool lock) { static int32_t metaGetTableTagByUid(SMeta *pMeta, int64_t suid, int64_t uid, void **tag, int32_t *len, bool lock) {

View File

@ -882,11 +882,10 @@ static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *ou
if (ctx->noExec == false) { if (ctx->noExec == false) {
for (int32_t m = 0; m < node->pParameterList->length; m++) { for (int32_t m = 0; m < node->pParameterList->length; m++) {
if (node->condType == LOGIC_COND_TYPE_AND) { if (node->condType == LOGIC_COND_TYPE_AND) {
(void)taosArrayAddAll(output->result, params[m].result); if (taosArrayAddAll(output->result, params[m].result) == NULL) return terrno;
} else if (node->condType == LOGIC_COND_TYPE_OR) { } else if (node->condType == LOGIC_COND_TYPE_OR) {
(void)taosArrayAddAll(output->result, params[m].result); if (taosArrayAddAll(output->result, params[m].result) == NULL) return terrno;
} else if (node->condType == LOGIC_COND_TYPE_NOT) { } else if (node->condType == LOGIC_COND_TYPE_NOT) {
// taosArrayAddAll(output->result, params[m].result);
} }
taosArraySort(output->result, uidCompare); taosArraySort(output->result, uidCompare);
taosArrayRemoveDuplicate(output->result, uidCompare, NULL); taosArrayRemoveDuplicate(output->result, uidCompare, NULL);
@ -894,8 +893,6 @@ static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *ou
} else { } else {
for (int32_t m = 0; m < node->pParameterList->length; m++) { for (int32_t m = 0; m < node->pParameterList->length; m++) {
output->status = sifMergeCond(node->condType, output->status, params[m].status); output->status = sifMergeCond(node->condType, output->status, params[m].status);
// taosArrayDestroy(params[m].result);
// params[m].result = NULL;
} }
} }
_return: _return:
@ -904,10 +901,13 @@ _return:
} }
static EDealRes sifWalkFunction(SNode *pNode, void *context) { static EDealRes sifWalkFunction(SNode *pNode, void *context) {
SIFCtx *ctx = context;
SFunctionNode *node = (SFunctionNode *)pNode; SFunctionNode *node = (SFunctionNode *)pNode;
SIFParam output = {.result = taosArrayInit(8, sizeof(uint64_t)), .status = SFLT_COARSE_INDEX}; SIFParam output = {.result = taosArrayInit(8, sizeof(uint64_t)), .status = SFLT_COARSE_INDEX};
if (output.result == NULL) {
SIFCtx *ctx = context; ctx->code = TSDB_CODE_OUT_OF_MEMORY;
return DEAL_RES_ERROR;
}
ctx->code = sifExecFunction(node, ctx, &output); ctx->code = sifExecFunction(node, ctx, &output);
if (ctx->code != TSDB_CODE_SUCCESS) { if (ctx->code != TSDB_CODE_SUCCESS) {
sifFreeParam(&output); sifFreeParam(&output);
@ -921,11 +921,15 @@ static EDealRes sifWalkFunction(SNode *pNode, void *context) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
static EDealRes sifWalkLogic(SNode *pNode, void *context) { static EDealRes sifWalkLogic(SNode *pNode, void *context) {
SIFCtx *ctx = context;
SLogicConditionNode *node = (SLogicConditionNode *)pNode; SLogicConditionNode *node = (SLogicConditionNode *)pNode;
SIFParam output = {.result = taosArrayInit(8, sizeof(uint64_t)), .status = SFLT_COARSE_INDEX}; SIFParam output = {.result = taosArrayInit(8, sizeof(uint64_t)), .status = SFLT_COARSE_INDEX};
if (output.result == NULL) {
ctx->code = TSDB_CODE_OUT_OF_MEMORY;
return DEAL_RES_ERROR;
}
SIFCtx *ctx = context;
ctx->code = sifExecLogic(node, ctx, &output); ctx->code = sifExecLogic(node, ctx, &output);
if (ctx->code) { if (ctx->code) {
sifFreeParam(&output); sifFreeParam(&output);
@ -939,10 +943,14 @@ static EDealRes sifWalkLogic(SNode *pNode, void *context) {
return DEAL_RES_CONTINUE; return DEAL_RES_CONTINUE;
} }
static EDealRes sifWalkOper(SNode *pNode, void *context) { static EDealRes sifWalkOper(SNode *pNode, void *context) {
SIFCtx *ctx = context;
SOperatorNode *node = (SOperatorNode *)pNode; SOperatorNode *node = (SOperatorNode *)pNode;
SIFParam output = {.result = taosArrayInit(8, sizeof(uint64_t)), .status = SFLT_COARSE_INDEX}; SIFParam output = {.result = taosArrayInit(8, sizeof(uint64_t)), .status = SFLT_COARSE_INDEX};
if (output.result == NULL) {
ctx->code = TSDB_CODE_OUT_OF_MEMORY;
return DEAL_RES_ERROR;
}
SIFCtx *ctx = context;
ctx->code = sifExecOper(node, ctx, &output); ctx->code = sifExecOper(node, ctx, &output);
if (ctx->code) { if (ctx->code) {
sifFreeParam(&output); sifFreeParam(&output);
@ -1018,7 +1026,9 @@ static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) {
SIF_ERR_RET(TSDB_CODE_APP_ERROR); SIF_ERR_RET(TSDB_CODE_APP_ERROR);
} }
if (res->result != NULL) { if (res->result != NULL) {
(void)taosArrayAddAll(pDst->result, res->result); if (taosArrayAddAll(pDst->result, res->result) == NULL) {
SIF_ERR_RET(TSDB_CODE_OUT_OF_MEMORY);
}
} }
pDst->status = res->status; pDst->status = res->status;
@ -1078,6 +1088,10 @@ int32_t doFilterTag(SNode *pFilterNode, SIndexMetaArg *metaArg, SArray *result,
SFilterInfo *filter = NULL; SFilterInfo *filter = NULL;
SArray *output = taosArrayInit(8, sizeof(uint64_t)); SArray *output = taosArrayInit(8, sizeof(uint64_t));
if (output == NULL) {
return TSDB_CODE_OUT_OF_MEMORY;
}
SIFParam param = {.arg = *metaArg, .result = output, .status = SFLT_NOT_INDEX, .api = *pAPI}; SIFParam param = {.arg = *metaArg, .result = output, .status = SFLT_NOT_INDEX, .api = *pAPI};
int32_t code = sifCalculate((SNode *)pFilterNode, &param); int32_t code = sifCalculate((SNode *)pFilterNode, &param);
if (code != 0) { if (code != 0) {
@ -1090,7 +1104,12 @@ int32_t doFilterTag(SNode *pFilterNode, SIndexMetaArg *metaArg, SArray *result,
*status = st; *status = st;
} }
(void)taosArrayAddAll(result, param.result);
if (taosArrayAddAll(result, param.result) == NULL) {
sifFreeParam(&param);
return TSDB_CODE_OUT_OF_MEMORY;
}
sifFreeParam(&param); sifFreeParam(&param);
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }