From 066786e681531a2e527f59a222608053f8df2877 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 15 May 2023 15:47:06 +0800 Subject: [PATCH] more code --- source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h | 1 + .../dnode/vnode/src/tsdb/dev/inc/tsdbFile.h | 4 +-- source/dnode/vnode/src/tsdb/dev/tsdbFSet.c | 30 +++++++++++-------- source/dnode/vnode/src/tsdb/dev/tsdbFile.c | 15 ++++++++++ 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h index 4f5494fdd8..7b98918477 100644 --- a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h +++ b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h @@ -49,6 +49,7 @@ struct STFileSystem { tsem_t canEdit; int64_t neid; SArray *cstate; // current state, SArray + // new state EFEditT etype; int64_t eid; SArray *nstate; // next state, SArray diff --git a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h index d2f62183c6..b1b08d7661 100644 --- a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h +++ b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h @@ -39,7 +39,7 @@ 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 tsdbTFileCreate(const STFile *pFile, STFile **f); int32_t tsdbTFileDestroy(STFile *pFile); // init/clear @@ -48,9 +48,9 @@ int32_t tsdbTFileClear(STFile *pFile); struct STFile { LISTD(STFile) listNode; - char fname[TSDB_FILENAME_LEN]; int32_t ref; + char fname[TSDB_FILENAME_LEN]; tsdb_ftype_t type; SDiskID did; int32_t fid; // file id diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c b/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c index 1199f6e45e..ad35d2cb64 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c @@ -43,6 +43,19 @@ static int32_t stt_lvl_from_json(const cJSON *json, SSttLvl *lvl) { return 0; } +static int32_t add_file(STFileSet *fset, STFile *f) { + if (f->type == TSDB_FTYPE_STT) { + SSttLvl *lvl = &fset->lvl0; // TODO + + lvl->nstt++; + lvl->fstt = f; + } else { + fset->farr[f->type] = f; + } + + return 0; +} + int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) { int32_t code = 0; @@ -118,20 +131,11 @@ int32_t tsdbFSetEdit(STFileSet *fset, const STFileOp *op) { if (op->oState.size == 0) { // create - STFile *f = taosMemoryMalloc(sizeof(STFile)); - if (f == NULL) return TSDB_CODE_OUT_OF_MEMORY; + STFile *f; + code = tsdbTFileCreate(&op->nState, &f); + if (code) return code; - f[0] = op->nState; - - if (f[0].type == TSDB_FTYPE_STT) { - SSttLvl *lvl; - // code = get_or_create_lvl(fset, f[0].stt.lvl, &lvl); - if (code) return code; - - // TODO: add the stt file to the level - } else { - fset->farr[f[0].type] = f; - } + add_file(fset, f); } else if (op->nState.size == 0) { // delete } else { diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFile.c b/source/dnode/vnode/src/tsdb/dev/tsdbFile.c index cae89e736e..fd9a84d9bc 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFile.c @@ -226,5 +226,20 @@ int32_t tsdbTFileFromJson(const cJSON *json, tsdb_ftype_t ftype, STFile **f) { f[0] = NULL; } + return 0; +} + +int32_t tsdbTFileCreate(const STFile *pFile, STFile **f) { + f[0] = taosMemoryMalloc(sizeof(*f[0])); + if (f[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY; + + *f[0] = *pFile; + + f[0]->ref = 1; + return 0; +} + +int32_t tsdbTFileDestroy(STFile *pFile) { + taosMemoryFree(pFile); return 0; } \ No newline at end of file