提交 4b5ea55d 编写于 作者: H Hongze Cheng

more code

上级 ccbc7c5b
......@@ -138,7 +138,7 @@ size_t taosArrayGetSize(const SArray* pArray);
* @param index
* @param pData
*/
void* taosArrayInsert(SArray* pArray, size_t index, void* pData);
void* taosArrayInsert(SArray* pArray, size_t index, const void* pData);
/**
* set data in array
......
......@@ -36,6 +36,7 @@ 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 fid);
int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet *fset2);
int32_t tsdbFileSetClear(STFileSet *pSet);
int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op);
......
......@@ -89,16 +89,6 @@ static int32_t current_fname(STsdb *pTsdb, char *fname, EFCurrentT ftype) {
return 0;
}
static int32_t fs_from_json_str(const char *pData, STFileSystem *pFS) {
int32_t code = 0;
int32_t lino;
ASSERTS(0, "TODO: Not implemented yet");
_exit:
return code;
}
static int32_t save_json(const cJSON *json, const char *fname) {
int32_t code = 0;
......@@ -251,15 +241,25 @@ _exit:
}
static int32_t apply_commit_add_fset(STFileSystem *fs, const STFileSet *fset) {
// TODO
int32_t idx = taosArraySearchIdx(fs->cstate, fset, (__compar_fn_t)tsdbFSetCmprFn, TD_GT);
if (idx < 0) idx = taosArrayGetSize(fs->cstate);
STFileSet *pFileSet = taosArrayInsert(fs->cstate, idx, fset);
if (pFileSet == NULL) return TSDB_CODE_OUT_OF_MEMORY;
int32_t code = tsdbFileSetInitEx(fset, pFileSet);
if (code) return code;
return 0;
}
static int32_t apply_commit_del_fset(STFileSystem *fs, const STFileSet *fset) {
// TODO
ASSERT(0);
return 0;
}
static int32_t apply_commit_upd_fset(STFileSystem *fs, STFileSet *fset_from, const STFileSet *fset_to) {
// TODO
ASSERT(0);
return 0;
}
static int32_t apply_commit(STFileSystem *fs) {
......
......@@ -258,6 +258,38 @@ int32_t tsdbFileSetEdit(STFileSet *fset, const STFileOp *op) {
int32_t tsdbFileSetInit(STFileSet *pSet, int32_t fid) { return fset_init(pSet, fid); }
int32_t tsdbFileSetInitEx(const STFileSet *fset1, STFileSet *fset2) {
int32_t code;
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;
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 *pSet) {
// TODO
return 0;
......
......@@ -221,7 +221,7 @@ size_t taosArrayGetSize(const SArray* pArray) {
return TARRAY_SIZE(pArray);
}
void* taosArrayInsert(SArray* pArray, size_t index, void* pData) {
void* taosArrayInsert(SArray* pArray, size_t index, const void* pData) {
if (pArray == NULL || pData == NULL) {
return NULL;
}
......@@ -488,7 +488,7 @@ void* taosDecodeArray(const void* buf, SArray** pArray, FDecode decode, int32_t
// order array<type *>
void taosArraySortPWithExt(SArray* pArray, __ext_compar_fn_t fn, const void* param) {
taosqsort(pArray->pData, pArray->size, pArray->elemSize, param, fn);
// taosArrayGetSize(pArray) > 8 ? taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param);
// taosArrayGetSize(pArray) > 8 ? taosArrayQuickSort(pArray, fn, param) : taosArrayInsertSort(pArray, fn, param);
}
void taosArraySwap(SArray* a, SArray* b) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册