check return code

This commit is contained in:
yihaoDeng 2024-08-26 14:26:01 +08:00
parent b57cd5f0d3
commit 95c0c7cedf
6 changed files with 82 additions and 46 deletions

View File

@ -162,7 +162,6 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt*
if (cond == MATCH) { if (cond == MATCH) {
if (c->operaType == ADD_VALUE) { if (c->operaType == ADD_VALUE) {
INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid) INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid)
// taosArrayPush(result, &c->uid);
*s = kTypeValue; *s = kTypeValue;
} else if (c->operaType == DEL_VALUE) { } else if (c->operaType == DEL_VALUE) {
INDEX_MERGE_ADD_DEL(tr->add, tr->del, c->uid) INDEX_MERGE_ADD_DEL(tr->add, tr->del, c->uid)
@ -818,7 +817,13 @@ static bool idxCacheIteratorNext(Iterate* itera) {
iv->type = ct->operaType; iv->type = ct->operaType;
iv->ver = ct->version; iv->ver = ct->version;
iv->colVal = taosStrdup(ct->colVal); iv->colVal = taosStrdup(ct->colVal);
(void)taosArrayPush(iv->val, &ct->uid); if (iv->colVal == NULL) {
return false;
}
if (taosArrayPush(iv->val, &ct->uid) == NULL) {
taosMemoryFree(iv->colVal);
return false;
}
} }
return next; return next;
} }

View File

@ -1029,7 +1029,12 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
uint8_t* data = fstSliceData(b, &len); uint8_t* data = fstSliceData(b, &len);
SArray* nodes = (SArray*)taosArrayInit(len, sizeof(FstNode*)); SArray* nodes = (SArray*)taosArrayInit(len, sizeof(FstNode*));
(void)taosArrayPush(nodes, &root); if (nodes == NULL) {
return false;
}
if (taosArrayPush(nodes, &root) == NULL) {
goto _return;
}
for (uint32_t i = 0; i < len; i++) { for (uint32_t i = 0; i < len; i++) {
uint8_t inp = data[i]; uint8_t inp = data[i];
Output res = 0; Output res = 0;
@ -1041,7 +1046,9 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
(void)fstNodeGetTransitionAt(root, res, &trn); (void)fstNodeGetTransitionAt(root, res, &trn);
tOut += trn.out; tOut += trn.out;
root = fstGetNode(fst, trn.addr); root = fstGetNode(fst, trn.addr);
(void)taosArrayPush(nodes, &root); if (taosArrayPush(nodes, &root) == NULL) {
goto _return;
}
} }
if (!FST_NODE_IS_FINAL(root)) { if (!FST_NODE_IS_FINAL(root)) {
goto _return; goto _return;
@ -1188,7 +1195,9 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
.trans = 0, .trans = 0,
.out = {.null = false, .out = 0}, .out = {.null = false, .out = 0},
.autState = automFuncs[aut->type].start(aut)}; // auto.start callback .autState = automFuncs[aut->type].start(aut)}; // auto.start callback
(void)taosArrayPush(sws->stack, &s); if (taosArrayPush(sws->stack, &s) == NULL) {
return false;
}
return true; return true;
} }
FstSlice* key = NULL; FstSlice* key = NULL;

View File

