From 4b5ea55d1ae188859213601568f00fa06731b1b2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 17 May 2023 16:46:10 +0800 Subject: [PATCH] more code --- include/util/tarray.h | 2 +- .../dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h | 1 + source/dnode/vnode/src/tsdb/dev/tsdbFS.c | 22 ++++++------- source/dnode/vnode/src/tsdb/dev/tsdbFSet.c | 32 +++++++++++++++++++ source/util/src/tarray.c | 4 +-- 5 files changed, 47 insertions(+), 14 deletions(-) diff --git a/include/util/tarray.h b/include/util/tarray.h index 372e69862a..12d0bcdcda 100644 --- a/include/util/tarray.h +++ b/include/util/tarray.h @@ -138,7 +138,7 @@ size_t taosArrayGetSize(const SArray* pArray); * @param index * @param pData */ -void* taosArrayInsert(SArray* pArray, size_t index, void* pData); +void* taosArrayInsert(SArray* pArray, size_t index, const void* pData); /** * set data in array diff --git a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h index 1247bb68d9..5a744a3de9 100644 --- a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h +++ b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h @@ -36,6 +36,7 @@ typedef enum { int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json); int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet *fset); int32_t tsdbFileSetInit(STFileSet *pSet, int32_t fid); +int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet *fset2); int32_t tsdbFileSetClear(STFileSet *pSet); int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op); diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFS.c b/source/dnode/vnode/src/tsdb/dev/tsdbFS.c index 44ff89a372..74b817a231 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFS.c @@ -89,16 +89,6 @@ static int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) { return 0; } -static int32_t fs_from_json_str(const char *pData, STFileSystem *pFS) { - int32_t code = 0; - int32_t lino; - - ASSERTS(0, "TODO: Not implemented yet"); - -_exit: - return code; -} - static int32_t save_json(const cJSON *json, const char *fname) { int32_t code = 0; @@ -251,15 +241,25 @@ _exit: } static int32_t apply_commit_add_fset(STFileSystem *fs, const STFileSet *fset) { - // TODO + int32_t idx = taosArraySearchIdx(fs->cstate, fset, (__compar_fn_t)tsdbFSetCmprFn, TD_GT); + if (idx < 0) idx = taosArrayGetSize(fs->cstate); + + STFileSet *pFileSet = taosArrayInsert(fs->cstate, idx, fset); + if (pFileSet == NULL) return TSDB_CODE_OUT_OF_MEMORY; + + int32_t code = tsdbFileSetInitEx(fset, pFileSet); + if (code) return code; + return 0; } static int32_t apply_commit_del_fset(STFileSystem *fs, const STFileSet *fset) { // TODO + ASSERT(0); return 0; } static int32_t apply_commit_upd_fset(STFileSystem *fs, STFileSet *fset_from, const STFileSet *fset_to) { // TODO + ASSERT(0); return 0; } static int32_t apply_commit(STFileSystem *fs) { diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c b/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c index bd8be47ce8..57ca0f4e0d 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c @@ -258,6 +258,38 @@ int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op) { int32_t tsdbFileSetInit(STFileSet *pSet, int32_t fid) { return fset_init(pSet, fid); } +int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet *fset2) { + int32_t code; + + fset_init(fset2, fset1->fid); + for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) { + if (fset1->farr[ftype] == NULL) continue; + + code = tsdbTFileObjCreate(&fset2->farr[ftype]); + if (code) return code; + fset2->farr[ftype]->f = fset1->farr[ftype]->f; + } + + SRBTreeIter iter = tRBTreeIterCreate(&fset1->lvlTree, 1); + for (SRBTreeNode *node = tRBTreeIterNext(&iter); node; node = tRBTreeIterNext(&iter)) { + SSttLvl *lvl1 = TCONTAINER_OF(node, SSttLvl, rbtn); + SSttLvl *lvl2 = taosMemoryCalloc(1, sizeof(*lvl2)); + if (lvl2 == NULL) return TSDB_CODE_OUT_OF_MEMORY; + add_stt_lvl(fset2, lvl2); + + SRBTreeIter iter2 = tRBTreeIterCreate(&lvl1->sttTree, 1); + for (SRBTreeNode *node2 = tRBTreeIterNext(&iter2); node2; node2 = tRBTreeIterNext(&iter2)) { + STFileObj *fobj1 = TCONTAINER_OF(node2, STFileObj, rbtn); + STFileObj *fobj2; + code = tsdbTFileObjCreate(&fobj2); + if (code) return code; + fobj2->f = fobj1->f; + add_file_to_stt_lvl(lvl2, fobj2); + } + } + return 0; +} + int32_t tsdbFileSetClear(STFileSet *pSet) { // TODO return 0; diff --git a/source/util/src/tarray.c b/source/util/src/tarray.c index a7a848bd51..1901e8d89c 100644 --- a/source/util/src/tarray.c +++ b/source/util/src/tarray.c @@ -221,7 +221,7 @@ size_t taosArrayGetSize(const SArray* pArray) { return TARRAY_SIZE(pArray); } -void* taosArrayInsert(SArray* pArray, size_t index, void* pData) { +void* taosArrayInsert(SArray* pArray, size_t index, const void* pData) { if (pArray == NULL || pData == NULL) { return NULL; } @@ -488,7 +488,7 @@ void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t // order array void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param) { taosqsort(pArray->pData, pArray->size, pArray->elemSize, param, fn); -// taosArrayGetSize(pArray) > 8 ? taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param); + // taosArrayGetSize(pArray) > 8 ? taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param); } void taosArraySwap(SArray* a, SArray* b) { -- GitLab