more code

This commit is contained in:
Hongze Cheng 2023-05-15 15:47:06 +08:00
parent c31b1034cd
commit 066786e681
4 changed files with 35 additions and 15 deletions

View File

@ -49,6 +49,7 @@ struct STFileSystem {
tsem_t canEdit;
int64_t neid;
SArray *cstate; // current state, SArray<STFileSet>
// new state
EFEditT etype;
int64_t eid;
SArray *nstate; // next state, SArray<STFileSet>

View File

@ -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

View File

@ -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 {

View File

@ -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;
}