提交 066786e6 编写于 作者: H Hongze Cheng

more code

上级 c31b1034
......@@ -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>
......
......@@ -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
......
......@@ -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;
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;
STFile *f;
code = tsdbTFileCreate(&op->nState, &f);
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 {
......
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册