@ -14,6 +14,7 @@
*/ */
#include "indexFstDfa.h" #include "indexFstDfa.h"
#include "indexInt.h"
#include "thash.h" #include "thash.h"
const static uint32_t STATE_LIMIT = 1000; const static uint32_t STATE_LIMIT = 1000;
@ -68,23 +69,41 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) {
uint32_t sz = taosArrayGetSize(builder->dfa->insts); uint32_t sz = taosArrayGetSize(builder->dfa->insts);
FstSparseSet *cur = sparSetCreate(sz); FstSparseSet *cur = sparSetCreate(sz);
FstSparseSet *nxt = sparSetCreate(sz); FstSparseSet *nxt = sparSetCreate(sz);
if (cur == NULL || nxt == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
dfaAdd(builder->dfa, cur, 0); dfaAdd(builder->dfa, cur, 0);
uint32_t result; uint32_t result;
SArray *states = taosArrayInit(0, sizeof(uint32_t)); SArray *states = taosArrayInit(0, sizeof(uint32_t));
if (states == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
if (dfaBuilderCacheState(builder, cur, &result)) { if (dfaBuilderCacheState(builder, cur, &result)) {
(void)taosArrayPush(states, &result); if (taosArrayPush(states, &result) == NULL) {
goto _exception;
}
} }
SHashObj *seen = taosHashInit(12, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK); SHashObj *seen = taosHashInit(12, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), false, HASH_NO_LOCK);
if (seen == NULL) {
goto _exception;
}
while (taosArrayGetSize(states) != 0) { while (taosArrayGetSize(states) != 0) {
result = *(uint32_t *)taosArrayPop(states); result = *(uint32_t *)taosArrayPop(states);
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
uint32_t ns, dummpy = 0; uint32_t ns, dummpy = 0;
if (dfaBuilderRunState(builder, cur, nxt, result, i, &ns)) { if (dfaBuilderRunState(builder, cur, nxt, result, i, &ns)) {
if (taosHashGet(seen, &ns, sizeof(ns)) == NULL) { if (taosHashGet(seen, &ns, sizeof(ns)) == NULL) {
(void)taosHashPut(seen, &ns, sizeof(ns), &dummpy, sizeof(dummpy)); if (taosHashPut(seen, &ns, sizeof(ns), &dummpy, sizeof(dummpy)) != 0) {
(void)taosArrayPush(states, &ns); goto _exception;
}
if (taosArrayPush(states, &ns) == NULL) {
goto _exception;
}
} }
} }
if (taosArrayGetSize(builder->dfa->states) > STATE_LIMIT) { if (taosArrayGetSize(builder->dfa->states) > STATE_LIMIT) {
@ -96,6 +115,11 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) {
taosArrayDestroy(states); taosArrayDestroy(states);
taosHashCleanup(seen); taosHashCleanup(seen);
return builder->dfa; return builder->dfa;
_exception:
taosArrayDestroy(states);
taosHashCleanup(seen);
indexError("failed to build dfa since %s", tstrerror(terrno));
return NULL;
} }
bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t byte, bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet *next, uint32_t state, uint8_t byte,
@ -122,7 +146,12 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet
} }
bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) { bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) {
int32_t code = 0;
SArray *tinsts = taosArrayInit(4, sizeof(uint32_t)); SArray *tinsts = taosArrayInit(4, sizeof(uint32_t));
if (tinsts == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exception;
}
bool isMatch = false; bool isMatch = false;
for (int i = 0; i < sparSetLen(set); i++) { for (int i = 0; i < sparSetLen(set); i++) {
@ -133,10 +162,16 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r
if (inst->ty == JUMP || inst->ty == SPLIT) { if (inst->ty == JUMP || inst->ty == SPLIT) {
continue; continue;
} else if (inst->ty == RANGE) { } else if (inst->ty == RANGE) {
(void)taosArrayPush(tinsts, &ip); if (taosArrayPush(tinsts, &ip) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exception;
}
} else if (inst->ty == MATCH) { } else if (inst->ty == MATCH) {
isMatch = true; isMatch = true;
(void)taosArrayPush(tinsts, &ip); if (taosArrayPush(tinsts, &ip) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exception;
}
} }
} }
if (taosArrayGetSize(tinsts) == 0) { if (taosArrayGetSize(tinsts) == 0) {
@ -149,13 +184,23 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r
taosArrayDestroy(tinsts); taosArrayDestroy(tinsts);
} else { } else {
DfaState st = {.insts = tinsts, .isMatch = isMatch}; DfaState st = {.insts = tinsts, .isMatch = isMatch};
(void)taosArrayPush(builder->dfa->states, &st); if (taosArrayPush(builder->dfa->states, &st) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exception;
}
int32_t sz = taosArrayGetSize(builder->dfa->states) - 1; int32_t sz = taosArrayGetSize(builder->dfa->states) - 1;
(void)taosHashPut(builder->cache, &tinsts, sizeof(POINTER_BYTES), &sz, sizeof(sz)); if ((code = taosHashPut(builder->cache, &tinsts, sizeof(POINTER_BYTES), &sz, sizeof(sz))) != 0) {
goto _exception;
}
*result = sz; *result = sz;
} }
return true; return true;
_exception:
indexError("failed to create dfa state, code:%d", code);
taosArrayDestroy(tinsts);
return false;
} }
FstDfa *dfaCreate(SArray *insts, SArray *states) { FstDfa *dfaCreate(SArray *insts, SArray *states) {

View File

@ -62,37 +62,6 @@ bool fstBuilderNodeEqual(FstBuilderNode* n1, FstBuilderNode* n2) {
return true; return true;
} }
#if 0
FstBuilderNode* fstBuilderNodeClone(FstBuilderNode* src) {
FstBuilderNode* node = taosMemoryMalloc(sizeof(FstBuilderNode));
if (node == NULL) {
return NULL;
}
//
size_t sz = taosArrayGetSize(src->trans);
SArray* trans = taosArrayInit(sz, sizeof(FstTransition));
if (trans == NULL) {
taosMemoryFree(node);
return NULL;
}
for (size_t i = 0; i < sz; i++) {
FstTransition* tran = taosArrayGet(src->trans, i);
if (taosArrayPush(trans, tran) != NULL) {
taosArrayDestroy(trans);
taosMemoryFree(node);
return NULL;
}
}
node->trans = trans;
node->isFinal = src->isFinal;
node->finalOutput = src->finalOutput;
return node;
}
#endif
// not destroy src, User's bussiness // not destroy src, User's bussiness
int32_t fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) { int32_t fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) {
if (dst == NULL || src == NULL) { if (dst == NULL || src == NULL) {

View File

@ -39,7 +39,12 @@ FstRegex *regexCreate(const char *str) {
for (int i = 0; i < strlen(str); i++) { for (int i = 0; i < strlen(str); i++) {
uint8_t v = str[i]; uint8_t v = str[i];
(void)taosArrayPush(insts, &v); if (taosArrayPush(insts, &v) == NULL) {
taosArrayDestroy(insts);
taosMemoryFree(regex->orig);
taosMemoryFree(regex);
return NULL;
}
} }
FstDfaBuilder *builder = dfaBuilderCreate(insts); FstDfaBuilder *builder = dfaBuilderCreate(insts);
regex->dfa = dfaBuilderBuild(builder); regex->dfa = dfaBuilderBuild(builder);

View File

@ -84,7 +84,10 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
for (uint64_t i = 0; i < nCells; i++) { for (uint64_t i = 0; i < nCells; i++) {
FstRegistryCell cell = {.addr = NONE_ADDRESS, .node = fstBuilderNodeDefault()}; FstRegistryCell cell = {.addr = NONE_ADDRESS, .node = fstBuilderNodeDefault()};
(void)taosArrayPush(tb, &cell); if (taosArrayPush(tb, &cell) == NULL) {
fstRegistryDestroy(registry);
return NULL;
}
} }
registry->table = tb; registry->table = tb;