diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 1230fe17ff..04e9b8b4ac 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -20,6 +20,7 @@ #include "tarray.h" #include "index_fst_util.h" #include "index_fst_registry.h" +#include "index_fst_counting_writer.h" typedef struct FstNode FstNode; @@ -35,7 +36,6 @@ typedef struct FstRange { typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal} State; typedef enum { Included, Excluded, Unbounded} FstBound; -typedef uint32_t CheckSummer; /* @@ -60,11 +60,6 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *node, FstSlice bs, Output o uint64_t fstUnFinishedNodesFindCommPrefix(FstUnFinishedNodes *node, FstSlice bs); uint64_t FstUnFinishedNodesFindCommPreifxAndSetOutput(FstUnFinishedNodes *node, FstSlice bs, Output in, Output *out); -typedef struct FstCountingWriter { - void* wtr; // wrap any writer that counts and checksum bytes written - uint64_t count; - CheckSummer summer; -} FstCountingWriter; typedef struct FstBuilder { FstCountingWriter wtr; // The FST raw data is written directly to `wtr`. diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 2974e7f9b5..cf8a6eabfe 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -275,8 +275,6 @@ bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr } - - FstBuilder *fstBuilderCreate(void *w, FstType ty) { FstBuilder *b = malloc(sizeof(FstBuilder)); if (NULL == b) { return b; } diff --git a/source/libs/index/src/index_fst_node.c b/source/libs/index/src/index_fst_node.c index 23af4a4a4b..d7aa1e5041 100644 --- a/source/libs/index/src/index_fst_node.c +++ b/source/libs/index/src/index_fst_node.c @@ -26,14 +26,13 @@ FstBuilderNode *fstBuilderNodeClone(FstBuilderNode *src) { FstBuilderNode *node = malloc(sizeof(FstBuilderNode)); if (node == NULL) { return NULL; } - + // size_t sz = taosArrayGetSize(src->trans); SArray *trans = taosArrayInit(sz, sizeof(FstTransition)); for (size_t i = 0; i < sz; i++) { FstTransition *tran = taosArrayGet(src->trans, i); - FstTransition t = *tran; - taosArrayPush(trans, &t); + taosArrayPush(trans, tran); } node->trans = trans; @@ -47,9 +46,11 @@ void fstBuilderNodeCloneFrom(FstBuilderNode *dst, FstBuilderNode *src) { if (dst == NULL || src == NULL) { return; } dst->isFinal = src->isFinal; - dst->finalOutput = src->finalOutput ; - dst->trans = src->trans; + dst->finalOutput = src->finalOutput; + // avoid mem leak + taosArrayDestroy(dst->trans); + dst->trans = src->trans; src->trans = NULL; } diff --git a/source/libs/index/src/index_fst_registry.c b/source/libs/index/src/index_fst_registry.c index 5d6c7b1712..718832c803 100644 --- a/source/libs/index/src/index_fst_registry.c +++ b/source/libs/index/src/index_fst_registry.c @@ -32,6 +32,7 @@ uint64_t fstRegistryHash(FstRegistry *registry, FstBuilderNode *bNode) { h = (h ^ (uint64_t)(trn->addr))* FNV_PRIME; } return h %(registry->tableSize); + } static void fstRegistryCellSwap(SArray *arr, uint32_t a, uint32_t b) { size_t sz = taosArrayGetSize(arr); @@ -72,10 +73,14 @@ FstRegistry* fstRegistryCreate(uint64_t tableSize, uint64_t mruSize) { uint64_t nCells = tableSize * mruSize; SArray* tb = (SArray *)taosArrayInit(nCells, sizeof(FstRegistryCell)); + if (NULL == tb) { + free(registry); + return NULL; + } + for (uint64_t i = 0; i < nCells; i++) { - FstRegistryCell *cell = taosArrayGet(tb, i); - cell->addr = NONE_ADDRESS; - cell->node = fstBuilderNodeDefault(); + FstRegistryCell cell = {.addr = NONE_ADDRESS, .node = fstBuilderNodeDefault()}; + taosArrayPush(tb, &cell); } registry->table = tb; @@ -98,11 +103,9 @@ FstRegistryEntry *fstRegistryGetEntry(FstRegistry *registry, FstBuilderNode *bNo //cell->isNode && if (cell->addr != NONE_ADDRESS && cell->node == bNode) { entry->state = FOUND; - entry->addr = cell->addr ; + entry->addr = cell->addr ; return entry; } else { - // clone from bNode, refactor later - // fstBuilderNodeCloneFrom(cell->node, bNode); entry->state = NOTFOUND; entry->cell = cell; // copy or not