check return code
This commit is contained in:
parent
b57cd5f0d3
commit
95c0c7cedf
|
@ -162,7 +162,6 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTRslt*
|
|||
if (cond == MATCH) {
|
||||
if (c->operaType == ADD_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->del, tr->add, c->uid)
|
||||
// taosArrayPush(result, &c->uid);
|
||||
*s = kTypeValue;
|
||||
} else if (c->operaType == DEL_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->add, tr->del, c->uid)
|
||||
|
@ -818,7 +817,13 @@ static bool idxCacheIteratorNext(Iterate* itera) {
|
|||
iv->type = ct->operaType;
|
||||
iv->ver = ct->version;
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1029,7 +1029,12 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
|
|||
uint8_t* data = fstSliceData(b, &len);
|
||||
|
||||
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++) {
|
||||
uint8_t inp = data[i];
|
||||
Output res = 0;
|
||||
|
@ -1041,7 +1046,9 @@ bool fstGet(Fst* fst, FstSlice* b, Output* out) {
|
|||
(void)fstNodeGetTransitionAt(root, res, &trn);
|
||||
tOut += trn.out;
|
||||
root = fstGetNode(fst, trn.addr);
|
||||
(void)taosArrayPush(nodes, &root);
|
||||
if (taosArrayPush(nodes, &root) == NULL) {
|
||||
goto _return;
|
||||
}
|
||||
}
|
||||
if (!FST_NODE_IS_FINAL(root)) {
|
||||
goto _return;
|
||||
|
@ -1188,7 +1195,9 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
|
|||
.trans = 0,
|
||||
.out = {.null = false, .out = 0},
|
||||
.autState = automFuncs[aut->type].start(aut)}; // auto.start callback
|
||||
(void)taosArrayPush(sws->stack, &s);
|
||||
if (taosArrayPush(sws->stack, &s) == NULL) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
FstSlice* key = NULL;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
#include "indexFstDfa.h"
|
||||
#include "indexInt.h"
|
||||
#include "thash.h"
|
||||
|
||||
const static uint32_t STATE_LIMIT = 1000;
|
||||
|
@ -68,23 +69,41 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) {
|
|||
uint32_t sz = taosArrayGetSize(builder->dfa->insts);
|
||||
FstSparseSet *cur = sparSetCreate(sz);
|
||||
FstSparseSet *nxt = sparSetCreate(sz);
|
||||
if (cur == NULL || nxt == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
dfaAdd(builder->dfa, cur, 0);
|
||||
|
||||
uint32_t result;
|
||||
SArray *states = taosArrayInit(0, sizeof(uint32_t));
|
||||
if (states == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
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);
|
||||
if (seen == NULL) {
|
||||
goto _exception;
|
||||
}
|
||||
|
||||
while (taosArrayGetSize(states) != 0) {
|
||||
result = *(uint32_t *)taosArrayPop(states);
|
||||
for (int i = 0; i < 256; i++) {
|
||||
uint32_t ns, dummpy = 0;
|
||||
if (dfaBuilderRunState(builder, cur, nxt, result, i, &ns)) {
|
||||
if (taosHashGet(seen, &ns, sizeof(ns)) == NULL) {
|
||||
(void)taosHashPut(seen, &ns, sizeof(ns), &dummpy, sizeof(dummpy));
|
||||
(void)taosArrayPush(states, &ns);
|
||||
if (taosHashPut(seen, &ns, sizeof(ns), &dummpy, sizeof(dummpy)) != 0) {
|
||||
goto _exception;
|
||||
}
|
||||
if (taosArrayPush(states, &ns) == NULL) {
|
||||
goto _exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (taosArrayGetSize(builder->dfa->states) > STATE_LIMIT) {
|
||||
|
@ -96,6 +115,11 @@ FstDfa *dfaBuilderBuild(FstDfaBuilder *builder) {
|
|||
taosArrayDestroy(states);
|
||||
taosHashCleanup(seen);
|
||||
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,
|
||||
|
@ -122,7 +146,12 @@ bool dfaBuilderRunState(FstDfaBuilder *builder, FstSparseSet *cur, FstSparseSet
|
|||
}
|
||||
|
||||
bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *result) {
|
||||
int32_t code = 0;
|
||||
SArray *tinsts = taosArrayInit(4, sizeof(uint32_t));
|
||||
if (tinsts == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exception;
|
||||
}
|
||||
bool isMatch = false;
|
||||
|
||||
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) {
|
||||
continue;
|
||||
} 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) {
|
||||
isMatch = true;
|
||||
(void)taosArrayPush(tinsts, &ip);
|
||||
if (taosArrayPush(tinsts, &ip) == NULL) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (taosArrayGetSize(tinsts) == 0) {
|
||||
|
@ -149,13 +184,23 @@ bool dfaBuilderCacheState(FstDfaBuilder *builder, FstSparseSet *set, uint32_t *r
|
|||
taosArrayDestroy(tinsts);
|
||||
} else {
|
||||
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;
|
||||
(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;
|
||||
}
|
||||
return true;
|
||||
_exception:
|
||||
indexError("failed to create dfa state, code:%d", code);
|
||||
taosArrayDestroy(tinsts);
|
||||
return false;
|
||||
}
|
||||
|
||||
FstDfa *dfaCreate(SArray *insts, SArray *states) {
|
||||
|
|
|
@ -62,37 +62,6 @@ bool fstBuilderNodeEqual(FstBuilderNode* n1, FstBuilderNode* n2) {
|
|||
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
|
||||
int32_t fstBuilderNodeCloneFrom(FstBuilderNode* dst, FstBuilderNode* src) {
|
||||
if (dst == NULL || src == NULL) {
|
||||
|
|
|
@ -39,7 +39,12 @@ FstRegex *regexCreate(const char *str) {
|
|||
|
||||
for (int i = 0; i < strlen(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);
|
||||
regex->dfa = dfaBuilderBuild(builder);
|
||||
|
|
|
@ -84,7 +84,10 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) {
|
|||
|
||||
for (uint64_t i = 0; i < nCells; i++) {
|
||||
FstRegistryCell cell = {.addr = NONE_ADDRESS, .node = fstBuilderNodeDefault()};
|
||||
(void)taosArrayPush(tb, &cell);
|
||||
if (taosArrayPush(tb, &cell) == NULL) {
|
||||
fstRegistryDestroy(registry);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
registry->table = tb;
|
||||
|
|
Loading…
Reference in New Issue