From e7ebb5c2dbed47fd317a605059d41fea33461e60 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 12 May 2023 16:23:07 +0800 Subject: [PATCH] more code --- include/util/tarray.h | 4 +- .../dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h | 5 +- .../dnode/vnode/src/tsdb/dev/inc/tsdbFile.h | 5 ++ source/dnode/vnode/src/tsdb/dev/tsdbFS.c | 15 ++++- source/dnode/vnode/src/tsdb/dev/tsdbFSet.c | 65 ++++++++++++++----- 5 files changed, 72 insertions(+), 22 deletions(-) diff --git a/include/util/tarray.h b/include/util/tarray.h index 4bf24b46b9..372e69862a 100644 --- a/include/util/tarray.h +++ b/include/util/tarray.h @@ -204,9 +204,9 @@ void taosArrayClearEx(SArray* pArray, void (*fp)(void*)); void* taosArrayDestroy(SArray* pArray); -void taosArrayDestroyP(SArray* pArray, FDelete fp); +void taosArrayDestroyP(SArray* pArray, FDelete fp); -void taosArrayDestroyEx(SArray* pArray, FDelete fp); +void taosArrayDestroyEx(SArray* pArray, FDelete fp); void taosArraySwap(SArray* a, SArray* b); diff --git a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h index d7218c505d..3896e5dd00 100644 --- a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h +++ b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h @@ -36,7 +36,9 @@ typedef enum { int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json); int32_t tsdbFileSetFromJson(const cJSON *json, STFileSet *fset); -int32_t tsdbFileSetCreate(int32_t fid, STFileSet **ppSet); +int32_t tsdbFileSetInit(STFileSet *pSet); +int32_t tsdbFileSetClear(STFileSet *pSet); + int32_t tsdbFSetEdit(STFileSet *pSet, const STFileOp *pOp); int32_t tsdbFSetCmprFn(const STFileSet *pSet1, const STFileSet *pSet2); @@ -57,7 +59,6 @@ typedef struct SSttLvl { struct STFileSet { int32_t fid; - int64_t nextid; STFile *farr[TSDB_FTYPE_MAX]; // file array SSttLvl lvl0; // level 0 of .stt }; diff --git a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h index ed43384d6b..d2f62183c6 100644 --- a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h +++ b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h @@ -38,6 +38,11 @@ typedef enum { int32_t tsdbTFileToJson(const STFile *f, cJSON *json); int32_t tsdbTFileFromJson(const cJSON *json, tsdb_ftype_t ftype, STFile **f); +// create/destroy +int32_t tsdbTFileCreate(STsdb *pTsdb, STFile *pFile, STFile **f); +int32_t tsdbTFileDestroy(STFile *pFile); + +// init/clear int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile); int32_t tsdbTFileClear(STFile *pFile); diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFS.c b/source/dnode/vnode/src/tsdb/dev/tsdbFS.c index b25502fca7..aaf814e35f 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFS.c @@ -444,9 +444,22 @@ static int32_t edit_fs(STFileSystem *pFS, const SArray *aFileOp) { pSet = taosArraySearch(pFS->nstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_EQ); } + // create fset if need if (pSet == NULL) { ASSERT(op->oState.size == 0 && op->nState.size > 0); - // TODO + + STFileSet fset = {.fid = op->fid}; + int32_t idx = taosArraySearchIdx(pFS->nstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_GT); + + if (idx < 0) idx = taosArrayGetSize(pFS->nstate); + + pSet = taosArrayInsert(pFS->nstate, idx, &fset); + if (pSet == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + TSDB_CHECK_CODE(code, lino, _exit) + } + + tsdbFileSetInit(pSet); } code = tsdbFSetEdit(pSet, op); diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c b/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c index 92a0ba0dd9..ae0a1d704f 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c @@ -43,21 +43,6 @@ static int32_t stt_lvl_from_json(const cJSON *json, SSttLvl *lvl) { return 0; } -int32_t tsdbFileSetCreate(int32_t fid, struct STFileSet **ppSet) { - int32_t code = 0; - - ppSet[0] = taosMemoryCalloc(1, sizeof(struct STFileSet)); - if (ppSet[0] == NULL) { - code = TSDB_CODE_OUT_OF_MEMORY; - goto _exit; - } - ppSet[0]->fid = fid; - ppSet[0]->nextid = 1; // TODO - -_exit: - return code; -} - int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) { int32_t code = 0; @@ -126,7 +111,53 @@ int32_t tsdbFSetCmprFn(const STFileSet *pSet1, const STFileSet *pSet2) { return 0; } -int32_t tsdbFSetEdit(STFileSet *pSet, const STFileOp *pOp) { +int32_t tsdbFSetEdit(STFileSet *fset, const STFileOp *op) { + ASSERT(fset->fid == op->fid); + + if (op->oState.size == 0) { + // create + STFile *f = taosMemoryMalloc(sizeof(STFile)); + if (f == NULL) return TSDB_CODE_OUT_OF_MEMORY; + + f[0] = op->nState; + + if (f[0].type == TSDB_FTYPE_STT) { + SSttLvl *lvl; + LISTD_FOREACH(&fset->lvl0, lvl, listNode) { + if (lvl->lvl == f[0].stt.lvl) { + break; + } + } + + if (lvl == NULL) { + // TODO: create the level + } + + // TODO: add the stt file to the level + } else { + fset->farr[f[0].type] = f; + } + } else if (op->nState.size == 0) { + // delete + } else { + // modify + } + return 0; +} + +int32_t tsdbFileSetInit(STFileSet *pSet) { + for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ftype++) { + pSet->farr[ftype] = NULL; + } + + LISTD_INIT(&pSet->lvl0, listNode); + pSet->lvl0.lvl = 0; + pSet->lvl0.nstt = 0; + pSet->lvl0.fstt = NULL; + return 0; +} + +int32_t tsdbFileSetClear(STFileSet *pSet) { // TODO return 0; -} \ No newline at end of file +}