more code
This commit is contained in:
parent
7cb10a2b70
commit
0b17e3fe1c
|
@ -35,11 +35,9 @@ typedef enum {
|
|||
|
||||
int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json);
|
||||
int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet *fset);
|
||||
|
||||
int32_t tsdbFileSetInit(STFileSet *pSet);
|
||||
int32_t tsdbFileSetInit(STFileSet *pSet, int32_t fid);
|
||||
int32_t tsdbFileSetClear(STFileSet *pSet);
|
||||
|
||||
int32_t tsdbFSetEdit(STFileSet *pSet, const STFileOp *pOp);
|
||||
int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op);
|
||||
|
||||
int32_t tsdbFSetCmprFn(const STFileSet *pSet1, const STFileSet *pSet2);
|
||||
|
||||
|
@ -51,7 +49,7 @@ struct STFileOp {
|
|||
};
|
||||
|
||||
typedef struct SSttLvl {
|
||||
int32_t lvl; // level
|
||||
int32_t level; // level
|
||||
int32_t nstt; // number of .stt files on this level
|
||||
SRBTree sttTree; // .stt file tree, sorted by cid
|
||||
SRBTreeNode rbtn;
|
||||
|
|
|
@ -409,37 +409,33 @@ static int32_t fset_cmpr_fn(const struct STFileSet *pSet1, const struct STFileSe
|
|||
}
|
||||
|
||||
static int32_t edit_fs(STFileSystem *pFS, const SArray *aFileOp) {
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
|
||||
int32_t code = 0;
|
||||
int32_t lino = 0;
|
||||
STFileSet *pSet = NULL;
|
||||
|
||||
for (int32_t iop = 0; iop < taosArrayGetSize(aFileOp); iop++) {
|
||||
struct STFileOp *op = taosArrayGet(aFileOp, iop);
|
||||
|
||||
if (pSet == NULL || pSet->fid != op->fid) {
|
||||
STFileSet fset = {.fid = op->fid};
|
||||
pSet = taosArraySearch(pFS->nstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_EQ);
|
||||
}
|
||||
int32_t idx = taosArraySearchIdx(pFS->nstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_GE);
|
||||
|
||||
// create fset if need
|
||||
if (pSet == NULL) {
|
||||
ASSERT(op->oState.size == 0 && op->nState.size > 0);
|
||||
|
||||
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);
|
||||
pSet = NULL;
|
||||
if (idx < 0) {
|
||||
idx = taosArrayGetSize(pFS->nstate);
|
||||
} else {
|
||||
pSet = taosArrayGet(pFS->nstate, idx);
|
||||
if (pSet->fid != op->fid) pSet = NULL;
|
||||
}
|
||||
|
||||
tsdbFileSetInit(pSet);
|
||||
if (!pSet) {
|
||||
pSet = taosArrayInsert(pFS->nstate, idx, &fset);
|
||||
if (!pSet) TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||
tsdbFileSetInit(pSet, op->fid);
|
||||
}
|
||||
}
|
||||
|
||||
code = tsdbFSetEdit(pSet, op);
|
||||
code = tsdbFileSetEdit(pSet, op);
|
||||
TSDB_CHECK_CODE(code, lino, _exit);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "inc/tsdbFSet.h"
|
||||
|
||||
static int32_t stt_lvl_to_json(const SSttLvl *lvl, cJSON *json) {
|
||||
if (cJSON_AddNumberToObject(json, "lvl", lvl->lvl) == NULL) {
|
||||
if (cJSON_AddNumberToObject(json, "lvl", lvl->level) == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
|
@ -49,8 +49,8 @@ static int32_t stt_file_cmpr(const SRBTreeNode *n1, const SRBTreeNode *n2) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t stt_lvl_init(SSttLvl *lvl) {
|
||||
lvl->lvl = 0;
|
||||
static int32_t stt_lvl_init(SSttLvl *lvl, int32_t level) {
|
||||
lvl->level = level;
|
||||
lvl->nstt = 0;
|
||||
tRBTreeCreate(&lvl->sttTree, stt_file_cmpr);
|
||||
return 0;
|
||||
|
@ -63,17 +63,17 @@ static int32_t add_file_to_stt_lvl(SSttLvl *lvl, STFileObj *fobj) {
|
|||
}
|
||||
|
||||
static int32_t json_to_stt_lvl(const cJSON *json, SSttLvl *lvl) {
|
||||
stt_lvl_init(lvl);
|
||||
|
||||
const cJSON *item1, *item2;
|
||||
|
||||
item1 = cJSON_GetObjectItem(json, "lvl");
|
||||
if (cJSON_IsNumber(item1)) {
|
||||
lvl->lvl = item1->valuedouble;
|
||||
lvl->level = item1->valuedouble;
|
||||
} else {
|
||||
return TSDB_CODE_FILE_CORRUPTED;
|
||||
}
|
||||
|
||||
stt_lvl_init(lvl, lvl->level);
|
||||
|
||||
item1 = cJSON_GetObjectItem(json, "files");
|
||||
if (cJSON_IsArray(item1)) {
|
||||
cJSON_ArrayForEach(item2, item1) {
|
||||
|
@ -94,21 +94,31 @@ static int32_t json_to_stt_lvl(const cJSON *json, SSttLvl *lvl) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t add_file(STFileSet *fset, STFile *f) {
|
||||
if (f->type == TSDB_FTYPE_STT) {
|
||||
SSttLvl *lvl = NULL; // TODO
|
||||
|
||||
// lvl->nstt++;
|
||||
// lvl->fstt = f;
|
||||
} else {
|
||||
// fset->farr[f->type] = f;
|
||||
}
|
||||
|
||||
static int32_t add_stt_lvl(STFileSet *fset, SSttLvl *lvl) {
|
||||
tRBTreePut(&fset->lvlTree, &lvl->rbtn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t add_stt_lvl(STFileSet *fset, SSttLvl *lvl) {
|
||||
tRBTreePut(&fset->lvlTree, &lvl->rbtn);
|
||||
static int32_t add_file_to_fset(STFileSet *fset, STFileObj *fobj) {
|
||||
if (fobj->f.type == TSDB_FTYPE_STT) {
|
||||
SSttLvl *lvl;
|
||||
SSttLvl tlvl = {.level = fobj->f.stt.lvl};
|
||||
|
||||
SRBTreeNode *node = tRBTreeGet(&fset->lvlTree, &tlvl.rbtn);
|
||||
if (node) {
|
||||
lvl = TCONTAINER_OF(node, SSttLvl, rbtn);
|
||||
} else {
|
||||
lvl = taosMemoryMalloc(sizeof(*lvl));
|
||||
if (!lvl) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
stt_lvl_init(lvl, fobj->f.stt.lvl);
|
||||
add_stt_lvl(fset, lvl);
|
||||
}
|
||||
add_file_to_stt_lvl(lvl, fobj);
|
||||
} else {
|
||||
fset->farr[fobj->f.type] = fobj;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -116,16 +126,19 @@ static int32_t stt_lvl_cmpr(const SRBTreeNode *n1, const SRBTreeNode *n2) {
|
|||
SSttLvl *lvl1 = TCONTAINER_OF(n1, SSttLvl, rbtn);
|
||||
SSttLvl *lvl2 = TCONTAINER_OF(n2, SSttLvl, rbtn);
|
||||
|
||||
if (lvl1->lvl < lvl2->lvl) {
|
||||
if (lvl1->level < lvl2->level) {
|
||||
return -1;
|
||||
} else if (lvl1->lvl > lvl2->lvl) {
|
||||
} else if (lvl1->level > lvl2->level) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t fset_init(STFileSet *fset) {
|
||||
memset(fset, 0, sizeof(*fset));
|
||||
static int32_t fset_init(STFileSet *fset, int32_t fid) {
|
||||
fset->fid = fid;
|
||||
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||
fset->farr[ftype] = NULL;
|
||||
}
|
||||
tRBTreeCreate(&fset->lvlTree, stt_lvl_cmpr);
|
||||
return 0;
|
||||
}
|
||||
|
@ -166,8 +179,8 @@ int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
|
|||
|
||||
int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet *fset) {
|
||||
const cJSON *item1, *item2;
|
||||
|
||||
fset_init(fset);
|
||||
int32_t code;
|
||||
STFile tf;
|
||||
|
||||
/* fid */
|
||||
item1 = cJSON_GetObjectItem(json, "fid");
|
||||
|
@ -177,8 +190,7 @@ int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet *fset) {
|
|||
return TSDB_CODE_FILE_CORRUPTED;
|
||||
}
|
||||
|
||||
int32_t code;
|
||||
STFile tf;
|
||||
fset_init(fset, fset->fid);
|
||||
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||
code = tsdbJsonToTFile(json, ftype, &tf);
|
||||
if (code == TSDB_CODE_NOT_FOUND) {
|
||||
|
@ -220,37 +232,28 @@ int32_t tsdbFSetCmprFn(const STFileSet *pSet1, const STFileSet *pSet2) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbFSetEdit(STFileSet *fset, const STFileOp *op) {
|
||||
int32_t code;
|
||||
int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op) {
|
||||
int32_t code = 0;
|
||||
|
||||
ASSERT(fset->fid == op->fid);
|
||||
|
||||
if (op->oState.size == 0) {
|
||||
// create
|
||||
// STFile *f;
|
||||
// code = tsdbTFileCreate(&op->nState, &f);
|
||||
// if (code) return code;
|
||||
|
||||
// add_file(fset, f);
|
||||
if (op->oState.size == 0 //
|
||||
|| 0 /* TODO*/
|
||||
) {
|
||||
STFileObj *fobj;
|
||||
code = tsdbTFileObjCreate(&fobj);
|
||||
if (code) return code;
|
||||
fobj->f = op->nState;
|
||||
add_file_to_fset(fset, fobj);
|
||||
} else if (op->nState.size == 0) {
|
||||
// delete
|
||||
ASSERT(0);
|
||||
} else {
|
||||
// modify
|
||||
ASSERT(0);
|
||||
}
|
||||
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 tsdbFileSetInit(STFileSet *pSet, int32_t fid) { return fset_init(pSet, fid); }
|
||||
|
||||
int32_t tsdbFileSetClear(STFileSet *pSet) {
|
||||
// TODO
|
||||
|
|
|
@ -234,7 +234,7 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) {
|
|||
|
||||
int32_t tsdbTFileObjCreate(STFileObj **fobj) {
|
||||
fobj[0] = taosMemoryMalloc(sizeof(STFileObj));
|
||||
if (fobj[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
if (!fobj[0]) return TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
fobj[0]->ref = 1;
|
||||
// TODO
|
||||
|
|
Loading…
Reference in New Issue