diff --git a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h index 7b989184772bc034c33dfa8a7a5f66d997957812..338dc84e4a03f4e3580d7cefbf5704db94cdd717 100644 --- a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h +++ b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFS.h @@ -32,8 +32,8 @@ typedef enum { /* Exposed APIs */ // open/close -int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **ppFS, int8_t rollback); -int32_t tsdbCloseFS(STFileSystem **ppFS); +int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback); +int32_t tsdbCloseFS(STFileSystem **fs); // txn int32_t tsdbFSAllocEid(STFileSystem *pFS, int64_t *eid); int32_t tsdbFSEditBegin(STFileSystem *fs, int64_t eid, const SArray *aFileOp, EFEditT etype); @@ -45,14 +45,14 @@ int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, const STFileSet **ppFSet); /* Exposed Structs */ struct STFileSystem { STsdb *pTsdb; - int32_t state; tsem_t canEdit; + int32_t state; int64_t neid; SArray *cstate; // current state, SArray // new state EFEditT etype; int64_t eid; - SArray *nstate; // next state, SArray + SArray *nstate; // staging state, SArray }; #ifdef __cplusplus diff --git a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h index 30de41b7f749b65a71d042a8f53fb570f4863dbd..40c3de2e1d7f90394a76fda5e5f1f1bd7eb6bf62 100644 --- a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h +++ b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFSet.h @@ -52,9 +52,9 @@ struct STFileOp { typedef struct SSttLvl { SRBTreeNode rbtn; - int32_t lvl; // level - int32_t nstt; // number of .stt files on this level - STFile *fstt; // .stt files + int32_t lvl; // level + int32_t nstt; // number of .stt files on this level + SRBTree sttTree; // .stt file tree, sorted by cid } SSttLvl; struct STFileSet { diff --git a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h index b1b08d7661a04bd48cadecdcf9baf2e1947c0b91..64b7b0b2aebde93a0618c5e602905d750864b03c 100644 --- a/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h +++ b/source/dnode/vnode/src/tsdb/dev/inc/tsdbFile.h @@ -47,12 +47,9 @@ int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile); int32_t tsdbTFileClear(STFile *pFile); struct STFile { - LISTD(STFile) listNode; - int32_t ref; - char fname[TSDB_FILENAME_LEN]; tsdb_ftype_t type; - SDiskID did; + SDiskID did; // disk id int32_t fid; // file id int64_t cid; // commit id int64_t size; @@ -64,6 +61,12 @@ struct STFile { }; }; +struct STFileObj { + SRBTreeNode rbtn; + int32_t ref; + STFile f; +}; + #ifdef __cplusplus } #endif diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFS.c b/source/dnode/vnode/src/tsdb/dev/tsdbFS.c index aaf814e35fd422383214c5415df3fa7e14f815f7..287eb493917e344715cb917569a7d2970ec43867 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFS.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFS.c @@ -37,36 +37,34 @@ static const char *gCurrentFname[] = { [TSDB_FCURRENT_M] = "current.m.json", }; -static int32_t create_fs(STsdb *pTsdb, STFileSystem **ppFS) { - ppFS[0] = taosMemoryCalloc(1, sizeof(*ppFS[0])); - if (ppFS[0] == NULL) { +static int32_t create_fs(STsdb *pTsdb, STFileSystem **fs) { + fs[0] = taosMemoryCalloc(1, sizeof(*fs[0])); + if (fs[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY; + + fs[0]->cstate = taosArrayInit(16, sizeof(STFileSet)); + fs[0]->nstate = taosArrayInit(16, sizeof(STFileSet)); + if (fs[0]->cstate == NULL || fs[0]->nstate == NULL) { + taosArrayDestroy(fs[0]->nstate); + taosArrayDestroy(fs[0]->cstate); + taosMemoryFree(fs[0]); return TSDB_CODE_OUT_OF_MEMORY; } - ppFS[0]->cstate = taosArrayInit(16, sizeof(STFileSet)); - ppFS[0]->nstate = taosArrayInit(16, sizeof(STFileSet)); - if (ppFS[0]->cstate == NULL || ppFS[0]->nstate == NULL) { - taosArrayDestroy(ppFS[0]->nstate); - taosArrayDestroy(ppFS[0]->cstate); - taosMemoryFree(ppFS[0]); - return TSDB_CODE_OUT_OF_MEMORY; - } - - ppFS[0]->pTsdb = pTsdb; - ppFS[0]->state = TSDB_FS_STATE_NONE; - tsem_init(&ppFS[0]->canEdit, 0, 1); - ppFS[0]->neid = 0; + fs[0]->pTsdb = pTsdb; + fs[0]->state = TSDB_FS_STATE_NONE; + tsem_init(&fs[0]->canEdit, 0, 1); + fs[0]->neid = 0; return 0; } -static int32_t destroy_fs(STFileSystem **ppFS) { - if (ppFS[0] == NULL) return 0; - taosArrayDestroy(ppFS[0]->nstate); - taosArrayDestroy(ppFS[0]->cstate); - tsem_destroy(&ppFS[0]->canEdit); - taosMemoryFree(ppFS[0]); - ppFS[0] = NULL; +static int32_t destroy_fs(STFileSystem **fs) { + if (fs[0] == NULL) return 0; + taosArrayDestroy(fs[0]->nstate); + taosArrayDestroy(fs[0]->cstate); + tsem_destroy(&fs[0]->canEdit); + taosMemoryFree(fs[0]); + fs[0] = NULL; return 0; } @@ -398,7 +396,7 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) { code = scan_and_fix_fs(fs); TSDB_CHECK_CODE(code, lino, _exit); } else { - code = save_fs(0, fs->nstate, fCurrent); + code = save_fs(0, fs->cstate, fCurrent); TSDB_CHECK_CODE(code, lino, _exit); } @@ -470,20 +468,20 @@ _exit: return 0; } -int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **ppFS, int8_t rollback) { +int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback) { int32_t code; int32_t lino; - code = create_fs(pTsdb, ppFS); + code = create_fs(pTsdb, fs); TSDB_CHECK_CODE(code, lino, _exit); - code = open_fs(ppFS[0], rollback); + code = open_fs(fs[0], rollback); TSDB_CHECK_CODE(code, lino, _exit) _exit: if (code) { tsdbError("vgId:%d %s failed at line %d since %s", TD_VID(pTsdb->pVnode), __func__, lino, tstrerror(code)); - destroy_fs(ppFS); + destroy_fs(fs); } else { tsdbInfo("vgId:%d %s success", TD_VID(pTsdb->pVnode), __func__); } diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c b/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c index 8d362360642f5de0e5161db89aa83fb499d19fbd..fb904072b035e5e851f65c37b9953292086c8b8d 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFSet.c @@ -47,8 +47,8 @@ static int32_t add_file(STFileSet *fset, STFile *f) { if (f->type == TSDB_FTYPE_STT) { SSttLvl *lvl = NULL; // TODO - lvl->nstt++; - lvl->fstt = f; + // lvl->nstt++; + // lvl->fstt = f; } else { fset->farr[f->type] = f; } diff --git a/source/dnode/vnode/src/tsdb/dev/tsdbFile.c b/source/dnode/vnode/src/tsdb/dev/tsdbFile.c index fd9a84d9bc39d3edeab6c66c323cc08d3b686ae7..5a1ab084487456a1bc13ec82eca96ced550593f4 100644 --- a/source/dnode/vnode/src/tsdb/dev/tsdbFile.c +++ b/source/dnode/vnode/src/tsdb/dev/tsdbFile.c @@ -193,7 +193,7 @@ int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile) { pFile->cid, // g_tfile_info[pFile->type].suffix); } - pFile->ref = 1; + // pFile->ref = 1; return 0; } @@ -235,7 +235,7 @@ int32_t tsdbTFileCreate(const STFile *pFile, STFile **f) { *f[0] = *pFile; - f[0]->ref = 1; + // f[0]->ref = 1; return 0; }