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

View File

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