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; tsem_t canEdit;
int64_t neid; int64_t neid;
SArray *cstate; // current state, SArray<STFileSet> SArray *cstate; // current state, SArray<STFileSet>
// new state
EFEditT etype; EFEditT etype;
int64_t eid; int64_t eid;
SArray *nstate; // next state, SArray<STFileSet> 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); int32_t tsdbTFileFromJson(const cJSON *json, tsdb_ftype_t ftype, STFile **f);
// create/destroy // create/destroy
int32_t tsdbTFileCreate(STsdb *pTsdb, STFile *pFile, STFile **f); int32_t tsdbTFileCreate(const STFile *pFile, STFile **f);
int32_t tsdbTFileDestroy(STFile *pFile); int32_t tsdbTFileDestroy(STFile *pFile);
// init/clear // init/clear
@ -48,9 +48,9 @@ int32_t tsdbTFileClear(STFile *pFile);
struct STFile { struct STFile {
LISTD(STFile) listNode; LISTD(STFile) listNode;
char fname[TSDB_FILENAME_LEN];
int32_t ref; int32_t ref;
char fname[TSDB_FILENAME_LEN];
tsdb_ftype_t type; tsdb_ftype_t type;
SDiskID did; SDiskID did;
int32_t fid; // file id 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; 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 tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
int32_t code = 0; int32_t code = 0;
@ -118,20 +131,11 @@ int32_t tsdbFSetEdit(STFileSet *fset, const STFileOp *op) {
if (op->oState.size == 0) { if (op->oState.size == 0) {
// create // create
STFile *f = taosMemoryMalloc(sizeof(STFile)); STFile *f;
if (f == NULL) return TSDB_CODE_OUT_OF_MEMORY; code = tsdbTFileCreate(&op->nState, &f);
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; if (code) return code;
// TODO: add the stt file to the level add_file(fset, f);
} else {
fset->farr[f[0].type] = f;
}
} else if (op->nState.size == 0) { } else if (op->nState.size == 0) {
// delete // delete
} else { } else {

View File

@ -228,3 +228,18 @@ int32_t tsdbTFileFromJson(const cJSON *json, tsdb_ftype_t ftype, STFile **f) {
return 0; 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;
}