more code

This commit is contained in:
Hongze Cheng 2023-05-16 10:34:02 +08:00
parent 96bfbbe784
commit f40986408c
4 changed files with 19 additions and 32 deletions

View File

@ -51,10 +51,10 @@ struct STFileOp {
};
typedef struct SSttLvl {
SRBTreeNode rbtn;
int32_t lvl; // level
int32_t nstt; // number of .stt files on this level
SRBTree sttTree; // .stt file tree, sorted by cid
SRBTreeNode rbtn;
} SSttLvl;
struct STFileSet {

View File

@ -165,7 +165,7 @@ _exit:
return code;
}
static int32_t save_fs(int64_t eid, SArray *aTFileSet, const char *fname) {
static int32_t save_fs(SArray *aTFileSet, const char *fname) {
int32_t code = 0;
int32_t lino = 0;
@ -178,31 +178,21 @@ static int32_t save_fs(int64_t eid, SArray *aTFileSet, const char *fname) {
TSDB_CHECK_CODE(code, lino, _exit);
}
// eid
if (cJSON_AddNumberToObject(json, "eid", eid) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
TSDB_CHECK_CODE(code, lino, _exit);
}
// fset
cJSON *ajson = cJSON_AddArrayToObject(json, "fset");
if (ajson == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
TSDB_CHECK_CODE(code, lino, _exit);
TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
}
for (int32_t i = 0; i < taosArrayGetSize(aTFileSet); i++) {
STFileSet *pFileSet = (STFileSet *)taosArrayGet(aTFileSet, i);
cJSON *item;
if ((item = cJSON_CreateObject()) == NULL) {
code = TSDB_CODE_OUT_OF_MEMORY;
TSDB_CHECK_CODE(code, lino, _exit);
}
item = cJSON_CreateObject();
if (!item) TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
cJSON_AddItemToArray(ajson, item);
code = tsdbFileSetToJson(pFileSet, item);
TSDB_CHECK_CODE(code, lino, _exit);
cJSON_AddItemToArray(ajson, item);
}
code = save_json(json, fname);
@ -396,7 +386,7 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
code = scan_and_fix_fs(fs);
TSDB_CHECK_CODE(code, lino, _exit);
} else {
code = save_fs(0, fs->cstate, fCurrent);
code = save_fs(fs->cstate, fCurrent);
TSDB_CHECK_CODE(code, lino, _exit);
}
@ -521,7 +511,7 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, int64_t eid, const SArray *aFileOp, EF
TSDB_CHECK_CODE(code, lino, _exit);
// save fs
code = save_fs(fs->eid, fs->nstate, current_t);
code = save_fs(fs->nstate, current_t);
TSDB_CHECK_CODE(code, lino, _exit);
_exit:

View File

@ -20,7 +20,7 @@ static int32_t stt_lvl_to_json(const SSttLvl *lvl, cJSON *json) {
return TSDB_CODE_OUT_OF_MEMORY;
}
cJSON *ajson = cJSON_AddArrayToObject(json, "stt");
cJSON *ajson = cJSON_AddArrayToObject(json, "files");
if (ajson == NULL) return TSDB_CODE_OUT_OF_MEMORY;
SRBTreeIter iter = tRBTreeIterCreate(&lvl->sttTree, 1);
@ -29,14 +29,10 @@ static int32_t stt_lvl_to_json(const SSttLvl *lvl, cJSON *json) {
cJSON *item = cJSON_CreateObject();
if (item == NULL) return TSDB_CODE_OUT_OF_MEMORY;
cJSON_AddItemToArray(ajson, item);
int32_t code = tsdbTFileToJson(&fobj->f, item);
if (code) {
cJSON_Delete(item);
return code;
}
cJSON_AddItemToArray(ajson, item);
if (code) return code;
}
return 0;
@ -69,9 +65,7 @@ int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
}
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
if (fset->farr[ftype] == NULL) {
continue;
}
if (fset->farr[ftype] == NULL) continue;
code = tsdbTFileToJson(&fset->farr[ftype]->f, json);
if (code) return code;

View File

@ -203,10 +203,13 @@ int32_t tsdbTFileClear(STFile *pFile) {
}
int32_t tsdbTFileToJson(const STFile *file, cJSON *json) {
cJSON *tjson = cJSON_AddObjectToObject(json, g_tfile_info[file->type].suffix);
if (tjson == NULL) return TSDB_CODE_OUT_OF_MEMORY;
return g_tfile_info[file->type].to_json(file, tjson);
if (file->type == TSDB_FTYPE_STT) {
return g_tfile_info[file->type].to_json(file, json);
} else {
cJSON *item = cJSON_AddObjectToObject(json, g_tfile_info[file->type].suffix);
if (item == NULL) return TSDB_CODE_OUT_OF_MEMORY;
return g_tfile_info[file->type].to_json(file, item);
}
}
int32_t tsdbTFileFromJson(const cJSON *json, tsdb_ftype_t ftype, STFile **f) {