提交 de1bdf97 编写于 作者: H Hongze Cheng

more code

上级 b75aca75
......@@ -93,9 +93,6 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arg, // array
TARRAY2_FREE(a); \
} while (0)
#define TARRAY2_SEARCH(a, ep, cmp, flag) \
(((a)->size == 0) ? NULL : taosbsearch(ep, (a)->data, (a)->size, sizeof(typeof((a)->data[0])), cmp, flag))
#define TARRAY2_INSERT(a, idx, e) \
({ \
int32_t __ret = 0; \
......@@ -116,6 +113,24 @@ static FORCE_INLINE int32_t tarray2_make_room(void *arg, // array
#define TARRAY2_APPEND(a, e) TARRAY2_INSERT(a, (a)->size, e)
#define TARRAY2_APPEND_P(a, ep) TARRAY2_APPEND(a, *(ep))
#define TARRAY2_SEARCH(a, ep, cmp, flag) \
(((a)->size == 0) ? NULL \
: taosbsearch(ep, (a)->data, (a)->size, sizeof(typeof((a)->data[0])), (__compar_fn_t)cmp, flag))
#define TARRAY2_SEARCH_IDX(a, ep, cmp, flag) \
({ \
typeof((a)->data) __p = TARRAY2_SEARCH(a, ep, cmp, flag); \
__p ? __p - (a)->data : -1; \
})
#define TARRAY2_SORT_INSERT(a, e, cmp) \
({ \
int32_t __idx = TARRAY2_SEARCH_IDX(a, &(e), cmp, TD_GT); \
TARRAY2_INSERT(a, __idx < 0 ? (a)->size : __idx, e); \
})
#define TARRAY2_SORT_INSERT_P(a, ep, cmp) TARRAY2_SORT_INSERT(a, *(ep), cmp)
#define TARRAY2_REMOVE(a, idx, cb) \
do { \
if ((idx) < (a)->size) { \
......
......@@ -24,7 +24,6 @@ extern "C" {
/* Exposed Handle */
typedef struct STFileSystem STFileSystem;
typedef TARRAY2(STFileOp) TFileOpArray;
typedef enum {
TSDB_FEDIT_COMMIT = 1, //
......
......@@ -27,6 +27,7 @@ typedef struct STFileOp STFileOp;
typedef struct SSttLvl SSttLvl;
typedef TARRAY2(STFileSet *) TFileSetArray;
typedef TARRAY2(SSttLvl *) TSttLvlArray;
typedef TARRAY2(STFileOp) TFileOpArray;
typedef enum {
TSDB_FOP_NONE = 0,
......@@ -43,7 +44,10 @@ int32_t tsdbTFileSetClear(STFileSet **fset);
int32_t tsdbTFileSetToJson(const STFileSet *fset, cJSON *json);
int32_t tsdbJsonToTFileSet(const cJSON *json, STFileSet **fset);
int32_t tsdbTFileSetCmprFn(const STFileSet **fset1, const STFileSet **fset2);
int32_t tsdbTFileSetEdit(STFileSet *fset, const STFileOp *op);
int32_t tsdbTFileSetEditEx(const STFileSet *fset1, STFileSet *fset);
const SSttLvl *tsdbTFileSetGetLvl(const STFileSet *fset, int32_t level);
......
......@@ -499,39 +499,37 @@ static int32_t fset_cmpr_fn(const struct STFileSet *pSet1, const struct STFileSe
return 0;
}
static int32_t edit_fs(STFileSystem *pFS, const SArray *aFileOp) {
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};
// int32_t idx = taosArraySearchIdx(pFS->nstate, &fset, (__compar_fn_t)tsdbFSetCmprFn, TD_GE);
// pSet = NULL;
// if (idx < 0) {
// idx = taosArrayGetSize(pFS->nstate);
// } else {
// pSet = taosArrayGet(pFS->nstate, idx);
// if (pSet->fid != op->fid) pSet = NULL;
// }
// 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);
// }
static int32_t edit_fs(TFileSetArray *fset_arr, const TFileOpArray *op_arr) {
int32_t code = 0;
int32_t lino = 0;
STFileSet *fset = NULL;
const STFileOp *op;
TARRAY2_FOREACH_PTR(op_arr, op) {
if (!fset || fset->fid != op->fid) {
STFileSet tfset = {.fid = op->fid};
fset = &tfset;
fset = TARRAY2_SEARCH(fset_arr, &fset, tsdbTFileSetCmprFn, TD_EQ);
if (!fset) {
code = tsdbTFileSetInit(op->fid, &fset);
TSDB_CHECK_CODE(code, lino, _exit);
code = TARRAY2_SORT_INSERT(fset_arr, fset, tsdbTFileSetCmprFn);
TSDB_CHECK_CODE(code, lino, _exit);
}
}
code = tsdbTFileSetEdit(pSet, op);
code = tsdbTFileSetEdit(fset, op);
TSDB_CHECK_CODE(code, lino, _exit);
if (0) {
// TODO check if the file set should be deleted
}
}
_exit:
return 0;
return code;
}
int32_t tsdbOpenFS(STsdb *pTsdb, STFileSystem **fs, int8_t rollback) {
......@@ -588,7 +586,7 @@ int32_t tsdbFSEditBegin(STFileSystem *fs, const SArray *aFileOp, EFEditT etype)
fs->etype = etype;
// edit
code = edit_fs(fs, aFileOp);
code = edit_fs(&fs->nstate, NULL /* TODO */);
TSDB_CHECK_CODE(code, lino, _exit);
// save fs
......
......@@ -208,6 +208,11 @@ int32_t tsdbTFileSetEdit(STFileSet *fset, const STFileOp *op) {
return 0;
}
int32_t tsdbTFileSetEditEx(const STFileSet *fset1, STFileSet *fset) {
// TODO
return 0;
}
int32_t tsdbTFileSetInit(int32_t fid, STFileSet **fset) {
fset[0] = taosMemoryCalloc(1, sizeof(STFileSet));
if (fset[0] == NULL) return TSDB_CODE_OUT_OF_MEMORY;
......@@ -268,4 +273,10 @@ const SSttLvl *tsdbTFileSetGetLvl(const STFileSet *fset, int32_t level) {
// return node ? TCONTAINER_OF(node, SSttLvl, rbtn) : NULL;
// TODO
return NULL;
}
int32_t tsdbTFileSetCmprFn(const STFileSet **fset1, const STFileSet **fset2) {
if (fset1[0]->fid < fset2[0]->fid) return -1;
if (fset1[0]->fid > fset2[0]->fid) return 1;
return 0;
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册