提交 e7ebb5c2 编写于 作者: H Hongze Cheng

more code

上级 10a39650
......@@ -204,9 +204,9 @@ void taosArrayClearEx(SArray* pArray, void (*fp)(void*));
void* taosArrayDestroy(SArray* pArray);
void taosArrayDestroyP(SArray* pArray, FDelete fp);
void taosArrayDestroyP(SArray* pArray, FDelete fp);
void taosArrayDestroyEx(SArray* pArray, FDelete fp);
void taosArrayDestroyEx(SArray* pArray, FDelete fp);
void taosArraySwap(SArray* a, SArray* b);
......
......@@ -36,7 +36,9 @@ typedef enum {
int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json);
int32_t tsdbFileSetFromJson(const cJSON *json, STFileSet *fset);
int32_t tsdbFileSetCreate(int32_t fid, STFileSet **ppSet);
int32_t tsdbFileSetInit(STFileSet *pSet);
int32_t tsdbFileSetClear(STFileSet *pSet);
int32_t tsdbFSetEdit(STFileSet *pSet, const STFileOp *pOp);
int32_t tsdbFSetCmprFn(const STFileSet *pSet1, const STFileSet *pSet2);
......@@ -57,7 +59,6 @@ typedef struct SSttLvl {
struct STFileSet {
int32_t fid;
int64_t nextid;
STFile *farr[TSDB_FTYPE_MAX]; // file array
SSttLvl lvl0; // level 0 of .stt
};
......
......@@ -38,6 +38,11 @@ typedef enum {
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 tsdbTFileDestroy(STFile *pFile);
// init/clear
int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile);
int32_t tsdbTFileClear(STFile *pFile);
......
......@@ -444,9 +444,22 @@ static int32_t edit_fs(STFileSystem *pFS, const SArray *aFileOp) {
pSet = taosArraySearch(pFS->nstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_EQ);
}
// create fset if need
if (pSet == NULL) {
ASSERT(op->oState.size == 0 && op->nState.size > 0);
// TODO
STFileSet fset = {.fid = op->fid};
int32_t idx = taosArraySearchIdx(pFS->nstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_GT);
if (idx < 0) idx = taosArrayGetSize(pFS->nstate);
pSet = taosArrayInsert(pFS->nstate, idx, &fset);
if (pSet == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
TSDB_CHECK_CODE(code, lino, _exit)
}
tsdbFileSetInit(pSet);
}
code = tsdbFSetEdit(pSet, op);
......
......@@ -43,21 +43,6 @@ static int32_t stt_lvl_from_json(const cJSON *json, SSttLvl *lvl) {
return 0;
}
int32_t tsdbFileSetCreate(int32_t fid, struct STFileSet **ppSet) {
int32_t code = 0;
ppSet[0] = taosMemoryCalloc(1, sizeof(struct STFileSet));
if (ppSet[0] == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
goto _exit;
}
ppSet[0]->fid = fid;
ppSet[0]->nextid = 1; // TODO
_exit:
return code;
}
int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
int32_t code = 0;
......@@ -126,7 +111,53 @@ int32_t tsdbFSetCmprFn(const STFileSet *pSet1, const STFileSet *pSet2) {
return 0;
}
int32_t tsdbFSetEdit(STFileSet *pSet, const STFileOp *pOp) {
int32_t tsdbFSetEdit(STFileSet *fset, const STFileOp *op) {
ASSERT(fset->fid == op->fid);
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;
LISTD_FOREACH(&fset->lvl0, lvl, listNode) {
if (lvl->lvl == f[0].stt.lvl) {
break;
}
}
if (lvl == NULL) {
// TODO: create the level
}
// TODO: add the stt file to the level
} else {
fset->farr[f[0].type] = f;
}
} else if (op->nState.size == 0) {
// delete
} else {
// modify
}
return 0;
}
int32_t tsdbFileSetInit(STFileSet *pSet) {
for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ftype++) {
pSet->farr[ftype] = NULL;
}
LISTD_INIT(&pSet->lvl0, listNode);
pSet->lvl0.lvl = 0;
pSet->lvl0.nstt = 0;
pSet->lvl0.fstt = NULL;
return 0;
}
int32_t tsdbFileSetClear(STFileSet *pSet) {
// TODO
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.
先完成此消息的编辑!
想要评论请 注册