more code
This commit is contained in:
parent
7cc7d35be4
commit
d273d10ff0
|
@ -36,17 +36,16 @@ typedef enum {
|
||||||
#define TSDB_FTYPE_MIN TSDB_FTYPE_HEAD
|
#define TSDB_FTYPE_MIN TSDB_FTYPE_HEAD
|
||||||
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
|
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
|
||||||
|
|
||||||
|
// STFile
|
||||||
int32_t tsdbTFileToJson(const STFile *f, cJSON *json);
|
int32_t tsdbTFileToJson(const STFile *f, cJSON *json);
|
||||||
int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f);
|
int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f);
|
||||||
|
|
||||||
// create/destroy
|
|
||||||
int32_t tsdbTFileCreate(const STFile *pFile, STFile **f);
|
|
||||||
int32_t tsdbTFileDestroy(STFile *pFile);
|
|
||||||
|
|
||||||
// init/clear
|
|
||||||
int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile);
|
int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile);
|
||||||
int32_t tsdbTFileClear(STFile *pFile);
|
int32_t tsdbTFileClear(STFile *pFile);
|
||||||
|
|
||||||
|
// STFileObj
|
||||||
|
int32_t tsdbTFileObjCreate(STFileObj **fobj);
|
||||||
|
int32_t tsdbTFileObjDestroy(STFileObj *fobj);
|
||||||
|
|
||||||
struct STFile {
|
struct STFile {
|
||||||
char fname[TSDB_FILENAME_LEN];
|
char fname[TSDB_FILENAME_LEN];
|
||||||
tsdb_ftype_t type;
|
tsdb_ftype_t type;
|
||||||
|
@ -63,9 +62,9 @@ struct STFile {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct STFileObj {
|
struct STFileObj {
|
||||||
SRBTreeNode rbtn;
|
SRBTreeNode rbtn;
|
||||||
int32_t ref;
|
volatile int32_t ref;
|
||||||
STFile f;
|
STFile f;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -38,8 +38,59 @@ static int32_t stt_lvl_to_json(const SSttLvl *lvl, cJSON *json) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t stt_lvl_from_json(const cJSON *json, SSttLvl *lvl) {
|
static int32_t stt_file_cmpr(const SRBTreeNode *n1, const SRBTreeNode *n2) {
|
||||||
// TODO
|
STFileObj *f1 = TCONTAINER_OF(n1, STFileObj, rbtn);
|
||||||
|
STFileObj *f2 = TCONTAINER_OF(n2, STFileObj, rbtn);
|
||||||
|
if (f1->f.cid < f2->f.cid) {
|
||||||
|
return -1;
|
||||||
|
} else if (f1->f.cid > f2->f.cid) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t stt_lvl_init(SSttLvl *lvl) {
|
||||||
|
lvl->lvl = 0;
|
||||||
|
lvl->nstt = 0;
|
||||||
|
tRBTreeCreate(&lvl->sttTree, stt_file_cmpr);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t add_file_to_stt_lvl(SSttLvl *lvl, STFileObj *fobj) {
|
||||||
|
lvl->nstt++;
|
||||||
|
tRBTreePut(&lvl->sttTree, &fobj->rbtn);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
} else {
|
||||||
|
return TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
|
item1 = cJSON_GetObjectItem(json, "files");
|
||||||
|
if (cJSON_IsArray(item1)) {
|
||||||
|
cJSON_ArrayForEach(item2, item1) {
|
||||||
|
STFileObj *fobj;
|
||||||
|
|
||||||
|
int32_t code = tsdbTFileObjCreate(&fobj);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
code = tsdbJsonToTFile(item2, TSDB_FTYPE_STT, &fobj->f);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
add_file_to_stt_lvl(lvl, fobj);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return TSDB_CODE_FILE_CORRUPTED;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,6 +107,11 @@ static int32_t add_file(STFileSet *fset, STFile *f) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t add_stt_lvl(STFileSet *fset, SSttLvl *lvl) {
|
||||||
|
tRBTreePut(&fset->lvlTree, &lvl->rbtn);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t stt_lvl_cmpr(const SRBTreeNode *n1, const SRBTreeNode *n2) {
|
static int32_t stt_lvl_cmpr(const SRBTreeNode *n1, const SRBTreeNode *n2) {
|
||||||
SSttLvl *lvl1 = TCONTAINER_OF(n1, SSttLvl, rbtn);
|
SSttLvl *lvl1 = TCONTAINER_OF(n1, SSttLvl, rbtn);
|
||||||
SSttLvl *lvl2 = TCONTAINER_OF(n2, SSttLvl, rbtn);
|
SSttLvl *lvl2 = TCONTAINER_OF(n2, SSttLvl, rbtn);
|
||||||
|
@ -109,37 +165,48 @@ int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet *fset) {
|
int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet *fset) {
|
||||||
const cJSON *item;
|
const cJSON *item1, *item2;
|
||||||
|
|
||||||
fset_init(fset);
|
fset_init(fset);
|
||||||
|
|
||||||
/* fid */
|
/* fid */
|
||||||
item = cJSON_GetObjectItem(json, "fid");
|
item1 = cJSON_GetObjectItem(json, "fid");
|
||||||
if (cJSON_IsNumber(item)) {
|
if (cJSON_IsNumber(item1)) {
|
||||||
fset->fid = item->valueint;
|
fset->fid = item1->valueint;
|
||||||
} else {
|
} else {
|
||||||
return TSDB_CODE_FILE_CORRUPTED;
|
return TSDB_CODE_FILE_CORRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
STFile tf;
|
||||||
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||||
STFile tf;
|
|
||||||
code = tsdbJsonToTFile(json, ftype, &tf);
|
code = tsdbJsonToTFile(json, ftype, &tf);
|
||||||
if (code == TSDB_CODE_NOT_FOUND) {
|
if (code == TSDB_CODE_NOT_FOUND) {
|
||||||
continue;
|
continue;
|
||||||
} else if (code) {
|
} else if (code) {
|
||||||
return code;
|
return code;
|
||||||
} else {
|
} else {
|
||||||
// TODO
|
code = tsdbTFileObjCreate(&fset->farr[ftype]);
|
||||||
// code = tsdbFileObjCreate(&tf, &fset->farr[ftype]);
|
if (code) return code;
|
||||||
// if (code) return code;
|
fset->farr[ftype]->f = tf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// each level
|
// each level
|
||||||
item = cJSON_GetObjectItem(json, "stt");
|
item1 = cJSON_GetObjectItem(json, "stt");
|
||||||
if (cJSON_IsArray(item)) {
|
if (cJSON_IsArray(item1)) {
|
||||||
// TODO
|
cJSON_ArrayForEach(item2, item1) {
|
||||||
|
SSttLvl *lvl = taosMemoryCalloc(1, sizeof(*lvl));
|
||||||
|
if (lvl == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
code = json_to_stt_lvl(item2, lvl);
|
||||||
|
if (code) {
|
||||||
|
taosMemoryFree(lvl);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
add_stt_lvl(fset, lvl);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return TSDB_CODE_FILE_CORRUPTED;
|
return TSDB_CODE_FILE_CORRUPTED;
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,17 +232,17 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbTFileCreate(const STFile *pFile, STFile **f) {
|
int32_t tsdbTFileObjCreate(STFileObj **fobj) {
|
||||||
f[0] = taosMemoryMalloc(sizeof(*f[0]));
|
fobj[0] = taosMemoryMalloc(sizeof(STFileObj));
|
||||||
if (f[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
if (fobj[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
*f[0] = *pFile;
|
fobj[0]->ref = 1;
|
||||||
|
// TODO
|
||||||
// f[0]->ref = 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbTFileDestroy(STFile *pFile) {
|
int32_t tsdbTFileObjDestroy(STFileObj *fobj) {
|
||||||
taosMemoryFree(pFile);
|
// TODO
|
||||||
|
taosMemoryFree(fobj);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue