more code
This commit is contained in:
parent
66ea10755e
commit
e247870548
|
@ -77,45 +77,55 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arg, // array
|
||||||
#define TARRAY2_CLEAR(a, cb) \
|
#define TARRAY2_CLEAR(a, cb) \
|
||||||
do { \
|
do { \
|
||||||
if (cb) { \
|
if (cb) { \
|
||||||
|
void (*cb_)(void *) = (cb); \
|
||||||
for (int32_t i = 0; i < (a)->size; ++i) { \
|
for (int32_t i = 0; i < (a)->size; ++i) { \
|
||||||
cb((a)->data + i); \
|
cb_((a)->data + i); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
(a)->size = 0; \
|
(a)->size = 0; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TARRAY2_SEARCH(a, ep, cmp, flag) \
|
#define TARRAY2_CLEAR_FREE(a, cb) \
|
||||||
(((a)->size == 0) ? NULL : taosbsearch(ep, (a)->data, (a)->size, sizeof((a)->data[0]), cmp, flag))
|
do { \
|
||||||
|
TARRAY2_CLEAR(a, cb); \
|
||||||
|
TARRAY2_FREE(a); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#define TARRAY2_INSERT(a, idx, e) \
|
#define TARRAY2_SEARCH(a, ep, cmp, flag) \
|
||||||
({ \
|
(((a)->size == 0) ? NULL : taosbsearch(ep, (a)->data, (a)->size, sizeof(typeof((a)->data[0])), cmp, flag))
|
||||||
int32_t __ret = 0; \
|
|
||||||
if ((a)->size >= (a)->capacity) { \
|
#define TARRAY2_INSERT(a, idx, e) \
|
||||||
__ret = tarray2_make_room(&(a), (a)->size + 1, sizeof(*(a)->data)); \
|
({ \
|
||||||
} \
|
int32_t __ret = 0; \
|
||||||
if (!__ret) { \
|
if ((a)->size >= (a)->capacity) { \
|
||||||
if ((a)->size > (idx)) { \
|
__ret = tarray2_make_room(&(a), (a)->size + 1, sizeof(typeof((a)->data[0]))); \
|
||||||
memmove((a)->data + (idx) + 1, (a)->data + (idx), sizeof(*(a)->data) * ((a)->size - (idx))); \
|
} \
|
||||||
} \
|
if (!__ret) { \
|
||||||
(a)->data[(idx)] = e; \
|
if ((a)->size > (idx)) { \
|
||||||
(a)->size++; \
|
memmove((a)->data + (idx) + 1, (a)->data + (idx), sizeof(typeof((a)->data[0])) * ((a)->size - (idx))); \
|
||||||
} \
|
} \
|
||||||
__ret; \
|
(a)->data[(idx)] = e; \
|
||||||
|
(a)->size++; \
|
||||||
|
} \
|
||||||
|
__ret; \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define TARRAY2_INSERT_P(a, idx, ep) TARRAY2_INSERT(a, idx, *(ep))
|
#define TARRAY2_INSERT_P(a, idx, ep) TARRAY2_INSERT(a, idx, *(ep))
|
||||||
#define TARRAY2_APPEND(a, e) TARRAY2_INSERT(a, (a)->size, e)
|
#define TARRAY2_APPEND(a, e) TARRAY2_INSERT(a, (a)->size, e)
|
||||||
#define TARRAY2_APPEND_P(a, ep) TARRAY2_APPEND(a, *(ep))
|
#define TARRAY2_APPEND_P(a, ep) TARRAY2_APPEND(a, *(ep))
|
||||||
|
|
||||||
#define TARRAY2_REMOVE(a, idx, cb) \
|
#define TARRAY2_REMOVE(a, idx, cb) \
|
||||||
do { \
|
do { \
|
||||||
if ((idx) < (a)->size) { \
|
if ((idx) < (a)->size) { \
|
||||||
if (cb) cb((a)->data + (idx)); \
|
if (cb) { \
|
||||||
if ((idx) < (a)->size - 1) { \
|
void (*cb_)(void *) = cb; \
|
||||||
memmove((a)->data + (idx), (a)->data + (idx) + 1, sizeof(*(a)->data) * ((a)->size - (idx)-1)); \
|
cb_((a)->data + (idx)); \
|
||||||
} \
|
} \
|
||||||
(a)->size--; \
|
if ((idx) < (a)->size - 1) { \
|
||||||
} \
|
memmove((a)->data + (idx), (a)->data + (idx) + 1, sizeof(typeof(*(a)->data)) * ((a)->size - (idx)-1)); \
|
||||||
|
} \
|
||||||
|
(a)->size--; \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TARRAY2_FOREACH(a, e) for (int32_t __i = 0; __i < (a)->size && ((e) = (a)->data[__i], 1); __i++)
|
#define TARRAY2_FOREACH(a, e) for (int32_t __i = 0; __i < (a)->size && ((e) = (a)->data[__i], 1); __i++)
|
||||||
|
|
|
@ -44,14 +44,14 @@ int32_t tsdbFSGetFSet(STFileSystem *fs, int32_t fid, const STFileSet **ppFSet);
|
||||||
|
|
||||||
/* Exposed Structs */
|
/* Exposed Structs */
|
||||||
struct STFileSystem {
|
struct STFileSystem {
|
||||||
STsdb *pTsdb;
|
STsdb *pTsdb;
|
||||||
tsem_t canEdit;
|
tsem_t canEdit;
|
||||||
int32_t state;
|
int32_t state;
|
||||||
int64_t neid;
|
int64_t neid;
|
||||||
EFEditT etype;
|
EFEditT etype;
|
||||||
int64_t eid;
|
int64_t eid;
|
||||||
TARRAY2(STFileSet *) cstate;
|
TFileSetArray cstate;
|
||||||
TARRAY2(STFileSet *) nstate;
|
TFileSetArray nstate;
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -25,6 +25,8 @@ extern "C" {
|
||||||
typedef struct STFileSet STFileSet;
|
typedef struct STFileSet STFileSet;
|
||||||
typedef struct STFileOp STFileOp;
|
typedef struct STFileOp STFileOp;
|
||||||
typedef struct SSttLvl SSttLvl;
|
typedef struct SSttLvl SSttLvl;
|
||||||
|
typedef TARRAY2(STFileSet *) TFileSetArray;
|
||||||
|
typedef TARRAY2(SSttLvl *) TSttLvlArray;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
TSDB_FOP_NONE = 0,
|
TSDB_FOP_NONE = 0,
|
||||||
|
@ -34,11 +36,12 @@ typedef enum {
|
||||||
TSDB_FOP_TRUNCATE,
|
TSDB_FOP_TRUNCATE,
|
||||||
} tsdb_fop_t;
|
} tsdb_fop_t;
|
||||||
|
|
||||||
|
int32_t tsdbFileSetInit(int32_t fid, STFileSet **fset);
|
||||||
|
int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet **fset2);
|
||||||
|
int32_t tsdbFileSetClear(STFileSet **fset);
|
||||||
|
|
||||||
int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json);
|
int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json);
|
||||||
int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet *fset);
|
int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet **fset);
|
||||||
int32_t tsdbFileSetInit(STFileSet *pSet, int32_t fid);
|
|
||||||
int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet *fset2);
|
|
||||||
int32_t tsdbFileSetClear(STFileSet *pSet);
|
|
||||||
int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op);
|
int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op);
|
||||||
int32_t tsdbFSetCmprFn(const STFileSet *pSet1, const STFileSet *pSet2);
|
int32_t tsdbFSetCmprFn(const STFileSet *pSet1, const STFileSet *pSet2);
|
||||||
|
|
||||||
|
@ -59,9 +62,9 @@ struct SSttLvl {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct STFileSet {
|
struct STFileSet {
|
||||||
int32_t fid;
|
int32_t fid;
|
||||||
STFileObj *farr[TSDB_FTYPE_MAX]; // file array
|
STFileObj *farr[TSDB_FTYPE_MAX]; // file array
|
||||||
SRBTree lvlTree; // SRBTree<SSttLvl>, level tree of .stt
|
TSttLvlArray lvlArr; // level array
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -37,13 +37,13 @@ typedef enum {
|
||||||
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
|
#define TSDB_FTYPE_MAX (TSDB_FTYPE_TOMB + 1)
|
||||||
|
|
||||||
// STFile
|
// STFile
|
||||||
int32_t tsdbTFileToJson(const STFile *f, cJSON *json);
|
|
||||||
int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f);
|
|
||||||
int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile);
|
int32_t tsdbTFileInit(STsdb *pTsdb, STFile *pFile);
|
||||||
int32_t tsdbTFileClear(STFile *pFile);
|
int32_t tsdbTFileClear(STFile *pFile);
|
||||||
|
int32_t tsdbTFileToJson(const STFile *f, cJSON *json);
|
||||||
|
int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f);
|
||||||
|
|
||||||
// STFileObj
|
// STFileObj
|
||||||
int32_t tsdbTFileObjCreate(STFileObj **fobj);
|
int32_t tsdbTFileObjCreate(const STFile *f, STFileObj **fobj);
|
||||||
int32_t tsdbTFileObjDestroy(STFileObj *fobj);
|
int32_t tsdbTFileObjDestroy(STFileObj *fobj);
|
||||||
|
|
||||||
struct STFile {
|
struct STFile {
|
||||||
|
|
|
@ -85,7 +85,7 @@ static int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) {
|
||||||
static int32_t save_json(const cJSON *json, const char *fname) {
|
static int32_t save_json(const cJSON *json, const char *fname) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
|
||||||
char *data = cJSON_Print(json);
|
char *data = cJSON_PrintUnformatted(json);
|
||||||
if (data == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
if (data == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
TdFilePtr fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
TdFilePtr fp = taosOpenFile(fname, TD_FILE_WRITE | TD_FILE_CREATE | TD_FILE_TRUNC);
|
||||||
|
@ -149,7 +149,7 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t save_fs(SArray *aTFileSet, const char *fname) {
|
static int32_t save_fs(const TFileSetArray *arr, const char *fname) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
|
@ -165,15 +165,13 @@ static int32_t save_fs(SArray *aTFileSet, const char *fname) {
|
||||||
// fset
|
// fset
|
||||||
cJSON *ajson = cJSON_AddArrayToObject(json, "fset");
|
cJSON *ajson = cJSON_AddArrayToObject(json, "fset");
|
||||||
if (!ajson) TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
if (!ajson) TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
for (int32_t i = 0; i < taosArrayGetSize(aTFileSet); i++) {
|
const STFileSet *fset;
|
||||||
STFileSet *pFileSet = (STFileSet *)taosArrayGet(aTFileSet, i);
|
TARRAY2_FOREACH(arr, fset) {
|
||||||
cJSON *item;
|
cJSON *item = cJSON_CreateObject();
|
||||||
|
|
||||||
item = cJSON_CreateObject();
|
|
||||||
if (!item) TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
if (!item) TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
||||||
cJSON_AddItemToArray(ajson, item);
|
cJSON_AddItemToArray(ajson, item);
|
||||||
|
|
||||||
code = tsdbFileSetToJson(pFileSet, item);
|
code = tsdbFileSetToJson(fset, item);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,11 +186,11 @@ _exit:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t load_fs(const char *fname, SArray *aTFileSet) {
|
static int32_t load_fs(const char *fname, TFileSetArray *arr) {
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
int32_t lino = 0;
|
int32_t lino = 0;
|
||||||
|
|
||||||
taosArrayClear(aTFileSet);
|
TARRAY2_CLEAR(arr, NULL);
|
||||||
|
|
||||||
// load json
|
// load json
|
||||||
cJSON *json = NULL;
|
cJSON *json = NULL;
|
||||||
|
@ -215,10 +213,11 @@ static int32_t load_fs(const char *fname, SArray *aTFileSet) {
|
||||||
if (cJSON_IsArray(item)) {
|
if (cJSON_IsArray(item)) {
|
||||||
const cJSON *titem;
|
const cJSON *titem;
|
||||||
cJSON_ArrayForEach(titem, item) {
|
cJSON_ArrayForEach(titem, item) {
|
||||||
STFileSet *fset = taosArrayReserve(aTFileSet, 1);
|
STFileSet *fset;
|
||||||
if (!fset) TSDB_CHECK_CODE(code = TSDB_CODE_OUT_OF_MEMORY, lino, _exit);
|
code = tsdbJsonToFileSet(titem, &fset);
|
||||||
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
code = tsdbJsonToFileSet(titem, fset);
|
code = TARRAY2_APPEND(arr, fset);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -420,8 +419,8 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
|
||||||
current_fname(pTsdb, mCurrent, TSDB_FCURRENT_M);
|
current_fname(pTsdb, mCurrent, TSDB_FCURRENT_M);
|
||||||
|
|
||||||
if (taosCheckExistFile(fCurrent)) { // current.json exists
|
if (taosCheckExistFile(fCurrent)) { // current.json exists
|
||||||
// code = load_fs(fCurrent, fs->cstate);
|
code = load_fs(fCurrent, &fs->cstate);
|
||||||
// TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
|
||||||
if (taosCheckExistFile(cCurrent)) {
|
if (taosCheckExistFile(cCurrent)) {
|
||||||
// current.c.json exists
|
// current.c.json exists
|
||||||
|
@ -447,8 +446,8 @@ static int32_t open_fs(STFileSystem *fs, int8_t rollback) {
|
||||||
code = scan_and_fix_fs(fs);
|
code = scan_and_fix_fs(fs);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
} else {
|
} else {
|
||||||
// code = save_fs(fs->cstate, fCurrent);
|
code = save_fs(&fs->cstate, fCurrent);
|
||||||
// TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
|
|
|
@ -79,11 +79,11 @@ static int32_t json_to_stt_lvl(const cJSON *json, SSttLvl *lvl) {
|
||||||
cJSON_ArrayForEach(item2, item1) {
|
cJSON_ArrayForEach(item2, item1) {
|
||||||
STFileObj *fobj;
|
STFileObj *fobj;
|
||||||
|
|
||||||
int32_t code = tsdbTFileObjCreate(&fobj);
|
// int32_t code = tsdbTFileObjCreate(&fobj);
|
||||||
if (code) return code;
|
// if (code) return code;
|
||||||
|
|
||||||
code = tsdbJsonToTFile(item2, TSDB_FTYPE_STT, &fobj->f);
|
// code = tsdbJsonToTFile(item2, TSDB_FTYPE_STT, &fobj->f);
|
||||||
if (code) return code;
|
// if (code) return code;
|
||||||
|
|
||||||
add_file_to_stt_lvl(lvl, fobj);
|
add_file_to_stt_lvl(lvl, fobj);
|
||||||
}
|
}
|
||||||
|
@ -95,29 +95,29 @@ static int32_t json_to_stt_lvl(const cJSON *json, SSttLvl *lvl) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t add_stt_lvl(STFileSet *fset, SSttLvl *lvl) {
|
static int32_t add_stt_lvl(STFileSet *fset, SSttLvl *lvl) {
|
||||||
tRBTreePut(&fset->lvlTree, &lvl->rbtn);
|
// tRBTreePut(&fset->lvlTree, &lvl->rbtn);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t add_file_to_fset(STFileSet *fset, STFileObj *fobj) {
|
static int32_t add_file_to_fset(STFileSet *fset, STFileObj *fobj) {
|
||||||
if (fobj->f.type == TSDB_FTYPE_STT) {
|
// if (fobj->f.type == TSDB_FTYPE_STT) {
|
||||||
SSttLvl *lvl;
|
// SSttLvl *lvl;
|
||||||
SSttLvl tlvl = {.level = fobj->f.stt.level};
|
// SSttLvl tlvl = {.level = fobj->f.stt.level};
|
||||||
|
|
||||||
SRBTreeNode *node = tRBTreeGet(&fset->lvlTree, &tlvl.rbtn);
|
// SRBTreeNode *node = tRBTreeGet(&fset->lvlTree, &tlvl.rbtn);
|
||||||
if (node) {
|
// if (node) {
|
||||||
lvl = TCONTAINER_OF(node, SSttLvl, rbtn);
|
// lvl = TCONTAINER_OF(node, SSttLvl, rbtn);
|
||||||
} else {
|
// } else {
|
||||||
lvl = taosMemoryMalloc(sizeof(*lvl));
|
// lvl = taosMemoryMalloc(sizeof(*lvl));
|
||||||
if (!lvl) return TSDB_CODE_OUT_OF_MEMORY;
|
// if (!lvl) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
stt_lvl_init(lvl, fobj->f.stt.level);
|
// stt_lvl_init(lvl, fobj->f.stt.level);
|
||||||
add_stt_lvl(fset, lvl);
|
// add_stt_lvl(fset, lvl);
|
||||||
}
|
// }
|
||||||
add_file_to_stt_lvl(lvl, fobj);
|
// add_file_to_stt_lvl(lvl, fobj);
|
||||||
} else {
|
// } else {
|
||||||
fset->farr[fobj->f.type] = fobj;
|
// fset->farr[fobj->f.type] = fobj;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -134,14 +134,14 @@ static int32_t stt_lvl_cmpr(const SRBTreeNode *n1, const SRBTreeNode *n2) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t fset_init(STFileSet *fset, int32_t fid) {
|
// static int32_t fset_init(STFileSet *fset, int32_t fid) {
|
||||||
fset->fid = fid;
|
// fset->fid = fid;
|
||||||
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
// for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||||
fset->farr[ftype] = NULL;
|
// fset->farr[ftype] = NULL;
|
||||||
}
|
// }
|
||||||
tRBTreeCreate(&fset->lvlTree, stt_lvl_cmpr);
|
// tRBTreeCreate(&fset->lvlTree, stt_lvl_cmpr);
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
static int32_t fset_clear(STFileSet *fset) {
|
static int32_t fset_clear(STFileSet *fset) {
|
||||||
// TODO
|
// TODO
|
||||||
|
@ -167,64 +167,64 @@ int32_t tsdbFileSetToJson(const STFileSet *fset, cJSON *json) {
|
||||||
// each level
|
// each level
|
||||||
item1 = cJSON_AddArrayToObject(json, "stt levels");
|
item1 = cJSON_AddArrayToObject(json, "stt levels");
|
||||||
if (item1 == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
if (item1 == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
SRBTreeIter iter = tRBTreeIterCreate(&fset->lvlTree, 1);
|
const SSttLvl *lvl;
|
||||||
for (SRBTreeNode *node = tRBTreeIterNext(&iter); node; node = tRBTreeIterNext(&iter)) {
|
TARRAY2_FOREACH(&fset->lvlArr, lvl) {
|
||||||
item2 = cJSON_CreateObject();
|
item2 = cJSON_CreateObject();
|
||||||
if (!item2) return TSDB_CODE_OUT_OF_MEMORY;
|
if (!item2) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
cJSON_AddItemToArray(item1, item2);
|
cJSON_AddItemToArray(item1, item2);
|
||||||
|
|
||||||
code = stt_lvl_to_json(TCONTAINER_OF(node, SSttLvl, rbtn), item2);
|
code = stt_lvl_to_json(lvl, item2);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet *fset) {
|
int32_t tsdbJsonToFileSet(const cJSON *json, STFileSet **fset) {
|
||||||
const cJSON *item1, *item2;
|
// const cJSON *item1, *item2;
|
||||||
int32_t code;
|
// int32_t code;
|
||||||
STFile tf;
|
// STFile tf;
|
||||||
|
|
||||||
/* fid */
|
// /* fid */
|
||||||
item1 = cJSON_GetObjectItem(json, "fid");
|
// item1 = cJSON_GetObjectItem(json, "fid");
|
||||||
if (cJSON_IsNumber(item1)) {
|
// if (cJSON_IsNumber(item1)) {
|
||||||
fset->fid = item1->valueint;
|
// fset->fid = item1->valueint;
|
||||||
} else {
|
// } else {
|
||||||
return TSDB_CODE_FILE_CORRUPTED;
|
// return TSDB_CODE_FILE_CORRUPTED;
|
||||||
}
|
// }
|
||||||
|
|
||||||
fset_init(fset, fset->fid);
|
// fset_init(fset, fset->fid);
|
||||||
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
// for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||||
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 {
|
||||||
code = tsdbTFileObjCreate(&fset->farr[ftype]);
|
// code = tsdbTFileObjCreate(&fset->farr[ftype]);
|
||||||
if (code) return code;
|
// if (code) return code;
|
||||||
fset->farr[ftype]->f = tf;
|
// fset->farr[ftype]->f = tf;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// each level
|
// // each level
|
||||||
item1 = cJSON_GetObjectItem(json, "stt");
|
// item1 = cJSON_GetObjectItem(json, "stt");
|
||||||
if (cJSON_IsArray(item1)) {
|
// if (cJSON_IsArray(item1)) {
|
||||||
cJSON_ArrayForEach(item2, item1) {
|
// cJSON_ArrayForEach(item2, item1) {
|
||||||
SSttLvl *lvl = taosMemoryCalloc(1, sizeof(*lvl));
|
// SSttLvl *lvl = taosMemoryCalloc(1, sizeof(*lvl));
|
||||||
if (lvl == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
// if (lvl == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
code = json_to_stt_lvl(item2, lvl);
|
// code = json_to_stt_lvl(item2, lvl);
|
||||||
if (code) {
|
// if (code) {
|
||||||
taosMemoryFree(lvl);
|
// taosMemoryFree(lvl);
|
||||||
return code;
|
// return code;
|
||||||
}
|
// }
|
||||||
|
|
||||||
add_stt_lvl(fset, lvl);
|
// add_stt_lvl(fset, lvl);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
return TSDB_CODE_FILE_CORRUPTED;
|
// return TSDB_CODE_FILE_CORRUPTED;
|
||||||
}
|
// }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op) {
|
||||||
|| 0 /* TODO*/
|
|| 0 /* TODO*/
|
||||||
) {
|
) {
|
||||||
STFileObj *fobj;
|
STFileObj *fobj;
|
||||||
code = tsdbTFileObjCreate(&fobj);
|
// code = tsdbTFileObjCreate(&fobj);
|
||||||
if (code) return code;
|
if (code) return code;
|
||||||
fobj->f = op->nState;
|
fobj->f = op->nState;
|
||||||
add_file_to_fset(fset, fobj);
|
add_file_to_fset(fset, fobj);
|
||||||
|
@ -256,48 +256,85 @@ int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbFileSetInit(STFileSet *pSet, int32_t fid) { return fset_init(pSet, fid); }
|
int32_t tsdbFileSetInit(int32_t fid, STFileSet **fset) {
|
||||||
|
fset[0] = taosMemoryCalloc(1, sizeof(STFileSet));
|
||||||
|
if (fset[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet *fset2) {
|
fset[0]->fid = fid;
|
||||||
int32_t code;
|
TARRAY2_INIT(&fset[0]->lvlArr);
|
||||||
|
|
||||||
fset_init(fset2, fset1->fid);
|
|
||||||
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
|
||||||
if (fset1->farr[ftype] == NULL) continue;
|
|
||||||
|
|
||||||
code = tsdbTFileObjCreate(&fset2->farr[ftype]);
|
|
||||||
if (code) return code;
|
|
||||||
fset2->farr[ftype]->f = fset1->farr[ftype]->f;
|
|
||||||
}
|
|
||||||
|
|
||||||
SRBTreeIter iter = tRBTreeIterCreate(&fset1->lvlTree, 1);
|
|
||||||
for (SRBTreeNode *node = tRBTreeIterNext(&iter); node; node = tRBTreeIterNext(&iter)) {
|
|
||||||
SSttLvl *lvl1 = TCONTAINER_OF(node, SSttLvl, rbtn);
|
|
||||||
SSttLvl *lvl2 = taosMemoryCalloc(1, sizeof(*lvl2));
|
|
||||||
if (lvl2 == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
|
||||||
stt_lvl_init(lvl2, lvl1->level);
|
|
||||||
add_stt_lvl(fset2, lvl2);
|
|
||||||
|
|
||||||
SRBTreeIter iter2 = tRBTreeIterCreate(&lvl1->sttTree, 1);
|
|
||||||
for (SRBTreeNode *node2 = tRBTreeIterNext(&iter2); node2; node2 = tRBTreeIterNext(&iter2)) {
|
|
||||||
STFileObj *fobj1 = TCONTAINER_OF(node2, STFileObj, rbtn);
|
|
||||||
STFileObj *fobj2;
|
|
||||||
code = tsdbTFileObjCreate(&fobj2);
|
|
||||||
if (code) return code;
|
|
||||||
fobj2->f = fobj1->f;
|
|
||||||
add_file_to_stt_lvl(lvl2, fobj2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbFileSetClear(STFileSet *pSet) {
|
int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet **fset) {
|
||||||
// TODO
|
int32_t code = tsdbFileSetInit(fset1->fid, fset);
|
||||||
|
if (code) return code;
|
||||||
|
|
||||||
|
for (int32_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||||
|
if (fset1->farr[ftype] == NULL) continue;
|
||||||
|
|
||||||
|
code = tsdbTFileObjCreate(&fset1->farr[ftype]->f, &fset[0]->farr[ftype]);
|
||||||
|
if (code) {
|
||||||
|
tsdbFileSetClear(fset);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const SSttLvl *lvl1;
|
||||||
|
TARRAY2_FOREACH(&fset1->lvlArr, lvl1) {
|
||||||
|
SSttLvl *lvl;
|
||||||
|
// code = stt_lvl_init_ex(lvl1, &lvl);
|
||||||
|
if (code) {
|
||||||
|
tsdbFileSetClear(fset);
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SRBTreeIter iter = tRBTreeIterCreate(&fset1->lvlTree, 1);
|
||||||
|
// for (SRBTreeNode *node = tRBTreeIterNext(&iter); node; node = tRBTreeIterNext(&iter)) {
|
||||||
|
// SSttLvl *lvl1 = TCONTAINER_OF(node, SSttLvl, rbtn);
|
||||||
|
// SSttLvl *lvl2 = taosMemoryCalloc(1, sizeof(*lvl2));
|
||||||
|
// if (lvl2 == NULL) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
// stt_lvl_init(lvl2, lvl1->level);
|
||||||
|
// add_stt_lvl(fset2, lvl2);
|
||||||
|
|
||||||
|
// SRBTreeIter iter2 = tRBTreeIterCreate(&lvl1->sttTree, 1);
|
||||||
|
// for (SRBTreeNode *node2 = tRBTreeIterNext(&iter2); node2; node2 = tRBTreeIterNext(&iter2)) {
|
||||||
|
// STFileObj *fobj1 = TCONTAINER_OF(node2, STFileObj, rbtn);
|
||||||
|
// STFileObj *fobj2;
|
||||||
|
// code = tsdbTFileObjCreate(&fobj2);
|
||||||
|
// if (code) return code;
|
||||||
|
// fobj2->f = fobj1->f;
|
||||||
|
// add_file_to_stt_lvl(lvl2, fobj2);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t tsdbFileSetClear(STFileSet **fset) {
|
||||||
|
if (fset[0]) {
|
||||||
|
for (tsdb_ftype_t ftype = TSDB_FTYPE_MIN; ftype < TSDB_FTYPE_MAX; ++ftype) {
|
||||||
|
// if (fset[0]->farr[ftype]) {
|
||||||
|
// tsdbTFileObjDestroy(&fset[0]->farr[ftype]);
|
||||||
|
// fset[0]->farr[ftype] = NULL;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
// SSttLvl *lvl;
|
||||||
|
// TARRAY2_FOREACH(&fset[0]->lvlArr, lvl) {
|
||||||
|
// // stt_lvl_clear(&lvl);
|
||||||
|
// }
|
||||||
|
|
||||||
|
taosMemoryFree(fset[0]);
|
||||||
|
fset[0] = NULL;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const SSttLvl *tsdbFileSetGetLvl(const STFileSet *fset, int32_t level) {
|
const SSttLvl *tsdbFileSetGetLvl(const STFileSet *fset, int32_t level) {
|
||||||
SSttLvl tlvl = {.level = level};
|
// SSttLvl tlvl = {.level = level};
|
||||||
SRBTreeNode *node = tRBTreeGet(&fset->lvlTree, &tlvl.rbtn);
|
// SRBTreeNode *node = tRBTreeGet(&fset->lvlTree, &tlvl.rbtn);
|
||||||
return node ? TCONTAINER_OF(node, SSttLvl, rbtn) : NULL;
|
// return node ? TCONTAINER_OF(node, SSttLvl, rbtn) : NULL;
|
||||||
|
// TODO
|
||||||
|
return NULL;
|
||||||
}
|
}
|
|
@ -232,7 +232,7 @@ int32_t tsdbJsonToTFile(const cJSON *json, tsdb_ftype_t ftype, STFile *f) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t tsdbTFileObjCreate(STFileObj **fobj) {
|
int32_t tsdbTFileObjCreate(const STFile *f, STFileObj **fobj) {
|
||||||
fobj[0] = taosMemoryMalloc(sizeof(STFileObj));
|
fobj[0] = taosMemoryMalloc(sizeof(STFileObj));
|
||||||
if (!fobj[0]) return TSDB_CODE_OUT_OF_MEMORY;
|
if (!fobj[0]) return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue